Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-128807: Add marking phase for free-threaded cyclic GC #128808

Merged
merged 20 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Include/internal/pycore_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ static inline PyObject* _Py_FROM_GC(PyGC_Head *gc) {
* the per-object lock.
*/
#ifdef Py_GIL_DISABLED
# define _PyGC_BITS_TRACKED (1) // Tracked by the GC
# define _PyGC_BITS_FINALIZED (2) // tp_finalize was called
# define _PyGC_BITS_UNREACHABLE (4)
# define _PyGC_BITS_FROZEN (8)
# define _PyGC_BITS_SHARED (16)
# define _PyGC_BITS_DEFERRED (64) // Use deferred reference counting
# define _PyGC_BITS_TRACKED (1<<0) // Tracked by the GC
# define _PyGC_BITS_FINALIZED (1<<1) // tp_finalize was called
# define _PyGC_BITS_UNREACHABLE (1<<2)
# define _PyGC_BITS_FROZEN (1<<3)
# define _PyGC_BITS_SHARED (1<<4)
# define _PyGC_BITS_ALIVE (1<<5) // Reachable from a known root.
# define _PyGC_BITS_DEFERRED (1<<6) // Use deferred reference counting
#endif

#ifdef Py_GIL_DISABLED
Expand Down Expand Up @@ -330,6 +331,9 @@ struct _gc_runtime_state {
collections, and are awaiting to undergo a full collection for
the first time. */
Py_ssize_t long_lived_pending;

/* True if gc.freeze() has been used. */
int freeze_active;
#endif
};

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