Commit a10db88
committed
Fix JIT non-deterministic execution on Arm64
The JIT compiler produced inconsistent results on Apple Silicon due to
several issues in register liveness tracking and cache maintenance:
1. Store instructions (sb, sh, sw, csw) were not tracking rs2 liveness,
causing the register allocator to potentially evict the data register
before the store executed.
2. I-cache invalidation now occurs BEFORE re-enabling write protection
to avoid a race window where executable code is not yet coherent.
Previous ordering risked stale instruction execution.
3. Removed redundant ISB barriers since sys_icache_invalidate already
includes the required DSB/ISB sequence on macOS/arm64.
4. Added final __builtin___clear_cache for the entire translated region
to guarantee all instructions are visible before execution.
5. Added cache flush after prepare_translate() in jit_state_init() to
ensure the prologue/epilogue code is cache-coherent.
The cache maintenance sequence now follows the correct ordering:
write → sys_icache_invalidate → pthread_jit_write_protect_np(true)
This ensures the I-cache is invalidated while the page is still writable,
closing the race window that existed in the previous implementation.
Note: Some edge cases (~5-10% failure rate) may still exist and require
further investigation into the register allocator or block chaining.1 parent 3d6acf5 commit a10db88
1 file changed
Lines changed: 33 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
317 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
318 | 321 | | |
| 322 | + | |
| 323 | + | |
319 | 324 | | |
320 | 325 | | |
321 | 326 | | |
| |||
612 | 617 | | |
613 | 618 | | |
614 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
615 | 624 | | |
| 625 | + | |
| 626 | + | |
616 | 627 | | |
617 | 628 | | |
618 | 629 | | |
| |||
1675 | 1686 | | |
1676 | 1687 | | |
1677 | 1688 | | |
| 1689 | + | |
1678 | 1690 | | |
1679 | 1691 | | |
1680 | 1692 | | |
| |||
1725 | 1737 | | |
1726 | 1738 | | |
1727 | 1739 | | |
| 1740 | + | |
1728 | 1741 | | |
1729 | 1742 | | |
1730 | 1743 | | |
| |||
2297 | 2310 | | |
2298 | 2311 | | |
2299 | 2312 | | |
| 2313 | + | |
2300 | 2314 | | |
2301 | 2315 | | |
2302 | 2316 | | |
| |||
2321 | 2335 | | |
2322 | 2336 | | |
2323 | 2337 | | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
2324 | 2348 | | |
2325 | 2349 | | |
2326 | 2350 | | |
| |||
2350 | 2374 | | |
2351 | 2375 | | |
2352 | 2376 | | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
2353 | 2385 | | |
2354 | 2386 | | |
2355 | 2387 | | |
| |||
0 commit comments