mirror of
https://github.com/python/cpython.git
synced 2025-08-26 19:55:24 +00:00
gh-123923: Defer refcounting for f_executable
in _PyInterpreterFrame
(#123924)
Use a `_PyStackRef` and defer the reference to `f_executable` when possible. This avoids some reference count contention in the common case of executing the same code object from multiple threads concurrently in the free-threaded build.
This commit is contained in:
parent
4ed7d1d6ac
commit
b2afe2aae4
18 changed files with 177 additions and 99 deletions
|
@ -194,7 +194,7 @@ static void
|
|||
lltrace_resume_frame(_PyInterpreterFrame *frame)
|
||||
{
|
||||
PyObject *fobj = frame->f_funcobj;
|
||||
if (!PyCode_Check(frame->f_executable) ||
|
||||
if (!PyStackRef_CodeCheck(frame->f_executable) ||
|
||||
fobj == NULL ||
|
||||
!PyFunction_Check(fobj)
|
||||
) {
|
||||
|
@ -784,7 +784,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
|
|||
entry_frame.f_globals = (PyObject*)0xaaa3;
|
||||
entry_frame.f_builtins = (PyObject*)0xaaa4;
|
||||
#endif
|
||||
entry_frame.f_executable = Py_None;
|
||||
entry_frame.f_executable = PyStackRef_None;
|
||||
entry_frame.instr_ptr = (_Py_CODEUNIT *)_Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS + 1;
|
||||
entry_frame.stackpointer = entry_frame.localsplus;
|
||||
entry_frame.owner = FRAME_OWNED_BY_CSTACK;
|
||||
|
@ -1681,7 +1681,7 @@ clear_thread_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
|
|||
tstate->c_recursion_remaining--;
|
||||
assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
|
||||
_PyFrame_ClearExceptCode(frame);
|
||||
Py_DECREF(frame->f_executable);
|
||||
PyStackRef_CLEAR(frame->f_executable);
|
||||
tstate->c_recursion_remaining++;
|
||||
_PyThreadState_PopFrame(tstate, frame);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue