GH-117442: Check eval-breaker at start (rather than end) of tier 2 loops (GH-118482)

This commit is contained in:
Mark Shannon 2024-05-02 13:10:31 +01:00 committed by GitHub
parent f8e088df2a
commit 67bba9dd0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 137 additions and 174 deletions

View file

@ -2493,19 +2493,21 @@
next_instr += 1;
INSTRUCTION_STATS(ENTER_EXECUTOR);
#ifdef _Py_TIER2
int prevoparg = oparg;
CHECK_EVAL_BREAKER();
if (this_instr->op.code != ENTER_EXECUTOR ||
this_instr->op.arg != prevoparg) {
next_instr = this_instr;
DISPATCH();
}
PyCodeObject *code = _PyFrame_GetCode(frame);
_PyExecutorObject *executor = code->co_executors->executors[oparg & 255];
assert(executor->vm_data.index == INSTR_OFFSET() - 1);
assert(executor->vm_data.code == code);
assert(executor->vm_data.valid);
assert(tstate->previous_executor == NULL);
/* If the eval breaker is set then stay in tier 1.
* This avoids any potentially infinite loops
* involving _RESUME_CHECK */
if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) {
opcode = executor->vm_data.opcode;
oparg = (oparg & ~255) | executor->vm_data.oparg;
next_instr = this_instr;
DISPATCH_GOTO();
}
tstate->previous_executor = Py_None;
Py_INCREF(executor);
GOTO_TIER_TWO(executor);