Skip to content

Commit fa0adba

Browse files
authored
YJIT: Invalidate i-cache for the other cb on next_page (#6631)
* YJIT: Invalidate i-cache for the other cb on next_page * YJIT: Invalidate only what's written by jmp_ptr * YJIT: Move the code to the arm64 backend
1 parent 0dc2e1a commit fa0adba

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

yjit/src/backend/arm64/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,23 @@ impl Assembler
708708
}
709709
}
710710

711+
/// Call emit_jmp_ptr and immediately invalidate the written range.
712+
/// This is needed when next_page also moves other_cb that is not invalidated
713+
/// by compile_with_regs. Doing it here allows you to avoid invalidating a lot
714+
/// more than necessary when other_cb jumps from a position early in the page.
715+
/// This invalidates a small range of cb twice, but we accept the small cost.
716+
fn emit_jmp_ptr_with_invalidation(cb: &mut CodeBlock, dst_ptr: CodePtr) {
717+
#[cfg(not(test))]
718+
let start = cb.get_write_ptr();
719+
emit_jmp_ptr(cb, dst_ptr);
720+
#[cfg(not(test))]
721+
{
722+
let end = cb.get_write_ptr();
723+
use crate::cruby::rb_yjit_icache_invalidate;
724+
unsafe { rb_yjit_icache_invalidate(start.raw_ptr() as _, end.raw_ptr() as _) };
725+
}
726+
}
727+
711728
// dbg!(&self.insns);
712729

713730
// List of GC offsets
@@ -1018,7 +1035,7 @@ impl Assembler
10181035
};
10191036

10201037
// On failure, jump to the next page and retry the current insn
1021-
if !had_dropped_bytes && cb.has_dropped_bytes() && cb.next_page(src_ptr, emit_jmp_ptr) {
1038+
if !had_dropped_bytes && cb.has_dropped_bytes() && cb.next_page(src_ptr, emit_jmp_ptr_with_invalidation) {
10221039
// Reset cb states before retrying the current Insn
10231040
cb.set_label_state(old_label_state);
10241041
} else {

0 commit comments

Comments
 (0)