Skip to content

Use _PyInterpreterFrame.stackpointer in free threaded GC when traversing threads' stacks #129236

Closed
@colesbury

Description

@colesbury

Feature or enhancement

The free threading GC traverses the active frames of threads in two places:

Previously, the frame's stackpointer was frequently not set during GC. To avoid missing some deferred references, we looked at the frame up to the maximum size (co->co_stacksize). That behavior isn't great:

  • We can only look at deferred references, because non-deferred references may be dead objects reclaimed by normal reference counting operations.
  • We need to zero-initialize the entire stack when pushing a frame

Now that the frame's stackpointer is nearly always set during GC, we should only look at the frame up to f->stackpointer. There are still some cases where the stackpointer isn't set currently; we'll (temporarily) need some fallback for those cases. Once the stackpointer is always valid during GC (ideally before the 3.14 release), we can remove the fallback and assert that f->stackpointer is not NULL.

cc @nascheme

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions