Skip to content

Commit 989a882

Browse files
committed
Clear exit if START_EXECUTOR detects that the executor is invalid
1 parent 264559a commit 989a882

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ static inline _PyExecutorObject *_PyExecutor_FromExit(_PyExitData *exit)
363363

364364
extern _PyExecutorObject *_PyExecutor_GetColdExecutor(void);
365365

366+
PyAPI_FUNC(void) _PyExecutor_ClearExit(_PyExitData *exit);
367+
366368
static inline int is_terminator(const _PyUOpInstruction *uop)
367369
{
368370
int opcode = uop->opcode;

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,7 @@ dummy_func(
29652965
this_instr[1].counter = initial_jump_backoff_counter();
29662966
assert(tstate->current_executor == NULL);
29672967
assert(executor != tstate->interp->cold_executor);
2968+
tstate->jit_exit = NULL;
29682969
GOTO_TIER_TWO(executor);
29692970
}
29702971
}
@@ -3030,6 +3031,7 @@ dummy_func(
30303031
DISPATCH_GOTO();
30313032
}
30323033
assert(executor != tstate->interp->cold_executor);
3034+
tstate->jit_exit = NULL;
30333035
GOTO_TIER_TWO(executor);
30343036
#else
30353037
Py_FatalError("ENTER_EXECUTOR is not supported in this build");
@@ -5352,6 +5354,12 @@ dummy_func(
53525354
current_executor = (_PyExecutorObject*)executor;
53535355
#endif
53545356
tstate->current_executor = (PyObject *)executor;
5357+
if (!current_executor->vm_data.valid) {
5358+
assert(tstate->jit_exit->executor == current_executor);
5359+
assert(tstate->current_executor == current_executor);
5360+
_PyExecutor_ClearExit(tstate->jit_exit);
5361+
DEOPT_IF(true);
5362+
}
53555363
}
53565364

53575365
tier2 op(_MAKE_WARM, (--)) {

Python/executor_cases.c.h

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ translate_bytecode_to_trace(
584584
code->co_firstlineno,
585585
2 * INSTR_IP(initial_instr, code));
586586
ADD_TO_TRACE(_START_EXECUTOR, 0, (uintptr_t)instr, INSTR_IP(instr, code));
587-
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, 0);
588587
ADD_TO_TRACE(_MAKE_WARM, 0, 0, 0);
589588
uint32_t target = 0;
590589

@@ -1494,6 +1493,16 @@ _PyExecutor_GetColdExecutor(void)
14941493
return cold;
14951494
}
14961495

1496+
void
1497+
_PyExecutor_ClearExit(_PyExitData *exit)
1498+
{
1499+
if (exit == NULL) {
1500+
return;
1501+
}
1502+
_PyExecutorObject *old = exit->executor;
1503+
exit->executor = _PyExecutor_GetColdExecutor();
1504+
Py_DECREF(old);
1505+
}
14971506

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

0 commit comments

Comments
 (0)