gh-112529: Implement GC for free-threaded builds (#114262)

* gh-112529: Implement GC for free-threaded builds

This implements a mark and sweep GC for the free-threaded builds of
CPython. The implementation relies on mimalloc to find GC tracked
objects (i.e., "containers").
This commit is contained in:
Sam Gross 2024-01-25 13:27:36 -05:00 committed by GitHub
parent 4850410b60
commit b52fc70d1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1952 additions and 22 deletions

View file

@ -10,6 +10,7 @@
#include "pycore_frame.h"
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_object.h" // _PyType_InitCache()
#include "pycore_object_stack.h" // _PyObjectStackChunk_ClearFreeList()
#include "pycore_parking_lot.h" // _PyParkingLot_AfterFork()
#include "pycore_pyerrors.h" // _PyErr_Clear()
#include "pycore_pylifecycle.h" // _PyAST_Fini()
@ -1468,6 +1469,7 @@ _Py_ClearFreeLists(_PyFreeListState *state, int is_finalization)
_PyList_ClearFreeList(state, is_finalization);
_PyContext_ClearFreeList(state, is_finalization);
_PyAsyncGen_ClearFreeLists(state, is_finalization);
_PyObjectStackChunk_ClearFreeList(state, is_finalization);
}
void
@ -2055,7 +2057,6 @@ start_the_world(struct _stoptheworld_state *stw)
HEAD_LOCK(runtime);
stw->requested = 0;
stw->world_stopped = 0;
stw->requester = NULL;
// Switch threads back to the detached state.
PyInterpreterState *i;
PyThreadState *t;
@ -2066,6 +2067,7 @@ start_the_world(struct _stoptheworld_state *stw)
_PyParkingLot_UnparkAll(&t->state);
}
}
stw->requester = NULL;
HEAD_UNLOCK(runtime);
if (stw->is_global) {
_PyRWMutex_Unlock(&runtime->stoptheworld_mutex);