Skip to content

Implement instruction metering resume#4902

Open
AlixANNERAUD wants to merge 1 commit intobytecodealliance:mainfrom
AlixANNERAUD:instruction-metering-resume
Open

Implement instruction metering resume#4902
AlixANNERAUD wants to merge 1 commit intobytecodealliance:mainfrom
AlixANNERAUD:instruction-metering-resume

Conversation

@AlixANNERAUD
Copy link
Copy Markdown
Contributor

@AlixANNERAUD AlixANNERAUD commented Apr 2, 2026

This pull request introduces support for resuming WebAssembly execution after an instruction metering trap in both the classic and fast interpreter modes. When the instruction budget is exhausted, the runtime now preserves interpreter state, allowing the host to set a new budget and resume execution from where it left off, rather than restarting the function. This is achieved through new APIs, changes to execution environment state, and updates to the interpreter logic.

Instruction Metering & Resumption Enhancements:

  • Added new fields to WASMExecEnv to track metering suspension state and the necessary context to resume execution (metering_suspended, metering_suspend_frame, metering_suspend_function, metering_suspend_argc, metering_suspend_argv). [1] [2]
  • Implemented the wasm_runtime_resume_wasm API, allowing the host to resume execution after an instruction limit trap, with documentation added to wasm_export.h and header exposure in wasm_runtime_common.h. [1] [2] [3]

Interpreter Logic Updates (Classic & Fast):

  • Modified both classic (wasm_interp_classic.c) and fast (wasm_interp_fast.c) interpreters to detect instruction metering exceptions, preserve interpreter state on trap, and resume execution from the correct frame and instruction pointer when requested. This includes careful frame management and state clearing. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

Instruction Metering Robustness:

  • Improved instruction metering checks to roll back the instruction pointer appropriately after a trap, ensuring correct resumption in the fast interpreter.

Documentation:

  • Updated the documentation to describe the new resumption behavior for instruction metering in both classic and fast interpreter modes.

@AlixANNERAUD AlixANNERAUD force-pushed the instruction-metering-resume branch from 986030e to 41dd8a7 Compare April 5, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant