Skip to content

Commit

Permalink
Properly initialize counters
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Dec 14, 2024
1 parent f9b89b5 commit e34235c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ translate_bytecode_to_trace(
assert(code->co_executors);
assert(code->co_executors->executors);
_PyExecutorObject *executor = code->co_executors->executors[oparg & 255];
if (_PyOpcode_Deopt[executor->vm_data.opcode] == RESUME) {
if (_PyOpcode_Deopt[executor->vm_data.opcode] == RESUME ||
// If previous was a _PUSH_FRAME, trace into it as well.
(trace_length >= 1 && trace[trace_length - 1].opcode == _PUSH_FRAME)) {
instr++;
instr += _PyOpcode_Caches[RESUME];
goto top;
Expand Down
7 changes: 6 additions & 1 deletion Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,15 @@ _PyCode_Quicken(_Py_CODEUNIT *instructions, Py_ssize_t size, PyObject *consts,
int enable_counters)
{
#if ENABLE_SPECIALIZATION_FT
_Py_BackoffCounter jump_counter, adaptive_counter;
_Py_BackoffCounter jump_counter, adaptive_counter, resume_counter;
if (enable_counters) {
jump_counter = initial_jump_backoff_counter();
resume_counter = initial_resume_counter();
adaptive_counter = adaptive_counter_warmup();
}
else {
jump_counter = initial_unreachable_backoff_counter();
resume_counter = initial_unreachable_backoff_counter();
adaptive_counter = initial_unreachable_backoff_counter();
}
int opcode = 0;
Expand All @@ -466,6 +468,9 @@ _PyCode_Quicken(_Py_CODEUNIT *instructions, Py_ssize_t size, PyObject *consts,
case JUMP_BACKWARD:
instructions[i + 1].counter = jump_counter;
break;
case RESUME:
instructions[i + 1].counter = resume_counter;
break;
case POP_JUMP_IF_FALSE:
case POP_JUMP_IF_TRUE:
case POP_JUMP_IF_NONE:
Expand Down

0 comments on commit e34235c

Please sign in to comment.