Skip to content

Implement instruction metering resume#4902

Open
AlixANNERAUD wants to merge 2 commits intobytecodealliance:mainfrom
AlixANNERAUD:instruction-metering-resume
Open

Implement instruction metering resume#4902
AlixANNERAUD wants to merge 2 commits intobytecodealliance:mainfrom
AlixANNERAUD:instruction-metering-resume

Conversation

@AlixANNERAUD
Copy link
Copy Markdown
Contributor

@AlixANNERAUD AlixANNERAUD commented Apr 2, 2026

This pull request adds robust support for resuming execution after instruction metering suspension in both the classic and fast interpreter modes. When a wasm module exceeds its instruction budget, execution now suspends with state preserved, allowing the host to set a new budget and resume from where it left off. The PR also introduces new tests and documentation updates to cover this behavior.

Interpreter and Metering Suspension Enhancements:

  • Added metering_suspended and metering_suspend_frame fields to WASMExecEnv, and logic to preserve and restore interpreter state on instruction limit suspension in both classic and fast interpreter modes (wasm_exec_env.h, wasm_exec_env_create_internal, wasm_interp_call_func_bytecode, wasm_interp_call_wasm, wasm_interp_fast.c) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19].

  • Ensured that resuming is only possible when re-entering the same function, with checks and exception handling for invalid or mismatched resume attempts (wasm_interp_call_wasm) [1] [2].

Instruction Metering Behavior and Documentation:

  • Updated the documentation to clarify that, in interpreter modes, exceeding the instruction budget suspends execution and allows resumption from the preserved state after budget reset (doc/build_wamr.md).

  • Improved instruction metering checks to properly roll back the instruction pointer when the budget is exceeded, ensuring correct resume behavior (wasm_interp_fast.c).

Testing:

  • Added a new unit test suite for instruction metering, including CMake configuration and WASM test applications, ensuring the new suspension/resume logic is covered (tests/unit/instruction-metering/, tests/unit/CMakeLists.txt) [1] [2].

These changes make instruction metering more robust and user-friendly, especially for hosts that need to pause and resume long-running wasm computations.

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