From 28f5e3de572e1f688b05126d395cf3aadd5ab8ad Mon Sep 17 00:00:00 2001 From: Dino Viehland Date: Thu, 13 Feb 2025 09:01:43 -0800 Subject: gh-129984: Mark immortal objects as deferred (#129985) Mark immortal objects as deferred --- Include/internal/pycore_object.h | 3 ++- Include/internal/pycore_stackref.h | 2 +- Objects/dictobject.c | 2 +- Objects/object.c | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 49ddfd5..ffd31bd 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -74,6 +74,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *); { \ .ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL, \ .ob_flags = _Py_STATICALLY_ALLOCATED_FLAG, \ + .ob_gc_bits = _PyGC_BITS_DEFERRED, \ .ob_type = (type) \ } #else @@ -612,7 +613,7 @@ _Py_TryIncrefCompare(PyObject **src, PyObject *op) static inline int _Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out) { - if (_Py_IsImmortal(op) || _PyObject_HasDeferredRefcount(op)) { + if (_PyObject_HasDeferredRefcount(op)) { *out = (_PyStackRef){ .bits = (intptr_t)op | Py_TAG_DEFERRED }; return 1; } diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 1ae62cc..92b10d2 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -219,7 +219,7 @@ PyStackRef_FromPyObjectNew(PyObject *obj) // Make sure we don't take an already tagged value. assert(((uintptr_t)obj & Py_TAG_BITS) == 0); assert(obj != NULL); - if (_Py_IsImmortal(obj) || _PyObject_HasDeferredRefcount(obj)) { + if (_PyObject_HasDeferredRefcount(obj)) { return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_DEFERRED }; } else { diff --git a/Objects/dictobject.c b/Objects/dictobject.c index d979cd7..900d001 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1590,7 +1590,7 @@ _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t h *value_addr = PyStackRef_NULL; return DKIX_EMPTY; } - if (_Py_IsImmortal(value) || _PyObject_HasDeferredRefcount(value)) { + if (_PyObject_HasDeferredRefcount(value)) { *value_addr = (_PyStackRef){ .bits = (uintptr_t)value | Py_TAG_DEFERRED }; return ix; } diff --git a/Objects/object.c b/Objects/object.c index 2dd5033..16aedac 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2538,6 +2538,7 @@ _Py_SetImmortalUntracked(PyObject *op) op->ob_tid = _Py_UNOWNED_TID; op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL; op->ob_ref_shared = 0; + _Py_atomic_or_uint8(&op->ob_gc_bits, _PyGC_BITS_DEFERRED); #else op->ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT; #endif -- cgit v0.12