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:
Sam Gross 2024-09-12 12:37:06 -04:00 committed by GitHub
parent 4ed7d1d6ac
commit b2afe2aae4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 177 additions and 99 deletions

View file

@ -227,6 +227,13 @@ PyStackRef_DUP(_PyStackRef stackref)
# define PyStackRef_DUP(stackref) PyStackRef_FromPyObjectSteal(Py_NewRef(PyStackRef_AsPyObjectBorrow(stackref)))
#endif
// Convert a possibly deferred reference to a strong reference.
static inline _PyStackRef
PyStackRef_AsStrongReference(_PyStackRef stackref)
{
return PyStackRef_FromPyObjectSteal(PyStackRef_AsPyObjectSteal(stackref));
}
static inline void
_PyObjectStack_FromStackRefStack(PyObject **dst, const _PyStackRef *src, size_t length)
{
@ -261,6 +268,11 @@ PyStackRef_ExceptionInstanceCheck(_PyStackRef stackref)
return PyExceptionInstance_Check(PyStackRef_AsPyObjectBorrow(stackref));
}
static inline bool
PyStackRef_CodeCheck(_PyStackRef stackref)
{
return PyCode_Check(PyStackRef_AsPyObjectBorrow(stackref));
}
static inline bool
PyStackRef_FunctionCheck(_PyStackRef stackref)