ZJIT: Add a VALUE#write_barrier helper method to deduplicate logic

This commit is contained in:
Benoit Daloze 2025-12-16 13:02:33 +01:00
parent 49cecd360f
commit 04edf3d993
Notes: git 2025-12-16 20:01:10 +00:00
3 changed files with 12 additions and 12 deletions

View File

@ -681,6 +681,14 @@ impl VALUE {
let k: isize = item.wrapping_add(item.wrapping_add(1));
VALUE(k as usize)
}
/// Call the write barrier after separately writing val to self.
pub fn write_barrier(self, val: VALUE) {
// rb_gc_writebarrier() asserts it is not called with a special constant
if !val.special_const_p() {
unsafe { rb_gc_writebarrier(self, val) };
}
}
}
pub type IseqParameters = rb_iseq_constant_body_rb_iseq_parameters;

View File

@ -183,9 +183,7 @@ pub fn append_gc_offsets(iseq: IseqPtr, mut version: IseqVersionRef, offsets: &V
let value_ptr = value_ptr as *const VALUE;
unsafe {
let object = value_ptr.read_unaligned();
if !object.special_const_p() {
rb_gc_writebarrier(iseq.into(), object);
}
VALUE::from(iseq).write_barrier(object);
}
}
}

View File

@ -124,9 +124,7 @@ fn profile_operands(profiler: &mut Profiler, profile: &mut IseqProfile, n: usize
// TODO(max): Handle GC-hidden classes like Array, Hash, etc and make them look normal or
// drop them or something
let ty = ProfiledType::new(obj);
if !ty.class().special_const_p() {
unsafe { rb_gc_writebarrier(profiler.iseq.into(), ty.class()) };
}
VALUE::from(profiler.iseq).write_barrier(ty.class());
profile_type.observe(ty);
}
}
@ -140,9 +138,7 @@ fn profile_self(profiler: &mut Profiler, profile: &mut IseqProfile) {
// TODO(max): Handle GC-hidden classes like Array, Hash, etc and make them look normal or
// drop them or something
let ty = ProfiledType::new(obj);
if !ty.class().special_const_p() {
unsafe { rb_gc_writebarrier(profiler.iseq.into(), ty.class()) };
}
VALUE::from(profiler.iseq).write_barrier(ty.class());
types[0].observe(ty);
}
@ -153,9 +149,7 @@ fn profile_block_handler(profiler: &mut Profiler, profile: &mut IseqProfile) {
}
let obj = profiler.peek_at_block_handler();
let ty = ProfiledType::object(obj);
if !ty.class().special_const_p() {
unsafe { rb_gc_writebarrier(profiler.iseq.into(), ty.class()) };
}
VALUE::from(profiler.iseq).write_barrier(ty.class());
types[0].observe(ty);
}