Skip to content

Commit 04edf3d

Browse files
committed
ZJIT: Add a VALUE#write_barrier helper method to deduplicate logic
1 parent 49cecd3 commit 04edf3d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

zjit/src/cruby.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,14 @@ impl VALUE {
681681
let k: isize = item.wrapping_add(item.wrapping_add(1));
682682
VALUE(k as usize)
683683
}
684+
685+
/// Call the write barrier after separately writing val to self.
686+
pub fn write_barrier(self, val: VALUE) {
687+
// rb_gc_writebarrier() asserts it is not called with a special constant
688+
if !val.special_const_p() {
689+
unsafe { rb_gc_writebarrier(self, val) };
690+
}
691+
}
684692
}
685693

686694
pub type IseqParameters = rb_iseq_constant_body_rb_iseq_parameters;

zjit/src/gc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ pub fn append_gc_offsets(iseq: IseqPtr, mut version: IseqVersionRef, offsets: &V
183183
let value_ptr = value_ptr as *const VALUE;
184184
unsafe {
185185
let object = value_ptr.read_unaligned();
186-
if !object.special_const_p() {
187-
rb_gc_writebarrier(iseq.into(), object);
188-
}
186+
VALUE::from(iseq).write_barrier(object);
189187
}
190188
}
191189
}

zjit/src/profile.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ fn profile_operands(profiler: &mut Profiler, profile: &mut IseqProfile, n: usize
124124
// TODO(max): Handle GC-hidden classes like Array, Hash, etc and make them look normal or
125125
// drop them or something
126126
let ty = ProfiledType::new(obj);
127-
if !ty.class().special_const_p() {
128-
unsafe { rb_gc_writebarrier(profiler.iseq.into(), ty.class()) };
129-
}
127+
VALUE::from(profiler.iseq).write_barrier(ty.class());
130128
profile_type.observe(ty);
131129
}
132130
}
@@ -140,9 +138,7 @@ fn profile_self(profiler: &mut Profiler, profile: &mut IseqProfile) {
140138
// TODO(max): Handle GC-hidden classes like Array, Hash, etc and make them look normal or
141139
// drop them or something
142140
let ty = ProfiledType::new(obj);
143-
if !ty.class().special_const_p() {
144-
unsafe { rb_gc_writebarrier(profiler.iseq.into(), ty.class()) };
145-
}
141+
VALUE::from(profiler.iseq).write_barrier(ty.class());
146142
types[0].observe(ty);
147143
}
148144

@@ -153,9 +149,7 @@ fn profile_block_handler(profiler: &mut Profiler, profile: &mut IseqProfile) {
153149
}
154150
let obj = profiler.peek_at_block_handler();
155151
let ty = ProfiledType::object(obj);
156-
if !ty.class().special_const_p() {
157-
unsafe { rb_gc_writebarrier(profiler.iseq.into(), ty.class()) };
158-
}
152+
VALUE::from(profiler.iseq).write_barrier(ty.class());
159153
types[0].observe(ty);
160154
}
161155

0 commit comments

Comments
 (0)