YJIT: Use raw memory write to update pointers in code

Because we have set all code memory to writable before the reference
updating phase, we can use raw memory writes directly.
This commit is contained in:
Kunshan Wang 2025-07-19 16:22:46 +08:00 committed by Alan Wu
parent fd492a45eb
commit 5ef20b3a27

View file

@ -2091,11 +2091,9 @@ pub extern "C" fn rb_yjit_iseq_update_references(iseq: IseqPtr) {
// Only write when the VALUE moves, to be copy-on-write friendly. // Only write when the VALUE moves, to be copy-on-write friendly.
if new_addr != object { if new_addr != object {
for (byte_idx, &byte) in new_addr.as_u64().to_le_bytes().iter().enumerate() { // SAFETY: Since we already set code memory writable before the compacting phase,
let byte_code_ptr = value_code_ptr.add_bytes(byte_idx); // we can use raw memory accesses directly.
cb.write_mem(byte_code_ptr, byte) unsafe { value_ptr.write_unaligned(new_addr); }
.expect("patching existing code should be within bounds");
}
} }
} }
} }