Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Protect against specialization failures in the tracing JIT compiler.
16 changes: 16 additions & 0 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,22 @@ _PyJit_translate_single_bytecode_to_trace(
target--;
}

if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]] > 0) {
uint16_t backoff = (this_instr + 1)->counter.value_and_backoff;
// adaptive_counter_cooldown is a fresh specialization.
// trigger_backoff_counter is what we set during tracing.
// All tracing backoffs should be freshly specialized or untouched.
// If not, that indicates a deopt during tracing, and
// thus the "actual" instruction executed is not the one that is
// in the instruction stream, but rather the deopt.
// It's important we check for this, as some specializations might make
// no progress (they can immediately deopt after specializing).
if (backoff != adaptive_counter_cooldown().value_and_backoff &&
backoff != trigger_backoff_counter().value_and_backoff) {
opcode = _PyOpcode_Deopt[opcode];
}
}

int old_stack_level = _tstate->jit_tracer_state.prev_state.instr_stacklevel;

// Strange control-flow
Expand Down
Loading