Skip to content

Commit fa87839

Browse files
eendebakptclaude
andcommitted
Fix JIT+pystats crash: is_terminator fails for base opcodes
Two bugs when building with --enable-experimental-jit --enable-pystats: 1. `is_terminator()` uses `_PyUop_Uncached[opcode]` to map replicated variants back to base opcodes, but the array only contains entries for replicated variants (e.g. `_JUMP_TO_TOP_r00`). For base opcodes like `_JUMP_TO_TOP` itself, it returns 0, so the terminator is not recognized. This causes `effective_trace_length()` to hit `Py_FatalError("No terminating instruction")`. Fix: fall back to the raw opcode when `_PyUop_Uncached` returns 0. 2. `jit.c` references `jit_got_size` in `OPT_STAT_ADD` but the field is missing from `OptimizationStats` in `pystats.h`, causing a build failure. Fix: add the missing `jit_got_size` field. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a0c57a8 commit fa87839

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Include/cpython/pystats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ typedef struct _optimization_stats {
162162
uint64_t jit_code_size;
163163
uint64_t jit_trampoline_size;
164164
uint64_t jit_data_size;
165+
uint64_t jit_got_size;
165166
uint64_t jit_padding_size;
166167
uint64_t jit_freed_memory_size;
167168
uint64_t trace_total_memory_hist[_Py_UOP_HIST_SIZE];

Python/optimizer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ static int
602602
is_terminator(const _PyUOpInstruction *uop)
603603
{
604604
int opcode = _PyUop_Uncached[uop->opcode];
605+
if (opcode == 0) {
606+
opcode = uop->opcode;
607+
}
605608
return (
606609
opcode == _EXIT_TRACE ||
607610
opcode == _DEOPT ||

0 commit comments

Comments
 (0)