Skip to content

Commit 5f76e6f

Browse files
Protect against non-progressing specializations in tracing JIT
1 parent 9ac1428 commit 5f76e6f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Python/optimizer.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,22 @@ _PyJit_translate_single_bytecode_to_trace(
610610
target--;
611611
}
612612

613+
if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]] > 0) {
614+
uint16_t backoff = (this_instr + 1)->counter.value_and_backoff;
615+
// adaptive_counter_cooldown is a fresh specialization.
616+
// trigger_backoff_counter is what we set during tracing.
617+
// All tracing backoffs should be freshly specialized or untouched.
618+
// If not, that indicates a deopt during tracing, and
619+
// thus the "actual" instruction executed is not the one that is
620+
// in the instruction stream, but rather the deopt.
621+
// It's important we check for this, as some specializations might make
622+
// no progress (they can immediately deopt after specializing).
623+
if (backoff != adaptive_counter_cooldown().value_and_backoff &&
624+
backoff != trigger_backoff_counter().value_and_backoff) {
625+
opcode = _PyOpcode_Deopt[opcode];
626+
}
627+
}
628+
613629
int old_stack_level = _tstate->jit_tracer_state.prev_state.instr_stacklevel;
614630

615631
// Strange control-flow

0 commit comments

Comments
 (0)