Skip to content

Commit

Permalink
Skip weak references to old objects in minor GC
Browse files Browse the repository at this point in the history
If we are in a minor GC and the object to mark is old, then the old
object should already be marked and cannot be reclaimed in this GC cycle
so we don't need to add it to the weak refences list.
  • Loading branch information
peterzhu2118 committed Sep 1, 2023
1 parent 7f6407c commit 771576f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6903,6 +6903,16 @@ rb_gc_mark_weak(VALUE *ptr)

GC_ASSERT(objspace->rgengc.parent_object == 0 || FL_TEST(objspace->rgengc.parent_object, FL_WB_PROTECTED));

/* If we are in a minor GC and the other object is old, then obj should
* already be marked and cannot be reclaimed in this GC cycle so we don't
* need to add it to the weak refences list. */
if (!is_full_marking(objspace) && RVALUE_OLD_P(obj)) {
GC_ASSERT(RVALUE_MARKED(obj));
GC_ASSERT(!objspace->flags.during_compacting);

return;
}

rgengc_check_relation(objspace, obj);

rb_darray_append_without_gc(&objspace->weak_references, ptr);
Expand Down

0 comments on commit 771576f

Please sign in to comment.