You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Decoding instructions should handle ENTER_EXECUTOR #107265
There's a variety of places where we walk over an array of instructions, using some variant of
for (inti=0; i<num_instructions;) {
intopcode=instructions[i].op.code;
// <decode EXTENDED_ARG>opcode=_PyOpcode_Deopt[opcode]; // or _Py_GetBaseOpcode(code, i)// <handle opcode>i+=1+_PyOpcode_Caches[opcode]; // or _PyInstruction_GetLength(code, i)
}
All these make the mistake that if opcode is ENTER_EXECUTOR, it may obscure an underlying JUMP_BACKWARD instruction, which has a cache entry.
I fixed this in gh-107256 for _PyInstruction_GetLength() and it was first reported in gh-107082, but there are a number of other occurrences. Basically every time we consult _PyOpcode_Caches we should ensure that the index is not ENTER_EXECUTOR.
Open question. Should ENTER_EXECUTOR be replaced by _Py_GetBaseOpcode() or is that its caller's responsibility? In deopt_code() the caller handles it, but in other cases the caller doesn't, but (probably) should. But you could also argue that the fix is to switch to using _PyInstruction_GetLength() instead of 1 + _PyOpcode_Caches[opcode].
Ideally, everything would use the same set of functions to get instruction lengths, opcodes and opargs.
The interaction between instrumentation and ENTER_EXECUTOR is more than just the ENTER_EXECUTOR itself, as we need to invalidate any executor if any of the instructions that it covers is instrumented.
I think we can remove _PyFrame_OpAlreadyRan altogether. If not now, definitely when PEP 667 is implemented.
But PEP 667 seems in limbo (and rather ambitious, so I wouldn't want to wait for it if we can drop _PyFrame_OpAlreadyRan).
I don't understand at all what _PyFrame_OpAlreadyRan does or why, or if there's a test for it. I added
assert(check_opcode != ENTER_EXECUTOR);
to it and am now running the test suite with -Xuops always on; we'll see in about an hour how that goes. (Hum, well, if at least one standard CI job runs runs with assertions enabled.)
So the entire test suite run with -Xuops hard-coded and a hard-coded check in _PyFrame_OpAlreadyRan that check_opcode != ENTER_EXECUTOR found nothing, so maybe there's some good reason why that function isn't a problem. In any case it's not a priority.
Guido, IIUC, we don't need to fix de_instrument.
Because de_instrument is only called from removetools and it requires that opcode should have event.
I will send a PR to add one line of assert statement for the context.
We now have _Py_GetBaseCodeUnit which returns the underlying code unit, handling instrumentation and ENTER_EXECUTOR, and is used in (almost?) all places it is needed.
Activity
gvanrossum commentedon Jul 25, 2023
Open question. Should
ENTER_EXECUTORbe replaced by_Py_GetBaseOpcode()or is that its caller's responsibility? Indeopt_code()the caller handles it, but in other cases the caller doesn't, but (probably) should. But you could also argue that the fix is to switch to using_PyInstruction_GetLength()instead of1 + _PyOpcode_Caches[opcode].@markshannon Do you have an opinion?
pythongh-107265: Fix code_richcompare to lookup actual opcode when EN…
Merge remote-tracking branch 'upstream/main' into pythongh-107265
corona10 commentedon Aug 21, 2023
I am working on
code_hashtooMerge remote-tracking branch 'upstream/main' into pythongh-107265
gh-107265: Fix code_richcompare for ENTER_EXECUTOR case (gh-108165)
pythongh-107265: Fix code_hash for ENTER_EXECUTOR case
pythongh-107265: Fix code_hash for ENTER_EXECUTOR case
markshannon commentedon Aug 21, 2023
Ideally, everything would use the same set of functions to get instruction lengths, opcodes and opargs.
The interaction between instrumentation and
ENTER_EXECUTORis more than just theENTER_EXECUTORitself, as we need to invalidate any executor if any of the instructions that it covers is instrumented.markshannon commentedon Aug 21, 2023
I think we can remove
_PyFrame_OpAlreadyRanaltogether. If not now, definitely when PEP 667 is implemented.gh-107265: Fix code_hash for ENTER_EXECUTOR case (#108188)
gvanrossum commentedon Aug 21, 2023
But PEP 667 seems in limbo (and rather ambitious, so I wouldn't want to wait for it if we can drop
_PyFrame_OpAlreadyRan).I don't understand at all what
_PyFrame_OpAlreadyRandoes or why, or if there's a test for it. I addedto it and am now running the test suite with
-Xuopsalways on; we'll see in about an hour how that goes. (Hum, well, if at least one standard CI job runs runs with assertions enabled.)gvanrossum commentedon Aug 22, 2023
So the entire test suite run with
-Xuopshard-coded and a hard-coded check in_PyFrame_OpAlreadyRanthatcheck_opcode != ENTER_EXECUTORfound nothing, so maybe there's some good reason why that function isn't a problem. In any case it's not a priority.corona10 commentedon Aug 23, 2023
Guido, IIUC, we don't need to fix
de_instrument.Because
de_instrumentis only called fromremovetoolsand it requires that opcode should have event.I will send a PR to add one line of assert statement for the context.
Please let me know if I miss something.
cpython/Python/instrumentation.c
Lines 705 to 727 in 154477b
cpython/Python/instrumentation.c
Lines 121 to 127 in 154477b
14 remaining items
gh-107265: Fix initialize/remove_tools for ENTER_EXECUTOR case (gh-10…
Revert "pythongh-107265: Fix initialize/remove_tools for ENTER_EXECUT…
pythongh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument
Merge remote-tracking branch 'upstream/main' into pythongh-107265-mark
Merge remote-tracking branch 'upstream/main' into pythongh-107265-mark
gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument (gh-…
corona10 commentedon Sep 13, 2023
About
_PyFrame_OpAlreadyRanwe don't have to do anything if it is removed: faster-cpython/ideas#623 (comment)GH-107265: Add missing deoptimizations for ENTER_EXECUTOR's original …
pythonGH-107265: Add missing deoptimizations for ENTER_EXECUTOR's ori…
pythongh-107265: Fix _PyFrame_OpAlreadyRan for ENTER_EXECUTOR case
ncoghlan commentedon Aug 1, 2024
PEP 667 landed for 3.13, and a code search indicates
_PyFrame_OpAlreadyRanis gone, so is there anything left to resolve for this issue?(This issue came up while doing a search for "PEP 667" to check for issues that could be closed now that has been implemented)
pythonGH-107265: Add missing deoptimizations for ENTER_EXECUTOR's ori…
markshannon commentedon Jan 7, 2026
We now have
_Py_GetBaseCodeUnitwhich returns the underlying code unit, handling instrumentation andENTER_EXECUTOR, and is used in (almost?) all places it is needed.