gh-117139: Garbage collector support for deferred refcounting (#122956)

The free-threaded GC now visits interpreter stacks to keep objects
that use deferred reference counting alive.

Interpreter frames are zero initialized in the free-threaded GC so
that the GC doesn't see garbage data. This is a temporary measure
until stack spilling around escaping calls is implemented.

Co-authored-by: Ken Jin <kenjin@python.org>
This commit is contained in:
Sam Gross 2024-08-15 12:09:11 -04:00 committed by GitHub
parent 1dad23edbc
commit e001027188
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 121 additions and 20 deletions

View file

@ -15,15 +15,7 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg)
Py_VISIT(frame->f_locals);
Py_VISIT(frame->f_funcobj);
Py_VISIT(_PyFrame_GetCode(frame));
/* locals */
_PyStackRef *locals = _PyFrame_GetLocalsArray(frame);
_PyStackRef *sp = frame->stackpointer;
/* locals and stack */
while (sp > locals) {
sp--;
Py_VISIT(PyStackRef_AsPyObjectBorrow(*sp));
}
return 0;
return _PyGC_VisitFrameStack(frame, visit, arg);
}
PyFrameObject *