rb_gc_impl_mark_and_move: avoid needless writes

Assuming not all objects are moved during compaction, it
is preferable to avoid rewriting references that haven't moved
as to avoid invalidating potentially shared memory pages.
This commit is contained in:
Jean Boussier 2025-08-01 18:17:33 +02:00
parent 95320f1ddf
commit 3ef8d833ab

View file

@ -4420,7 +4420,10 @@ rb_gc_impl_mark_and_move(void *objspace_ptr, VALUE *ptr)
GC_ASSERT(objspace->flags.during_compacting);
GC_ASSERT(during_gc);
*ptr = rb_gc_impl_location(objspace, *ptr);
VALUE destination = rb_gc_impl_location(objspace, *ptr);
if (destination != *ptr) {
*ptr = destination;
}
}
else {
gc_mark(objspace, *ptr);