gh-148219: Fix JIT+pystats crash: is_terminator fails for base opcodes#148220
Open
eendebakpt wants to merge 1 commit intopython:mainfrom
Open
gh-148219: Fix JIT+pystats crash: is_terminator fails for base opcodes#148220eendebakpt wants to merge 1 commit intopython:mainfrom
eendebakpt wants to merge 1 commit intopython:mainfrom
Conversation
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>
diegorusso
reviewed
Apr 7, 2026
| uint64_t jit_code_size; | ||
| uint64_t jit_trampoline_size; | ||
| uint64_t jit_data_size; | ||
| uint64_t jit_got_size; |
markshannon
reviewed
Apr 7, 2026
| is_terminator(const _PyUOpInstruction *uop) | ||
| { | ||
| int opcode = _PyUop_Uncached[uop->opcode]; | ||
| if (opcode == 0) { |
Member
There was a problem hiding this comment.
We probably should remove the line int opcode = _PyUop_Uncached[uop->opcode]; as the only time we should see a TOS caching uop is in the sanity_check function.
Maybe move that line there, and just assert(opcode <= MAX_UOP_ID) here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two bugs when building with --enable-experimental-jit --enable-pystats:
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_TOPitself, it returns 0, so the terminator is not recognized.jit.creferencesjit_got_sizeinOPT_STAT_ADDbut the field is missing fromOptimizationStatsinpystats.h, causing a build failure.