From 20b283b7b521f62cc4b5096e2a78b349be17cc80 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:23:50 +0100 Subject: [PATCH] Fix ENTER_EXECUTOR bug --- Python/bytecodes.c | 9 +++++++-- Python/ceval_macros.h | 7 ++++++- Python/generated_cases.c.h | 18 ++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index a377bb5a385f..98ff74b0d6af 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -3045,8 +3045,13 @@ dummy_func( assert(executor != tstate->interp->cold_executor); tstate->jit_exit = NULL; if (IS_JIT_TRACING()) { - RECORD_TRACE(); - BAIL_TRACING_NO_DISPATCH(); + int old_opcode = executor->vm_data.opcode; + int old_oparg = (oparg & ~255) | executor->vm_data.oparg; + RECORD_TRACE_NO_DISPATCH(); + opcode = old_opcode; + oparg = old_oparg; + next_instr = this_instr; + DISPATCH_GOTO(); } TIER1_TO_TIER2(executor, 1); #else diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 47da16592453..a13c94278044 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -137,7 +137,6 @@ # define BAIL_TRACING_NO_DISPATCH() \ LEAVE_TRACING(); \ int err = _PyOptimizer_Optimize(frame, tstate); \ - tstate->interp->jit_tracer_code_curr_size = 0; \ if (err < 0) { \ JUMP_TO_LABEL(error); \ } @@ -150,6 +149,12 @@ BAIL_TRACING(); \ } \ } while (0); +# define RECORD_TRACE_NO_DISPATCH() do { \ + frame->instr_ptr = next_instr; \ + if (add_to_code_trace(tstate, frame, old_code, this_instr, next_instr, opcode, oparg, _jump_taken)) { \ + BAIL_TRACING_NO_DISPATCH(); \ + } \ + } while (0); #endif diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 4183e23cdf18..9551acb4d64b 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -5810,8 +5810,13 @@ assert(executor != tstate->interp->cold_executor); tstate->jit_exit = NULL; if (IS_JIT_TRACING()) { - RECORD_TRACE(); - BAIL_TRACING_NO_DISPATCH(); + int old_opcode = executor->vm_data.opcode; + int old_oparg = (oparg & ~255) | executor->vm_data.oparg; + RECORD_TRACE_NO_DISPATCH(); + opcode = old_opcode; + oparg = old_oparg; + next_instr = this_instr; + DISPATCH_GOTO(); } TIER1_TO_TIER2(executor, 1); #else @@ -18947,8 +18952,13 @@ assert(executor != tstate->interp->cold_executor); tstate->jit_exit = NULL; if (IS_JIT_TRACING()) { - RECORD_TRACE(); - BAIL_TRACING_NO_DISPATCH(); + int old_opcode = executor->vm_data.opcode; + int old_oparg = (oparg & ~255) | executor->vm_data.oparg; + RECORD_TRACE_NO_DISPATCH(); + opcode = old_opcode; + oparg = old_oparg; + next_instr = this_instr; + DISPATCH_GOTO(); } TIER1_TO_TIER2(executor, 1); #else -- 2.47.3