diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-08-27 19:29:35 -0400 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-09-01 09:31:59 -0400 |
commit | 771576f02185b1044f23a451e3ac6b58494844dc (patch) | |
tree | 0abfd3fcb4777b642bb468ef72185e8874051afa /gc.c | |
parent | 7f6407c356789db9039a0e45fbb8792236601956 (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8304
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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); |