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

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

Open
colesbury opened this issue Jan 23, 2025 · 0 comments
Labels
topic-free-threading type-feature A feature request or enhancement

Comments

@colesbury
Copy link
Contributor

colesbury commented Jan 23, 2025

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

@colesbury colesbury added topic-free-threading type-feature A feature request or enhancement labels Jan 23, 2025
colesbury added a commit to colesbury/cpython that referenced this issue Jan 23, 2025
The stack pointers in interpreter frames are nearly always valid now, so
use them when visiting each thread's frame. For now, don't collect
objects with deferred references in the rare case that we see a frame
with a NULL stack pointer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-free-threading type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant