Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clear exit if START_EXECUTOR detects that the executor is invalid
  • Loading branch information
markshannon committed Jul 30, 2025
commit 989a882896e9798e453e2aff0d0464d2bbef2332
2 changes: 2 additions & 0 deletions Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ static inline _PyExecutorObject *_PyExecutor_FromExit(_PyExitData *exit)

extern _PyExecutorObject *_PyExecutor_GetColdExecutor(void);

PyAPI_FUNC(void) _PyExecutor_ClearExit(_PyExitData *exit);

static inline int is_terminator(const _PyUOpInstruction *uop)
{
int opcode = uop->opcode;
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,7 @@ dummy_func(
this_instr[1].counter = initial_jump_backoff_counter();
assert(tstate->current_executor == NULL);
assert(executor != tstate->interp->cold_executor);
tstate->jit_exit = NULL;
GOTO_TIER_TWO(executor);
}
}
Expand Down Expand Up @@ -3030,6 +3031,7 @@ dummy_func(
DISPATCH_GOTO();
}
assert(executor != tstate->interp->cold_executor);
tstate->jit_exit = NULL;
GOTO_TIER_TWO(executor);
#else
Py_FatalError("ENTER_EXECUTOR is not supported in this build");
Expand Down Expand Up @@ -5352,6 +5354,12 @@ dummy_func(
current_executor = (_PyExecutorObject*)executor;
#endif
tstate->current_executor = (PyObject *)executor;
if (!current_executor->vm_data.valid) {
assert(tstate->jit_exit->executor == current_executor);
assert(tstate->current_executor == current_executor);
_PyExecutor_ClearExit(tstate->jit_exit);
DEOPT_IF(true);
}
}

tier2 op(_MAKE_WARM, (--)) {
Expand Down
11 changes: 11 additions & 0 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ translate_bytecode_to_trace(
code->co_firstlineno,
2 * INSTR_IP(initial_instr, code));
ADD_TO_TRACE(_START_EXECUTOR, 0, (uintptr_t)instr, INSTR_IP(instr, code));
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, 0);
ADD_TO_TRACE(_MAKE_WARM, 0, 0, 0);
uint32_t target = 0;

Expand Down Expand Up @@ -1494,6 +1493,16 @@ _PyExecutor_GetColdExecutor(void)
return cold;
}

void
_PyExecutor_ClearExit(_PyExitData *exit)
{
if (exit == NULL) {
return;
}
_PyExecutorObject *old = exit->executor;
exit->executor = _PyExecutor_GetColdExecutor();
Py_DECREF(old);
}

/* Detaches the executor from the code object (if any) that
* holds a reference to it */
Expand Down