mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 04:55:21 +02:00
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:
parent
7f6407c356
commit
771576f021
Notes:
git
2023-09-01 13:32:22 +00:00
1 changed files with 10 additions and 0 deletions
10
gc.c
10
gc.c
|
@ -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));
|
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);
|
rgengc_check_relation(objspace, obj);
|
||||||
|
|
||||||
rb_darray_append_without_gc(&objspace->weak_references, ptr);
|
rb_darray_append_without_gc(&objspace->weak_references, ptr);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue