Skip weak references to old objects in minor GC

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.
This commit is contained in:
Peter Zhu 2023-08-27 19:29:35 -04:00
parent 7f6407c356
commit 771576f021
Notes: git 2023-09-01 13:32:22 +00:00

10
gc.c
View File

@ -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);