Read barriers
Opened this issue · 1 comments
This is needed for collectors that use concurrent marking or forwarding pointers, like Java's ZGC and Shenandoah.
I used to think this was impossible, but now I think it is not.
I think we could insert them in the deref
implementation of Gc. We could guarantee the pointers are updated at least once after each safe point. Is this good enough?
TODO: Consult The GC Handbook
I've implemented concurrent copying in Rust but it was based on C4: cgc. It's object header is quite large as it has 2 words: pointer to vtable and pointer to forwarding word. Forwarding word by default points to object itself and read barrier is as simpel as this:
pub(crate) unsafe fn read_barrier_impl<T: Trace>(src_: *mut HeapInner<T>) -> *mut HeapInner<T> {
let src = &*src_;
// src.forward points to fromspace or to tospace.
let r = src.forward.load(Ordering::Acquire) as *mut _;
log::trace!("Read barrier: From {:p} to {:p}", src_, r);
r
}
This barrier means always doing two loads but it is much better than read barriers with conditions