Repository navigation
Commit 24527bb
committed
[Wasm] Optimize JITCallee publication
https://bugs.webkit.org/show_bug.cgi?id=320747
rdar://183747593
Reviewed by Yusuke Suzuki.
Publishing a freshly compiled wasm function held CalleeGroup::m_lock across the two most
expensive steps in the sequence: a per-callsite icache flush for every outgoing call, and
barrierCacheOnAllThreads(), which forces a kernel round-trip per tracked wasm thread.
Neither reads nor mutates CalleeGroup state, yet every other compiler thread blocked
behind them.
This does three things.
First, correctness: Relying on LinkBuffer's finalize flush to cover a function's outgoing
call sites is unsafe: those targets are written after finalization, so an adjacent live
instruction sharing a cache line with a call site can pull the stale pre-link bytes into
the instruction cache. relink{Jump,Call,TailCall} and repatchNearCall gain a
RepatchingInfo template parameter so a repatch can skip its flush, with
flush{Jump,Call,TailCall} counterparts to perform it later, and wasm's LinkBuffers are
constructed with CacheFlushOnFinalize::No. A single whole-range cacheFlush then runs after
every outgoing call is linked. machineCodeCopy already static_asserts that a memcpy
repatch carries no Flush bit, so the split cannot be quietly broken.
Second, the critical section: installOptimizedCallee now links outgoing calls under the
lock, drops it via DropLockForScope to flush and synchronize, then re-acquires to publish
and relink callers. The window is safe because the callee is not yet in m_optimizedCallees,
so no execution thread can reach unflushed code. It is not, however, undiscoverable:
m_pendingPublishCallees keeps it findable as a direct-call target, so a thread that retires
one of its callees during the window still relinks it rather than leaving it calling code
that is about to be freed. Since an OMG install for the same index can land mid-window,
the decision to redirect callers is recomputed after re-acquiring; acting on the stale one
would relink callers to BBQ over a newer OMG and tier the function back down.
Third, the readers: Maintains the lock-free tier-up peeks from 299970@main for the two hot
paths — the IPInt loop back-edge and the BBQ loop's OMG check — now that the critical
section they contended with is short. Both are sound because a callee only appears in
m_optimizedCallees after its code is flushed and published. The staging slot that commit
needed is gone: m_pendingPublishCallees subsumes it, and more cleanly, since an unpublished
callee is simply absent rather than visible-but-half-baked. m_bbqCalleeLock has to stay
because ThreadSafeWeakOrStrongPtr is a tagged union whose strong->weak transition and
assignment are both non-atomic. The IPInt prologue reader deliberately stays on m_lock: it
is only reached when IPInt cannot interpret the function at all, so it must find whichever
JIT callee exists, and it is disabled in the default configuration.
barrierCacheOnAllThreads() no longer "claims" to invalidate any instruction cache, only
context-synchronizes, and is rewritten on top of a new Thread::barrierInstructionCache().
The old implementation passed crossModifyingCodeFence() to sendMessage, which runs the functor
on the calling thread, not the target, so it only ever worked via the suspend/resume the
message mechanism performs incidentally. On ARM64 Darwin the new primitive reads the target's
register state instead, whose returning ERET is the context-synchronizing event. Elsewhere it
stays as a thread suspend/resume sequence.
OSR entry installation shares all of this rather than duplicating it, as it did before. An
OMGOSREntryCallee is not the function's entrypoint even though it shares its index, so one
predicate gates both the recursive-call resolution and the caller relinking; its reservation
in m_osrEntryCallees also registers it, which is safe because that map is relinking
bookkeeping and only BBQCallee::setOSREntryCallee, after the flush, makes the code enterable.
Also removes EntryPlan::m_unlinkedWasmToWasmCalls and IPIntPlan's relink loop over it,
which were dead (parseAndCompileMetadata never populated the vector).
No new tests, no behavior change. Covered by existing tests.
Canonical link: https://commits.webkit.org/318386@main1 parent e7f11c8 commit 24527bb
23 files changed
Lines changed: 472 additions & 249 deletions
File tree
- Source
- JavaScriptCore
- assembler
- wasm
- WTF/wtf
- posix
- win
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3973 | 3973 | | |
3974 | 3974 | | |
3975 | 3975 | | |
| 3976 | + | |
3976 | 3977 | | |
3977 | 3978 | | |
3978 | | - | |
3979 | | - | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
3980 | 3982 | | |
3981 | | - | |
| 3983 | + | |
| 3984 | + | |
3982 | 3985 | | |
3983 | 3986 | | |
3984 | | - | |
3985 | | - | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
3986 | 3990 | | |
3987 | 3991 | | |
| 3992 | + | |
3988 | 3993 | | |
3989 | 3994 | | |
3990 | | - | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
3991 | 4011 | | |
3992 | 4012 | | |
3993 | 4013 | | |
| |||
4336 | 4356 | | |
4337 | 4357 | | |
4338 | 4358 | | |
4339 | | - | |
| 4359 | + | |
4340 | 4360 | | |
4341 | 4361 | | |
4342 | 4362 | | |
| |||
4353 | 4373 | | |
4354 | 4374 | | |
4355 | 4375 | | |
4356 | | - | |
| 4376 | + | |
4357 | 4377 | | |
4358 | 4378 | | |
4359 | 4379 | | |
| |||
4366 | 4386 | | |
4367 | 4387 | | |
4368 | 4388 | | |
4369 | | - | |
| 4389 | + | |
4370 | 4390 | | |
4371 | 4391 | | |
4372 | 4392 | | |
| |||
4378 | 4398 | | |
4379 | 4399 | | |
4380 | 4400 | | |
4381 | | - | |
| 4401 | + | |
4382 | 4402 | | |
4383 | 4403 | | |
4384 | 4404 | | |
4385 | 4405 | | |
4386 | | - | |
| 4406 | + | |
4387 | 4407 | | |
4388 | 4408 | | |
4389 | 4409 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2730 | 2730 | | |
2731 | 2731 | | |
2732 | 2732 | | |
| 2733 | + | |
2733 | 2734 | | |
2734 | 2735 | | |
2735 | 2736 | | |
2736 | 2737 | | |
2737 | 2738 | | |
2738 | 2739 | | |
2739 | 2740 | | |
2740 | | - | |
| 2741 | + | |
| 2742 | + | |
2741 | 2743 | | |
2742 | 2744 | | |
| 2745 | + | |
2743 | 2746 | | |
2744 | 2747 | | |
2745 | 2748 | | |
2746 | 2749 | | |
2747 | 2750 | | |
2748 | 2751 | | |
2749 | 2752 | | |
2750 | | - | |
| 2753 | + | |
| 2754 | + | |
2751 | 2755 | | |
2752 | 2756 | | |
2753 | 2757 | | |
2754 | | - | |
| 2758 | + | |
2755 | 2759 | | |
2756 | 2760 | | |
| 2761 | + | |
2757 | 2762 | | |
2758 | 2763 | | |
2759 | 2764 | | |
2760 | 2765 | | |
2761 | 2766 | | |
2762 | 2767 | | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
2763 | 2793 | | |
2764 | 2794 | | |
2765 | 2795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1021 | 1021 | | |
1022 | 1022 | | |
1023 | 1023 | | |
1024 | | - | |
| 1024 | + | |
1025 | 1025 | | |
1026 | 1026 | | |
1027 | 1027 | | |
1028 | 1028 | | |
1029 | | - | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1030 | 1044 | | |
1031 | 1045 | | |
1032 | | - | |
| 1046 | + | |
1033 | 1047 | | |
1034 | 1048 | | |
1035 | 1049 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
581 | | - | |
| 581 | + | |
| 582 | + | |
582 | 583 | | |
583 | 584 | | |
584 | 585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
169 | 171 | | |
| 172 | + | |
170 | 173 | | |
171 | 174 | | |
172 | 175 | | |
| |||
465 | 468 | | |
466 | 469 | | |
467 | 470 | | |
| 471 | + | |
468 | 472 | | |
469 | 473 | | |
470 | 474 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1632 | 1632 | | |
1633 | 1633 | | |
1634 | 1634 | | |
| 1635 | + | |
1635 | 1636 | | |
1636 | 1637 | | |
1637 | 1638 | | |
1638 | 1639 | | |
1639 | | - | |
| 1640 | + | |
| 1641 | + | |
1640 | 1642 | | |
1641 | 1643 | | |
| 1644 | + | |
1642 | 1645 | | |
1643 | 1646 | | |
1644 | 1647 | | |
1645 | 1648 | | |
1646 | | - | |
| 1649 | + | |
| 1650 | + | |
1647 | 1651 | | |
1648 | 1652 | | |
| 1653 | + | |
1649 | 1654 | | |
1650 | 1655 | | |
1651 | | - | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
1652 | 1672 | | |
1653 | 1673 | | |
1654 | 1674 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6407 | 6407 | | |
6408 | 6408 | | |
6409 | 6409 | | |
| 6410 | + | |
6410 | 6411 | | |
6411 | 6412 | | |
6412 | 6413 | | |
6413 | 6414 | | |
6414 | | - | |
| 6415 | + | |
| 6416 | + | |
6415 | 6417 | | |
6416 | 6418 | | |
6417 | 6419 | | |
6418 | 6420 | | |
6419 | 6421 | | |
| 6422 | + | |
6420 | 6423 | | |
6421 | 6424 | | |
6422 | | - | |
| 6425 | + | |
6423 | 6426 | | |
6424 | 6427 | | |
| 6428 | + | |
| 6429 | + | |
| 6430 | + | |
| 6431 | + | |
| 6432 | + | |
| 6433 | + | |
6425 | 6434 | | |
6426 | 6435 | | |
6427 | 6436 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
| |||
131 | 133 | | |
132 | 134 | | |
133 | 135 | | |
| 136 | + | |
134 | 137 | | |
135 | 138 | | |
136 | | - | |
| 139 | + | |
137 | 140 | | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
0 commit comments