From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 23 Oct 2025 23:49:18 +0000 (+0100) Subject: fix a tracing bug, ifdef out code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a3f12993ee7a882cddab1abee4e5ad7640e318b;p=thirdparty%2FPython%2Fcpython.git fix a tracing bug, ifdef out code --- diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 9c0759af7c89..be98f34ce819 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -5219,6 +5219,7 @@ dummy_func( } tier1 no_save_ip inst(RECORD_PREVIOUS_INST, (--)) { +#if _Py_TIER2 assert(IS_JIT_TRACING()); int opcode = next_instr->op.code; int full = !_PyJit_translate_single_bytecode_to_trace(tstate, frame, next_instr); @@ -5236,6 +5237,9 @@ dummy_func( tstate->interp->jit_state.prev_instr_oparg = oparg; tstate->interp->jit_state.prev_instr_stacklevel = STACK_LEVEL(); DISPATCH_GOTO_NON_TRACING(); +#else + Py_FatalError("JIT instruction executed in non-jit build."); +#endif } ///////// Tier-2 only opcodes ///////// diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 27cc8b19f715..b741707377ae 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -413,7 +413,6 @@ _PyFrame_SetStackPointer(frame, stack_pointer) #define TIER1_TO_TIER2(EXECUTOR) \ do { \ - LEAVE_TRACING(); \ OPT_STAT_INC(traces_executed); \ next_instr = _Py_jit_entry((EXECUTOR), frame, stack_pointer, tstate); \ frame = tstate->current_frame; \ diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 516d42a3972d..0665f985ff08 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -10199,6 +10199,7 @@ TARGET(RECORD_PREVIOUS_INST) { INSTRUCTION_STATS(RECORD_PREVIOUS_INST); + #if _Py_TIER2 assert(IS_JIT_TRACING()); int opcode = next_instr->op.code; _PyFrame_SetStackPointer(frame, stack_pointer); @@ -10224,6 +10225,9 @@ tstate->interp->jit_state.prev_instr_oparg = oparg; tstate->interp->jit_state.prev_instr_stacklevel = STACK_LEVEL(); DISPATCH_GOTO_NON_TRACING(); + #else + Py_FatalError("JIT instruction executed in non-jit build."); + #endif } TARGET(RERAISE) { diff --git a/Python/optimizer.c b/Python/optimizer.c index a3d847b6eab8..c11cd22cf9df 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -884,14 +884,17 @@ _PyJit_translate_single_bytecode_to_trace( ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0); goto done; } + DPRINTF(2, "Trace continuing\n"); tstate->interp->jit_state.code_curr_size = trace_length; tstate->interp->jit_state.code_max_size = max_length; return 1; done: + DPRINTF(2, "Trace done\n"); tstate->interp->jit_state.code_curr_size = trace_length; tstate->interp->jit_state.code_max_size = max_length; return 0; full: + DPRINTF(2, "Trace full\n"); if (!is_terminator(&tstate->interp->jit_state.code_buffer[trace_length-1])) { // Undo the last few instructions. trace_length = tstate->interp->jit_state.code_curr_size;