Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-126491: GC: Mark objects reachable from roots before doing cycle collection #127110

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

Merged
merged 18 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Do not touch permanent generation
  • Loading branch information
markshannon committed Nov 21, 2024
commit 698abb384fd1d156ed78bbad723680ed03d2ca61
35 changes: 24 additions & 11 deletions 35 Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,12 @@
static void
validate_consistent_old_space(PyGC_Head *head)
{
PyGC_Head *prev = head;

Check warning on line 459 in Python/gc.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

variable ‘prev’ set but not used [-Wunused-but-set-variable]
PyGC_Head *gc = GC_NEXT(head);
if (gc == head) {
return;
}
int old_space = gc_old_space(gc);

Check warning on line 464 in Python/gc.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

unused variable ‘old_space’ [-Wunused-variable]
while (gc != head) {
PyGC_Head *truenext = GC_NEXT(gc);
assert(truenext != NULL);
Expand Down Expand Up @@ -1400,15 +1400,28 @@

/* Do bookkeeping for a completed GC cycle */
static void
completed_cycle(GCState *gcstate)
{
/* Flip spaces */
int not_visited = gcstate->visited_space;
int visited = other_space(not_visited);
gcstate->visited_space = visited;
/* Make sure all objects have visited bit set correctly */
gc_list_set_space(&gcstate->young.head, not_visited);
gc_list_set_space(&gcstate->permanent_generation.head, visited);
completed_scavenge(GCState *gcstate)
{
/* We must observe two invariants:
* 1. Members of the permanent generation must be marked visited.
* 2. We cannot touch members of the permanent generation. */
int visited;
if (gc_list_is_empty(&gcstate->permanent_generation.head)) {
/* Permanent generation is empty so we can flip spaces bit */
int not_visited = gcstate->visited_space;
visited = other_space(not_visited);
gcstate->visited_space = visited;
/* Make sure all objects have visited bit set correctly */
gc_list_set_space(&gcstate->young.head, not_visited);
}
else {
/* We must move the objects from visited to pending space. */
visited = gcstate->visited_space;
int not_visited = other_space(visited);
assert(gc_list_is_empty(&gcstate->old[not_visited].head));
gc_list_merge(&gcstate->old[visited].head, &gcstate->old[not_visited].head);
gc_list_set_space(&gcstate->old[not_visited].head, not_visited);
}
assert(gc_list_is_empty(&gcstate->old[visited].head));
gcstate->work_to_do = 0;
gcstate->phase = GC_PHASE_MARK;
Expand Down Expand Up @@ -1627,7 +1640,7 @@

add_stats(gcstate, 1, stats);
if (gc_list_is_empty(not_visited)) {
completed_cycle(gcstate);
completed_scavenge(gcstate);
}
validate_spaces(gcstate);
}
Expand Down Expand Up @@ -1657,7 +1670,7 @@
gcstate->young.count = 0;
gcstate->old[0].count = 0;
gcstate->old[1].count = 0;
completed_cycle(gcstate);
completed_scavenge(gcstate);
_PyGC_ClearAllFreeLists(tstate->interp);
validate_spaces(gcstate);
add_stats(gcstate, 2, stats);
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.