Add a portable (no codegen/JIT) baseline interpreter to SpiderMonkey
Categories
(Core :: JavaScript Engine, enhancement, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox120 | --- | fixed |
People
(Reporter: cfallin, Assigned: cfallin)
References
(Blocks 1 open bug)
Details
Attachments
(17 files, 1 obsolete file)
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review |
Currently, SpiderMonkey's tiers above the C++ interpreter -- including the "baseline interpreter" and "baseline compiler", which can execute inline caches (ICs) and significantly speed up execution -- work only on platforms that support runtime code generation. This is true even for the baseline interpreter, because (i) its interpreter body is generated at startup, by using the same logic that the baseline compiler uses, and (ii) it invokes compiled IC bodies.
Not every platform or environment supports runtime codegen: for example, SpiderMonkey inside a Wasm module (wasm32-wasi
target) does not, some operating systems prohibit it, some CPU architectures are not supported by SpiderMonkey's JIT backends, and some use-cases may require the security of disabling JIT. It would be a significant enhancement to SpiderMonkey's usefulness if it could make use of the engineering that has gone into CacheIR-based ICs in these use-cases.
Assignee | ||
Comment 1•1 year ago
|
||
I have implemented this, and the current implementation is seeing nice speedups in production in our use-case: 42% wallclock time reduction for one use-case, 17% for another, a geomean speedup on Octane benchmarks of 1.26x and up to 1.87x on one benchmark (DeltaBlue). I'll attach patches momentarily.
Here is a public version of the design document: link
Assignee | ||
Comment 2•1 year ago
|
||
This commit adds --enable-portable-baseline
and
--enable-portable-baseline-force
. The former builds SpiderMonkey with
PBL included, but part of the normal tiering hierarchy; when the latter
is included, all JS execution (that is able) is executed by PBL eagerly.
Updated•1 year ago
|
Assignee | ||
Comment 3•1 year ago
|
||
This commit adds JitOptions and corresponding JS shell command-line
options to control whether PBL is enabled and what its tiering threshold
is.
Depends on D189294
Assignee | ||
Comment 4•1 year ago
|
||
PBL is going to use some of these same helpers, so let's put them in
Interpreter-inl.h
rather than Interpreter.cpp
.
Depends on D189295
Assignee | ||
Comment 5•1 year ago
|
||
These field accessors will be needed by PBL's CacheIR interpreter.
Depends on D189296
Assignee | ||
Comment 6•1 year ago
|
||
This is needed to support a JitStackAlignment
of 4, which can happen
on 32-bit builds with PBL enabled (e.g. on wasm32-wasi).
Depends on D189297
Assignee | ||
Comment 7•1 year ago
|
||
Depends on D189298
Assignee | ||
Comment 8•1 year ago
|
||
This is needed by the static branch prediction (next-opcode prediction)
in PBL's CacheIR interpreter.
Depends on D189299
Assignee | ||
Comment 9•1 year ago
|
||
PBL's CacheIR interpreter is measurably faster if we avoid bounds-checks
on every CacheIRReader read of an opcode or operand/immediate. We assume
that we will be executing well-formed CacheIR (this assumption is
already relied upon elsewhere) and thus we instead stop interpreting
when we reach a ReturnFromIC
or hit an earlier guard failure.
Depends on D189300
Assignee | ||
Comment 10•1 year ago
|
||
While this will increase the size of CacheIR slightly in memory, it is a
nontrivial performance improvement when interpreting CacheIR opcodes,
because it avoids a hard-to-predict branch. The small size increase
appears worth it, at least in PBL applications, and has not been
observed to lead to any measurable macro-scale memory bloat.
Depends on D189301
Assignee | ||
Comment 11•1 year ago
|
||
This stack is needed by PBL to store baseline stack frames, because it
cannot use the machine stack (which will be managed by the host's C++
compiler instead).
Depends on D189302
Assignee | ||
Comment 12•1 year ago
|
||
These miscellaneous accessors are needed by the PBL interpreter.
Depends on D189303
Assignee | ||
Comment 13•1 year ago
|
||
PBL diverges slightly from the native baseline implementation's stack
state at IC invocation time (though the stack signatures of all JSOps
match when including the pre-IC and post-IC logic) and thus PBL must
avoid invocation of the expression decompiler for error messages in some
cases. This commit makes the fallback IC logic more tolerant of missing
"stack indices" for this purpose.
Depends on D189304
Assignee | ||
Comment 14•1 year ago
|
||
- Sometimes there is no JitRuntime, even if we are in baseline-related
code paths. - Sometimes a jit-code or stub-code pointer is null.
Depends on D189305
Assignee | ||
Comment 15•1 year ago
|
||
This commit adds the body of PBL, the Portable Baseline Interpreter.
A more detailed description is included in the [SMDOC] in the header
file.
Almost all of this commit was authored by the named commit author; two
CacheIR guard opcodes, the constructor-call fastpath, and several
bugfixes are due to Jamey Sharp <jsharp@fastly.com> (thanks!).
Depends on D189306
Assignee | ||
Comment 16•1 year ago
|
||
Depends on D189307
Assignee | ||
Comment 17•1 year ago
|
||
Depends on D189308
Assignee | ||
Comment 18•1 year ago
|
||
Several of the jit-tests need to be modified for all tests to pass with
PBL enabled and eager (test with --portable-baseline --portable-baseline-eager
). With these changes, all jit-tests do pass.
The changes fall into several main categories:
-
Because PBL diverges slightly in decompiler usage, error messages are
sometimes more generic (e.g., "undefined value" rather than "x is
undefined", that sort of thing). Several of these changes loosen
error-message expectations or exclude the relevant tests from PBL.
All actual error statuses (code works or throws exception) remain
correct. -
PBL's auxiliary stack and recursion limit are smaller than native
baseline supports, at least on some platforms; recursion counts that
are meant to invoke overflow or not invoke overflow (but whose
specific value is otherwise immaterial) are thus adjusted in places. -
A few other miscellaneous changes, supported at each point with a
comment.
Depends on D189309
Assignee | ||
Comment 19•1 year ago
|
||
On PBL, alignment is only to native word size, to avoid the need to add
additional alignment padding.
Depends on D189310
Updated•1 year ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Updated•11 months ago
|
Comment 20•11 months ago
|
||
Pushed by iireland@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/418d4dfe5fa0 part 1 / 17 (PBL): add configure options. r=jandem https://hg.mozilla.org/integration/autoland/rev/5a041bffa082 part 2 / 17 (PBL): add runtime options to enable/disable PBL. r=jandem https://hg.mozilla.org/integration/autoland/rev/206c10d873b3 part 3 / 17 (PBL): move some C++ interpreter helpers into inline .h file. r=jandem https://hg.mozilla.org/integration/autoland/rev/7e4aa1404ab4 part 4 / 17 (PBL): code motion: put CacheIR field accessors in header. r=jandem https://hg.mozilla.org/integration/autoland/rev/598525a0055a part 5 / 17 (PBL): `AbstractFramePtr` tagging: fit within two bits. r=jandem https://hg.mozilla.org/integration/autoland/rev/07686583c076 part 6 / 17 (PBL): make CacheOp a `uint16_t` explicitly, and expose `NumOpcodes`. r=jandem https://hg.mozilla.org/integration/autoland/rev/90aa66a98802 part 7 / 17 (PBL): CacheIRReader: add "peek" method. r=jandem https://hg.mozilla.org/integration/autoland/rev/90ddd9ea8b06 part 8 / 17 (PBL): CacheIR: use fixed 16-bit values for ops rather than packed 15-bit values (for speed). r=jandem https://hg.mozilla.org/integration/autoland/rev/bc9431e5c954 part 9 / 17 (PBL): add an auxiliary stack. r=jandem https://hg.mozilla.org/integration/autoland/rev/41a81b07f3e1 part 10 / 17 (PBL): Add some needed accessors. r=jandem https://hg.mozilla.org/integration/autoland/rev/3364d2c6a3b0 part 11 / 17 (PBL): CacheIR fallbacks: make more tolerant of no-decompiler case. r=jandem https://hg.mozilla.org/integration/autoland/rev/768de7534ff5 part 12 / 17 (PBL): miscellaneous ifdefs and null-checks to handle running in new configuration. r=jandem https://hg.mozilla.org/integration/autoland/rev/145f913e7033 part 13 / 17 (PBL): Add the main implementation of PBL (not yet invoked). r=jandem https://hg.mozilla.org/integration/autoland/rev/56a1e3b40bbe part 14 / 17 (PBL): invoke the PBL tier from tiering logic. r=jandem https://hg.mozilla.org/integration/autoland/rev/0dd9a6719b68 part 15 / 17 (PBL): Tweak profiling to deal with PBL. r=jandem https://hg.mozilla.org/integration/autoland/rev/146015287659 part 16 / 17 (PBL): update tests. r=jandem https://hg.mozilla.org/integration/autoland/rev/31abb9c9df15 part 17 / 17 (PBL): Fix JitStackAlignment. r=jandem
Comment 21•11 months ago
|
||
Backed out for causing sm bustages in JSScript.cpp
- Backout link
- Push with failures
- Failure Log
- Failure line: /builds/worker/checkouts/gecko/js/src/vm/JSScript.cpp:3177:23: error: unused variable 'PBLJitCodePtr' [-Werror,-Wunused-const-variable]
Assignee | ||
Comment 22•11 months ago
|
||
Sorry about that! Moved that definition inside the PBL ifdef; will try landing again.
Comment 23•11 months ago
|
||
Pushed by iireland@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/37aabeaab4ce part 1 / 17 (PBL): add configure options. r=jandem https://hg.mozilla.org/integration/autoland/rev/50465202ecdb part 2 / 17 (PBL): add runtime options to enable/disable PBL. r=jandem https://hg.mozilla.org/integration/autoland/rev/94fefa578027 part 3 / 17 (PBL): move some C++ interpreter helpers into inline .h file. r=jandem https://hg.mozilla.org/integration/autoland/rev/adeeb6a497ec part 4 / 17 (PBL): code motion: put CacheIR field accessors in header. r=jandem https://hg.mozilla.org/integration/autoland/rev/f59766bd98d4 part 5 / 17 (PBL): `AbstractFramePtr` tagging: fit within two bits. r=jandem https://hg.mozilla.org/integration/autoland/rev/0e4c337e8a63 part 6 / 17 (PBL): make CacheOp a `uint16_t` explicitly, and expose `NumOpcodes`. r=jandem https://hg.mozilla.org/integration/autoland/rev/60365e2a3f44 part 7 / 17 (PBL): CacheIRReader: add "peek" method. r=jandem https://hg.mozilla.org/integration/autoland/rev/baf78b746d01 part 8 / 17 (PBL): CacheIR: use fixed 16-bit values for ops rather than packed 15-bit values (for speed). r=jandem https://hg.mozilla.org/integration/autoland/rev/53e0f3409fae part 9 / 17 (PBL): add an auxiliary stack. r=jandem https://hg.mozilla.org/integration/autoland/rev/f7079573e6a6 part 10 / 17 (PBL): Add some needed accessors. r=jandem https://hg.mozilla.org/integration/autoland/rev/021270427b94 part 11 / 17 (PBL): CacheIR fallbacks: make more tolerant of no-decompiler case. r=jandem https://hg.mozilla.org/integration/autoland/rev/0f792335cac1 part 12 / 17 (PBL): miscellaneous ifdefs and null-checks to handle running in new configuration. r=jandem https://hg.mozilla.org/integration/autoland/rev/6b64d50f990c part 13 / 17 (PBL): Add the main implementation of PBL (not yet invoked). r=jandem https://hg.mozilla.org/integration/autoland/rev/72c978283dd4 part 14 / 17 (PBL): invoke the PBL tier from tiering logic. r=jandem https://hg.mozilla.org/integration/autoland/rev/f69064f64ced part 15 / 17 (PBL): Tweak profiling to deal with PBL. r=jandem https://hg.mozilla.org/integration/autoland/rev/81239954a114 part 16 / 17 (PBL): update tests. r=jandem https://hg.mozilla.org/integration/autoland/rev/2c28daffd2b8 part 17 / 17 (PBL): Fix JitStackAlignment. r=jandem
Comment 24•11 months ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/37aabeaab4ce
https://hg.mozilla.org/mozilla-central/rev/50465202ecdb
https://hg.mozilla.org/mozilla-central/rev/94fefa578027
https://hg.mozilla.org/mozilla-central/rev/adeeb6a497ec
https://hg.mozilla.org/mozilla-central/rev/f59766bd98d4
https://hg.mozilla.org/mozilla-central/rev/0e4c337e8a63
https://hg.mozilla.org/mozilla-central/rev/60365e2a3f44
https://hg.mozilla.org/mozilla-central/rev/baf78b746d01
https://hg.mozilla.org/mozilla-central/rev/53e0f3409fae
https://hg.mozilla.org/mozilla-central/rev/f7079573e6a6
https://hg.mozilla.org/mozilla-central/rev/021270427b94
https://hg.mozilla.org/mozilla-central/rev/0f792335cac1
https://hg.mozilla.org/mozilla-central/rev/6b64d50f990c
https://hg.mozilla.org/mozilla-central/rev/72c978283dd4
https://hg.mozilla.org/mozilla-central/rev/f69064f64ced
https://hg.mozilla.org/mozilla-central/rev/81239954a114
https://hg.mozilla.org/mozilla-central/rev/2c28daffd2b8
Updated•10 months ago
|
Description
•