Skip to content

Commit 080f444

Browse files
authored
gh-128807: Add marking phase for free-threaded cyclic GC (gh-128808)
1 parent 8d8b854 commit 080f444

File tree

3 files changed

+336
-22
lines changed

3 files changed

+336
-22
lines changed

Include/internal/pycore_gc.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ static inline PyObject* _Py_FROM_GC(PyGC_Head *gc) {
4545
* the per-object lock.
4646
*/
4747
#ifdef Py_GIL_DISABLED
48-
# define _PyGC_BITS_TRACKED (1) // Tracked by the GC
49-
# define _PyGC_BITS_FINALIZED (2) // tp_finalize was called
50-
# define _PyGC_BITS_UNREACHABLE (4)
51-
# define _PyGC_BITS_FROZEN (8)
52-
# define _PyGC_BITS_SHARED (16)
53-
# define _PyGC_BITS_DEFERRED (64) // Use deferred reference counting
48+
# define _PyGC_BITS_TRACKED (1<<0) // Tracked by the GC
49+
# define _PyGC_BITS_FINALIZED (1<<1) // tp_finalize was called
50+
# define _PyGC_BITS_UNREACHABLE (1<<2)
51+
# define _PyGC_BITS_FROZEN (1<<3)
52+
# define _PyGC_BITS_SHARED (1<<4)
53+
# define _PyGC_BITS_ALIVE (1<<5) // Reachable from a known root.
54+
# define _PyGC_BITS_DEFERRED (1<<6) // Use deferred reference counting
5455
#endif
5556

5657
#ifdef Py_GIL_DISABLED
@@ -330,6 +331,9 @@ struct _gc_runtime_state {
330331
collections, and are awaiting to undergo a full collection for
331332
the first time. */
332333
Py_ssize_t long_lived_pending;
334+
335+
/* True if gc.freeze() has been used. */
336+
int freeze_active;
333337
#endif
334338
};
335339

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Add a marking phase to the free-threaded GC. This is similar to what was
2+
done in GH-126491. Since the free-threaded GC does not have generations and
3+
is not incremental, the marking phase looks for all objects reachable from
4+
known roots. The roots are objects known to not be garbage, like the module
5+
dictionary for :mod:`sys`. For most programs, this marking phase should
6+
make the GC a bit faster since typically less work is done per object.

0 commit comments

Comments
 (0)