From 5ef20b3a274e855b802edd03cd432464d2a49b35 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Sat, 19 Jul 2025 16:22:46 +0800 Subject: [PATCH] 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. --- yjit/src/core.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/yjit/src/core.rs b/yjit/src/core.rs index 57756e86ce..d42726bcc7 100644 --- a/yjit/src/core.rs +++ b/yjit/src/core.rs @@ -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. if new_addr != object { - for (byte_idx, &byte) in new_addr.as_u64().to_le_bytes().iter().enumerate() { - let byte_code_ptr = value_code_ptr.add_bytes(byte_idx); - cb.write_mem(byte_code_ptr, byte) - .expect("patching existing code should be within bounds"); - } + // SAFETY: Since we already set code memory writable before the compacting phase, + // we can use raw memory accesses directly. + unsafe { value_ptr.write_unaligned(new_addr); } } } }