Repository navigation
jit: align due_insn_count with the interpreter on budget exhaustion - #233
Conversation
|
To me the broad direction seems about right. I believe interpreter's behaviour here is the more appropriate one. The code path is cold so the addition doesn't hurt anything. |
|
Rebased onto latest main to resolve the conflict with the new tests at the end of tests/execution.rs. Also removed the unused stack/heap bindings in the new test, which were failing the beta toolchain lint job. The CI run is awaiting approval. |
| )); | ||
| let due_insn_count_jit = vm.due_insn_count; | ||
|
|
||
| assert_eq!( |
There was a problem hiding this comment.
Given the nature of the problem I believe this check should rather be a part of test_interpreter_and_jit. It will then cover every single test that uses said macro.
There was a problem hiding this comment.
The macro now compares due_insn_count between the engines on every test that uses it. I also tried adding the absolute equality (due == budget on exhaustion) to the macro, but it cannot hold universally: test_err_instruction_count_syscall_capped exhausts after a syscall, and dispatch_syscall resets due_insn_count mid-run, so the due count at exhaustion is the post-syscall tally rather than the budget.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
+ Coverage 66.87% 67.42% +0.54%
==========================================
Files 26 26
Lines 17925 18199 +274
==========================================
+ Hits 11988 12271 +283
+ Misses 5937 5928 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The budget-exceeded handler saved the instruction meter to the scratch register but did not increment it, while the shared epilogue always decremented it by one. The normal exit path has a matching increment before jumping to the epilogue, but the exceeded path did not, so the JIT reported due_insn_count = budget + 1 while the interpreter reported budget. The saturating subtraction in consume() masked the difference from instruction_count, but the value passed to ContextObject::consume() was still one greater than intended. Increment the instruction meter in the exceeded handler to cancel the epilogue's decrement, matching the interpreter's accounting. The regression test checks due_insn_count directly, since the saturation hides the difference through instruction_count. Fixes anza-xyz#146
|
Moved the due_insn_count check into the test_interpreter_and_jit macro as suggested, so it now covers every test that uses the macro. The standalone test now only verifies the interpreter baseline (budget-exceeded case). All 147 tests pass. |
| /// `instruction_count`, so the `test_interpreter_and_jit` macro now checks | ||
| /// `due_insn_count` directly on every test that uses it. | ||
| #[test] | ||
| fn test_jit_exceeded_due_insn_count_matches_interpreter() { |
There was a problem hiding this comment.
Any reason this can't be run through test_interpreter_and_jit_asm() like the other tests?
There was a problem hiding this comment.
No good reason. Removed it; with the relative check in the macro it would have been redundant with test_tight_infinite_loop_unconditional anyway.
| ja -1 | ||
| exit", | ||
| loader, | ||
| ) |
There was a problem hiding this comment.
Isn't this identical to test_tight_infinite_loop_unconditional()?
There was a problem hiding this comment.
You are right, it is the same program and budget. Removed it; the macro's due_insn_count comparison covers the alignment on every test.
Fixes #146
Problem
The budget-exceeded handler saved the instruction meter to the scratch register but did not increment it, while the shared epilogue always decremented it by one. The normal exit path has a matching increment before jumping to the epilogue, but the exceeded path did not, so the JIT reported
due_insn_count = budget + 1while the interpreter reportedbudget.The saturating subtraction in
consume()masked the difference frominstruction_count, but the value passed toContextObject::consume()was still one greater than intended.Fix
Increment the instruction meter in the exceeded handler to cancel the epilogue's decrement, matching the interpreter's accounting. One line in the JIT assembly emission.
Testing
test_jit_exceeded_due_insn_count_matches_interpreterchecksdue_insn_countdirectly (the saturation hides the difference throughinstruction_count). Red on the old code (JIT 6, interpreter 5, budget 5), green after.