summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-04-29 18:36:02 (GMT)
committerGitHub <noreply@github.com>2024-04-29 18:36:02 (GMT)
commit7ccacb220d99662b626c8bc63b00a27eaf604f0c (patch)
tree231cb901ee62e523be237392b0f2b966aa8be128 /Objects/object.c
parent8d4b756fd31d4d91b55105b1241561e92cc571a3 (diff)
downloadcpython-7ccacb220d99662b626c8bc63b00a27eaf604f0c.zip
cpython-7ccacb220d99662b626c8bc63b00a27eaf604f0c.tar.gz
cpython-7ccacb220d99662b626c8bc63b00a27eaf604f0c.tar.bz2
gh-117783: Immortalize objects that use deferred reference counting (#118112)
Deferred reference counting is not fully implemented yet. As a temporary measure, we immortalize objects that would use deferred reference counting to avoid multi-threaded scaling bottlenecks. This is only performed in the free-threaded build once the first non-main thread is started. Additionally, some tests, including refleak tests, suppress this behavior.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 91bb011..8d85693 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -2430,6 +2430,13 @@ _PyObject_SetDeferredRefcount(PyObject *op)
assert(PyType_IS_GC(Py_TYPE(op)));
assert(_Py_IsOwnedByCurrentThread(op));
assert(op->ob_ref_shared == 0);
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (interp->gc.immortalize.enabled) {
+ // gh-117696: immortalize objects instead of using deferred reference
+ // counting for now.
+ _Py_SetImmortal(op);
+ return;
+ }
op->ob_gc_bits |= _PyGC_BITS_DEFERRED;
op->ob_ref_local += 1;
op->ob_ref_shared = _Py_REF_QUEUED;