Skip to content

Commit f738357

Browse files
committed
Attempt to fix JIT icache coherency on Arm64
The JIT compiler was experiencing intermittent failures on Arm64/Apple Silicon due to missing instruction cache invalidation after patching branch instructions. When update_branch_imm() modified branch targets in JIT-compiled code, the CPU's icache wasn't being invalidated, causing it to execute stale cached instructions instead of the newly patched ones. This manifested as non-deterministic test failures, particularly in compute-intensive benchmarks like the pi calculation test, with failure rates around 40%. The fix adds sys_icache_invalidate() after memcpy() in update_branch_imm to ensure the icache is synchronized with the data cache after code modification. This is critical on Arm64 architectures which have separate L1 instruction and data caches.
1 parent d22b787 commit f738357

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/jit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ static void update_branch_imm(struct jit_state *state,
611611
pthread_jit_write_protect_np(false);
612612
#endif
613613
memcpy(state->buf + offset, &insn, sizeof(uint32_t));
614+
sys_icache_invalidate(state->buf + offset, sizeof(uint32_t));
614615
#if defined(__APPLE__) && defined(__aarch64__)
615616
pthread_jit_write_protect_np(true);
616617
#endif

0 commit comments

Comments
 (0)