Commit d68e05e
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.
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.1 parent 3d6acf5 commit d68e05e
1 file changed
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
316 | 319 | | |
317 | 320 | | |
318 | 321 | | |
| |||
611 | 614 | | |
612 | 615 | | |
613 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
614 | 621 | | |
615 | 622 | | |
616 | 623 | | |
| |||
1675 | 1682 | | |
1676 | 1683 | | |
1677 | 1684 | | |
| 1685 | + | |
1678 | 1686 | | |
1679 | 1687 | | |
1680 | 1688 | | |
| |||
1725 | 1733 | | |
1726 | 1734 | | |
1727 | 1735 | | |
| 1736 | + | |
1728 | 1737 | | |
1729 | 1738 | | |
1730 | 1739 | | |
| |||
2321 | 2330 | | |
2322 | 2331 | | |
2323 | 2332 | | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
2324 | 2343 | | |
2325 | 2344 | | |
2326 | 2345 | | |
| |||
0 commit comments