summaryrefslogtreecommitdiffstats
path: root/Include/internal
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-03-26 11:11:42 (GMT)
committerGitHub <noreply@github.com>2024-03-26 11:11:42 (GMT)
commit8bef34f625e21886b1c64544c060e19ee2e229bf (patch)
treeec99928ad40650b4c5e1c5dbe1bb7e2bd91bddff /Include/internal
parentbf82f77957a31c3731b4ec470c406f5708ca9ba3 (diff)
downloadcpython-8bef34f625e21886b1c64544c060e19ee2e229bf.zip
cpython-8bef34f625e21886b1c64544c060e19ee2e229bf.tar.gz
cpython-8bef34f625e21886b1c64544c060e19ee2e229bf.tar.bz2
GH-117108: Set the "old space bit" to "visited" for all young objects (#117213)
Change old space bit of young objects from 0 to gcstate->visited_space. This ensures that any object created *and* collected during cycle GC has the bit set correctly.
Diffstat (limited to 'Include/internal')
-rw-r--r--Include/internal/pycore_gc.h14
-rw-r--r--Include/internal/pycore_object.h4
2 files changed, 15 insertions, 3 deletions
diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h
index e729616..c4482c4 100644
--- a/Include/internal/pycore_gc.h
+++ b/Include/internal/pycore_gc.h
@@ -113,7 +113,19 @@ static inline void _PyObject_GC_SET_SHARED_INLINE(PyObject *op) {
/* Bit 1 is set when the object is in generation which is GCed currently. */
#define _PyGC_PREV_MASK_COLLECTING 2
-/* Bit 0 is set if the object belongs to old space 1 */
+/* Bit 0 in _gc_next is the old space bit.
+ * It is set as follows:
+ * Young: gcstate->visited_space
+ * old[0]: 0
+ * old[1]: 1
+ * permanent: 0
+ *
+ * During a collection all objects handled should have the bit set to
+ * gcstate->visited_space, as objects are moved from the young gen
+ * and the increment into old[gcstate->visited_space].
+ * When object are moved from the pending space, old[gcstate->visited_space^1]
+ * into the increment, the old space bit is flipped.
+*/
#define _PyGC_NEXT_MASK_OLD_SPACE_1 1
#define _PyGC_PREV_SHIFT 2
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 13fe543..0b17ddf 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -318,8 +318,8 @@ static inline void _PyObject_GC_TRACK(
PyGC_Head *last = (PyGC_Head*)(generation0->_gc_prev);
_PyGCHead_SET_NEXT(last, gc);
_PyGCHead_SET_PREV(gc, last);
- _PyGCHead_SET_NEXT(gc, generation0);
- assert((gc->_gc_next & _PyGC_NEXT_MASK_OLD_SPACE_1) == 0);
+ /* Young objects will be moved into the visited space during GC, so set the bit here */
+ gc->_gc_next = ((uintptr_t)generation0) | interp->gc.visited_space;
generation0->_gc_prev = (uintptr_t)gc;
#endif
}