react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hermes/CMakeLists.txt +874 -0
- package/hermes/android/HostObjectJniTest.cpp +178 -0
- package/hermes/android/build-logic/build.gradle.kts +31 -0
- package/hermes/android/build-logic/settings.gradle.kts +17 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
- package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
- package/hermes/android/build.gradle.kts +332 -0
- package/hermes/android/cppruntime/build.gradle +72 -0
- package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
- package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
- package/hermes/android/cross-compile/swift-libicu.patch +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
- package/hermes/android/gradle/libs.versions.toml +30 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/hermes/android/gradle.properties +3 -0
- package/hermes/android/gradlew +248 -0
- package/hermes/android/gradlew.bat +93 -0
- package/hermes/android/intltest/build.gradle +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
- package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
- package/hermes/android/settings.gradle.kts +27 -0
- package/hermes/cmake/modules/Hermes.cmake +481 -0
- package/hermes/cmake/modules/Lit.cmake +96 -0
- package/hermes/doc/Branches.md +38 -0
- package/hermes/doc/BuildingAndRunning.md +121 -0
- package/hermes/doc/CodingStandards.md +112 -0
- package/hermes/doc/CrossCompilation.md +79 -0
- package/hermes/doc/Design.md +217 -0
- package/hermes/doc/Emscripten.md +156 -0
- package/hermes/doc/Features.md +143 -0
- package/hermes/doc/GCSafeCoding.md +563 -0
- package/hermes/doc/GenGC.md +300 -0
- package/hermes/doc/Hades.md +344 -0
- package/hermes/doc/HighLevelOptimizations.md +37 -0
- package/hermes/doc/IR.md +1306 -0
- package/hermes/doc/IntlAPIs.md +196 -0
- package/hermes/doc/JIT.md +999 -0
- package/hermes/doc/LazyEvalCompilation.md +84 -0
- package/hermes/doc/MemoryProfilers.md +316 -0
- package/hermes/doc/Modules.md +144 -0
- package/hermes/doc/Optimizer.md +83 -0
- package/hermes/doc/PerfProfiling.md +29 -0
- package/hermes/doc/ProhibitInvoke.md +329 -0
- package/hermes/doc/ReactNative.md +40 -0
- package/hermes/doc/ReactNativeIntegration.md +94 -0
- package/hermes/doc/RegExp.md +24 -0
- package/hermes/doc/SpecIncompat.md +85 -0
- package/hermes/doc/Strings.md +140 -0
- package/hermes/doc/TypedLanguage.md +432 -0
- package/hermes/doc/VM.md +174 -0
- package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
- package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
- package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
- package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
- package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
- package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
- package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
- package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
- package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
- package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
- package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
- package/hermes/doc/blog/README.md +25 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
- package/hermes/doc/icu_license.txt +420 -0
- package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
- package/hermes/doc/img/logo.svg +1 -0
- package/hermes/doc/img/object_captured_by_environment.png +0 -0
- package/hermes/doc/img/root_categories.png +0 -0
- package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
- package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
- package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
- package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
- package/hermes/doc/plans/ir-type/memory.md +48 -0
- package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
- package/hermes/doc/plans/ir-type/progress.md +239 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
- package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
- package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
- package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
- package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
- package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
- package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
- package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
- package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
- package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
- package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
- package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
- package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
- package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
- package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
- package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
- package/hermes/doc/typescript-stripping.md +90 -0
- package/hermes/external/CMakeLists.txt +20 -0
- package/hermes/utils/IntlGen/IntlGen.java +531 -0
- package/hermes/utils/bench_with_stats.py +827 -0
- package/hermes/utils/build-apple-framework.sh +323 -0
- package/hermes/utils/chrome_snapshot_parser.py +210 -0
- package/hermes/utils/cmake-dev-build.sh +18 -0
- package/hermes/utils/commons.sh +55 -0
- package/hermes/utils/dump-cpp-funcs.sh +3 -0
- package/hermes/utils/es5objects.js +198 -0
- package/hermes/utils/format.sh +145 -0
- package/hermes/utils/gen-promise-internal-bc.sh +66 -0
- package/hermes/utils/genUnicodeTable.py +2503 -0
- package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
- package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
- package/hermes/utils/jit/README.md +134 -0
- package/hermes/utils/jit/jit-diff.sh +160 -0
- package/hermes/utils/jit/jit-dump.sh +193 -0
- package/hermes/utils/lit-expect-gen/generate.py +217 -0
- package/hermes/utils/promise/index.js +15 -0
- package/hermes/utils/promise/package.json +13 -0
- package/hermes/utils/promise/rollup.config.js +19 -0
- package/hermes/utils/promise/yarn.lock +247 -0
- package/hermes/utils/scripts/hermes/consts.js +26 -0
- package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
- package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
- package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
- package/hermes/utils/scripts/hermes/package.json +6 -0
- package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
- package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
- package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
- package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
- package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
- package/hermes/utils/scripts/hermes/version-utils.js +98 -0
- package/hermes/utils/scripts/hermes/yarn.lock +240 -0
- package/hermes/utils/summarize_sizes.py +184 -0
- package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
- package/hermes/utils/test_runner.py +13 -0
- package/hermes/utils/testsuite/README.facebook +3 -0
- package/hermes/utils/testsuite/README.md +69 -0
- package/hermes/utils/testsuite/cli.py +547 -0
- package/hermes/utils/testsuite/es_ast.py +337 -0
- package/hermes/utils/testsuite/external/LICENSE +28 -0
- package/hermes/utils/testsuite/external/README.facebook +8 -0
- package/hermes/utils/testsuite/external/__init__.py +0 -0
- package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
- package/hermes/utils/testsuite/external/parse_test262.py +141 -0
- package/hermes/utils/testsuite/hermes.py +522 -0
- package/hermes/utils/testsuite/preprocess.py +365 -0
- package/hermes/utils/testsuite/progress.py +377 -0
- package/hermes/utils/testsuite/skiplist.json +4356 -0
- package/hermes/utils/testsuite/skiplist.py +270 -0
- package/hermes/utils/testsuite/test_run_defs.py +435 -0
- package/hermes/utils/testsuite/typing_defs.py +52 -0
- package/hermes/utils/testsuite/utils.py +214 -0
- package/hermes/utils/tidy.sh +22 -0
- package/hermes/utils/update-fbcode-hermes.sh +53 -0
- package/hermes/utils/updateErrorTest.py +193 -0
- package/hermes/utils/wasm-compile.sh +65 -0
- package/package.json +1 -1
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
# Design: runtime verification of FR type assumptions (`-Xjit-emit-type-asserts`)
|
|
2
|
+
|
|
3
|
+
## Motivation
|
|
4
|
+
|
|
5
|
+
The JIT elides tag checks and decides GC register residency based on FR type
|
|
6
|
+
facts (`FRState::globalType` / `localType`) that come from three unverified
|
|
7
|
+
sources: the bytecode header's number/non-pointer register counts (i.e. the
|
|
8
|
+
whole front-end pipeline), each emitter's hand-written result-type claims
|
|
9
|
+
(~150 `frUpdatedWithHW` sites), and the `*N` instruction contract
|
|
10
|
+
(`forceNumber`). A wrong fact produces silently wrong JS values (a mistyped
|
|
11
|
+
object NaN-boxes as NaN and flows through `fadd`) or delayed heap corruption
|
|
12
|
+
(a pointer in a NonPtr-class callee-saved register is invisible to the GC).
|
|
13
|
+
Nothing checks any of this at run time; `assertPostInstructionInvariants`
|
|
14
|
+
audits only compile-time bookkeeping.
|
|
15
|
+
|
|
16
|
+
This design adds emitted-code verification of those assumptions under the
|
|
17
|
+
new `emitTypeAsserts_` flag (`-Xjit-emit-type-asserts`, see Configuration), so a violation traps at
|
|
18
|
+
the first instruction that relies on it, with enough metadata to name the
|
|
19
|
+
site. Primary consumer: validating the arm64 backend before the x86-64 port,
|
|
20
|
+
then keeping x86-64 bring-up honest while every emitter is rewritten.
|
|
21
|
+
|
|
22
|
+
## Goals / non-goals
|
|
23
|
+
|
|
24
|
+
Goals:
|
|
25
|
+
|
|
26
|
+
- Trap at the **first consumption** of a value that violates the type fact
|
|
27
|
+
the fast path relied on, and at the **end of the instruction** that
|
|
28
|
+
leaves a global-register-class fact violated (see Class C).
|
|
29
|
+
- **Pure insertion**: the build with the flag on must make byte-identical
|
|
30
|
+
allocation and code-shape decisions to the run with it off, plus
|
|
31
|
+
inserted check sequences. No interaction with `TempRegAlloc`, no new
|
|
32
|
+
spills, no changed LRU state.
|
|
33
|
+
- Actionable diagnostics: failure names the function, bytecode offset, FR,
|
|
34
|
+
and violated predicate.
|
|
35
|
+
|
|
36
|
+
Non-goals:
|
|
37
|
+
|
|
38
|
+
- Not a general verifier. A wrong claim that is never consumed (and not
|
|
39
|
+
covered by the write-side global-class checks) is not caught.
|
|
40
|
+
- Class C validates the front-end's number/non-pointer classification only
|
|
41
|
+
for the FRs that actually received a global register (~16 per function):
|
|
42
|
+
`enter()` records `globalType` only for those, so class claims for the
|
|
43
|
+
overflow FRs are neither used by the JIT nor checkable here. (They are
|
|
44
|
+
also harmless while unused — but a future backend that consumes them
|
|
45
|
+
must extend the recording.)
|
|
46
|
+
- The tag-test helpers themselves (`emit_sh_ljs_is_*`) are trusted; they are
|
|
47
|
+
already covered by static_asserts against the HV encoding.
|
|
48
|
+
- No attempt to keep flags/registers alive across a *failed* check — the
|
|
49
|
+
failure path is noreturn.
|
|
50
|
+
|
|
51
|
+
## Design principles
|
|
52
|
+
|
|
53
|
+
1. **Assert the predicate the fast path relies on, not the declared FRType.**
|
|
54
|
+
Consumption sites know exactly what they exploit: `arithBinOp` relies on
|
|
55
|
+
"is a double", the strict-equality raw-bit tier relies on "not a pointer
|
|
56
|
+
and not a double", global-reg residency relies on "not a pointer". The
|
|
57
|
+
API therefore takes a predicate, not an `FRType`:
|
|
58
|
+
|
|
59
|
+
```cpp
|
|
60
|
+
enum class TypePred : uint8_t {
|
|
61
|
+
IsNumber, // unsigned-below (HVTag_First << kHV_NumDataBits)
|
|
62
|
+
IsBool, // ETag == HVETag_Bool
|
|
63
|
+
NotPointer, // tag unsigned-below the pointer range (GC-safety)
|
|
64
|
+
BitComparable, // NotPointer && !IsNumber: bits are the === identity
|
|
65
|
+
IsObject, // tag == HVTag_Object (typed-invariant sites, phase 2)
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. **Reserved scratch only.** All check sequences use x16/x17 (already
|
|
70
|
+
outside `TempRegAlloc`'s x0–x15 domain, already used as raw scratch by
|
|
71
|
+
`callRuntime`/`callRuntimeWithSavedIP` and by the `_loadFrame`/
|
|
72
|
+
`_storeFrame` encoding fallbacks). Never `allocTempGpX`.
|
|
73
|
+
|
|
74
|
+
3. **Flags-dead placement — a per-site obligation, not a given.** Checks
|
|
75
|
+
clobber NZCV, so each insertion point must be verified flags-dead by the
|
|
76
|
+
author; it is *not* a property emitters have in general. Counterexample:
|
|
77
|
+
`selectObject` sets flags via `emit_sh_ljs_is_object`, then calls
|
|
78
|
+
`getOrAllocFRInGpX`, then consumes the flags in `csel` — flags live
|
|
79
|
+
across an allocation call. None of the Class A/B sites below have that
|
|
80
|
+
shape (their operand materialization precedes their own compare), and
|
|
81
|
+
the Class C hook runs at bytecode-instruction boundaries where NZCV is
|
|
82
|
+
dead by construction, but any future site (Class D especially) must be
|
|
83
|
+
checked, and `emitTypeAssert`'s doc comment must state the obligation.
|
|
84
|
+
Checks are never inserted inside a window where x16 is live; all such
|
|
85
|
+
windows (call-target/IP materialization, the frame-access encoding
|
|
86
|
+
fallbacks) are contained within single helper emissions, so no
|
|
87
|
+
insertion point in this design ever lands inside one.
|
|
88
|
+
`readFRForAssert`'s own frame load may itself take the encoding
|
|
89
|
+
fallback; that is fine — the fallback's x16 use is sequenced before x16
|
|
90
|
+
receives the loaded value.
|
|
91
|
+
|
|
92
|
+
## The check primitive
|
|
93
|
+
|
|
94
|
+
```cpp
|
|
95
|
+
/// Emit (only when emitTypeAsserts_) a trap-on-violation check that the value
|
|
96
|
+
/// of \p fr, currently available in \p hwVal, satisfies \p pred.
|
|
97
|
+
/// Uses only x16/x17. Clobbers NZCV. Must be called when flags are dead.
|
|
98
|
+
void Emitter::emitTypeAssert(FR fr, HWReg hwVal, TypePred pred);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Sequences (input first normalized to a GpX: if `hwVal` is a VecD, emit
|
|
102
|
+
`fmov x16, dN` and check x16; helpers tolerate temp == input):
|
|
103
|
+
|
|
104
|
+
- `IsNumber`: `mov x17, #(HVTag_First << kHV_NumDataBits)` ; `cmp xIn, x17` ;
|
|
105
|
+
`b.hs fail`. (Reuses the `emit_sh_ljs_is_double` shape; the only predicate
|
|
106
|
+
needing both scratch registers when the input is already a GpX.)
|
|
107
|
+
- `IsBool`: `asr x16, xIn, #(kHV_NumDataBits - 1)` ; `cmn x16, #-HVETag_Bool`
|
|
108
|
+
; `b.ne fail` (existing `emit_sh_ljs_is_bool`).
|
|
109
|
+
- `NotPointer`: `asr x16, xIn, #kHV_NumDataBits` ; `cmn x16,
|
|
110
|
+
#-HVTag_FirstPointer` ; `b.hs fail` (inverted `emit_sh_ljs_tag_is_pointer`).
|
|
111
|
+
- `BitComparable`: `IsNumber`-style bound check with inverted branch
|
|
112
|
+
(`b.lo fail`) followed by `NotPointer`.
|
|
113
|
+
- `IsObject`: existing `emit_sh_ljs_is_object` with x16 as temp; `b.ne fail`.
|
|
114
|
+
|
|
115
|
+
For sites where no operand is materialized at all (see `jmpUndefined`
|
|
116
|
+
below), a small read helper loads the FR's current value into x16 directly
|
|
117
|
+
from its best location per `FRState` (local reg → global reg → frame slot),
|
|
118
|
+
again without touching the allocator:
|
|
119
|
+
|
|
120
|
+
```cpp
|
|
121
|
+
/// Read the current value of \p fr into x16 for assertion purposes,
|
|
122
|
+
/// without allocating or perturbing any state.
|
|
123
|
+
void Emitter::readFRForAssert(FR fr);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`readFRForAssert` must honor the FRState up-to-date invariants, not just
|
|
127
|
+
the location priority: read the local reg if one exists (locals always
|
|
128
|
+
hold the latest value), else the global reg **only if
|
|
129
|
+
`globalRegUpToDate`**, else the frame slot (asserting `frameUpToDate`),
|
|
130
|
+
and assert `!regIsDirty` on entry. Reading a stale location would make
|
|
131
|
+
the assert itself report phantom violations — the worst failure mode a
|
|
132
|
+
checking feature can have.
|
|
133
|
+
|
|
134
|
+
## Insertion sites
|
|
135
|
+
|
|
136
|
+
### Class A — `forceNumber` contract sites (highest value)
|
|
137
|
+
|
|
138
|
+
The `*N` bytecodes promise number operands; the emitters skip both checks
|
|
139
|
+
and slow paths. Assert `IsNumber` on every operand. This validates the
|
|
140
|
+
front-end's type inference, not merely the JIT's bookkeeping.
|
|
141
|
+
|
|
142
|
+
| Emitter | Condition | Operands asserted |
|
|
143
|
+
|---|---|---|
|
|
144
|
+
| `arithBinOp` | `forceNumber` (`AddN`, `SubN`, `MulN`, `DivN`) | left, right |
|
|
145
|
+
| `arithUnop` | `forceNumber`, **unreachable today** | input |
|
|
146
|
+
| `jCond` | `forceNumber` (`JLessN`, `JNotLessN`, `JLessEqualN`, `JNotLessEqualN`) | left, right |
|
|
147
|
+
| `mod` | `forceNumber`, **unreachable today** | left, right |
|
|
148
|
+
| `callWithNewTargetLong` | argc `fcvtzu` assumes number | frArgc |
|
|
149
|
+
|
|
150
|
+
The `*N` family is exactly those eight opcodes: there is no `NegateN` or
|
|
151
|
+
`ModN`, every `DECL_UNOP` hardcodes `forceNum = false`, and `mod`'s only
|
|
152
|
+
caller passes `false`. The `arithUnop` and `mod` rows are therefore
|
|
153
|
+
contracts the current bytecode never exercises; they cost nothing to
|
|
154
|
+
assert and cover a future `*N` opcode for free.
|
|
155
|
+
|
|
156
|
+
### Class B — `isFRKnown*` elisions
|
|
157
|
+
|
|
158
|
+
Wherever a fast path skips a check because `isFRKnownNumber/Bool/
|
|
159
|
+
OtherNonPtr` returned true, emit the skipped predicate anyway:
|
|
160
|
+
|
|
161
|
+
| Emitter | Elision | Predicate |
|
|
162
|
+
|---|---|---|
|
|
163
|
+
| `arithBinOp` / `arithUnop` | operand known Number → no NaN-box check, possibly no slow path | `IsNumber` per known operand |
|
|
164
|
+
| `compareImpl` / `jCond` | both known Number → no `b.vs` slow path | `IsNumber` per known operand |
|
|
165
|
+
| `mod` | both known Number → no `fcmp`/`b.vs` slow path | `IsNumber` per known operand |
|
|
166
|
+
| `jmpTrueFalse` | known Number → fcmp-only path; known Bool → tst-only path | `IsNumber` / `IsBool` |
|
|
167
|
+
| `jmpUndefined` | known Number/Bool → **emits nothing** | `IsNumber` or `IsBool`, whichever was relied on, via `readFRForAssert` (no operand is otherwise loaded) |
|
|
168
|
+
| `strictEqualImpl` | side known Bool/OtherNonPtr → raw-bit tier; side known Number → fcmp-only tier | `BitComparable` / `IsNumber` on the known side |
|
|
169
|
+
| `jStrictEqual` | separate emitter, same two tiers as `strictEqualImpl` | `BitComparable` / `IsNumber` on the known side |
|
|
170
|
+
| `toNumber` / `toNumeric` | known Number → early `return mov(...)`, no operand materialized | `IsNumber` via `readFRForAssert` |
|
|
171
|
+
|
|
172
|
+
Where an emitter computes one known-type boolean per operand
|
|
173
|
+
(`arithBinOp`, `mod`, `compareImpl`, `jCond`, `strictEqualImpl`,
|
|
174
|
+
`jStrictEqual`), guard each operand's check on that operand's own
|
|
175
|
+
boolean, never on the emitter's combined fast-path condition (`!slow`).
|
|
176
|
+
Per-operand asserts every fact the JIT holds, at its first appearance,
|
|
177
|
+
rather than only the facts that happen to be load-bearing for the shape
|
|
178
|
+
the emitter chose; with `leftIsNum && !rightIsNum`, `!slow` would assert
|
|
179
|
+
nothing at all.
|
|
180
|
+
|
|
181
|
+
`jmpUndefined` must **not** use `BitComparable` (`NotPointer && !IsNumber`):
|
|
182
|
+
it would trap on every legitimate number reaching the elided path, and it
|
|
183
|
+
accepts `undefined`. Assert the fact the emitter actually tested.
|
|
184
|
+
|
|
185
|
+
`toInt32` is deliberately absent: it has no `isFRKnownNumber` elision, and
|
|
186
|
+
always emits its own check and slow path.
|
|
187
|
+
|
|
188
|
+
### Class C — producer-side checks for global-class FRs (GC direction)
|
|
189
|
+
|
|
190
|
+
Consumption checks cannot cover the GC, whose "consumption" is implicit in
|
|
191
|
+
register residency. Instead, verify on the **producer side**: whenever a
|
|
192
|
+
value is stored into an FR whose `globalType` is `Number` or
|
|
193
|
+
`UnknownNonPtr` (equivalently: any FR that is *eligible* for a
|
|
194
|
+
callee-saved global register), assert the value matches the class:
|
|
195
|
+
|
|
196
|
+
- `globalType == Number` → `IsNumber`
|
|
197
|
+
- `globalType == UnknownNonPtr` → `NotPointer`
|
|
198
|
+
|
|
199
|
+
"Producer side", not "write time": the check is emitted at the *next
|
|
200
|
+
bytecode instruction boundary*, for the reasons argued below, so what it
|
|
201
|
+
validates is the value the FR holds once the writing instruction has
|
|
202
|
+
finished. An instruction that stores a non-conforming value, makes a
|
|
203
|
+
runtime call (a GC safepoint), and then overwrites it with a conforming
|
|
204
|
+
one before it ends passes the check. That gap is not a bug in the
|
|
205
|
+
recording; it follows from the boundary placement, which is the only
|
|
206
|
+
sound hook available.
|
|
207
|
+
|
|
208
|
+
Insertion point: a **post-instruction hook**, not a tail hook in
|
|
209
|
+
`frUpdatedWithHW`. A tail hook there is unsound: many emitters call
|
|
210
|
+
`frUpdatedWithHW` *before* emitting the write into the register (the
|
|
211
|
+
declare-then-write pattern that `FRState::regIsDirty` exists to model —
|
|
212
|
+
e.g. `catchInst` declares the result FR updated and only then emits the
|
|
213
|
+
`ldr` from `thrownValue_`; `callImpl`'s SavedCodeBlock reg, `bitNot`,
|
|
214
|
+
`booleanNot` and `loadThisNS` have the same shape), so the hook would
|
|
215
|
+
check a register that does not yet hold the value — and since
|
|
216
|
+
`frUpdatedWithHW` clears `regIsDirty`, the hook cannot even detect that it
|
|
217
|
+
is in that window. A third write path, `syncFrameOutParam` (the runtime
|
|
218
|
+
wrote the frame slot directly; seven callers), reaches neither
|
|
219
|
+
`frUpdatedWithHW` nor `movFRFromHW` at all.
|
|
220
|
+
|
|
221
|
+
Instead: `frUpdatedWithHW`/`movFRFromHW`/`syncFrameOutParam` merely
|
|
222
|
+
*record* the FR in a small per-instruction written-set (compile-time
|
|
223
|
+
bookkeeping, done only when the flag is on), and a hook invoked at each
|
|
224
|
+
bytecode instruction boundary — alongside the existing compile-time
|
|
225
|
+
`assertPostInstructionInvariants` call in `compileBB` — emits the checks
|
|
226
|
+
for the recorded FRs whose class requires one, then clears the set. At an
|
|
227
|
+
instruction boundary the value is definitionally materialized (that is
|
|
228
|
+
the post-instruction invariant), NZCV is dead by construction, x16/x17
|
|
229
|
+
are free, and all three write paths are covered by a single call site.
|
|
230
|
+
|
|
231
|
+
Guard the check on the *class claim* (`globalType == Number` /
|
|
232
|
+
`UnknownNonPtr`), and separately assert the expected equivalence
|
|
233
|
+
`(globalType != UnknownPtr) == globalReg.isValid()` — today the two
|
|
234
|
+
coincide only because `enter()`'s allocation loops set both together and
|
|
235
|
+
break together; that is a load-bearing coincidence worth pinning with an
|
|
236
|
+
assert rather than silently relying on.
|
|
237
|
+
|
|
238
|
+
### Class D (phase 2, optional) — typed-mode invariants
|
|
239
|
+
|
|
240
|
+
`typedLoadParent`, `fastArray*` element assumptions, and
|
|
241
|
+
`AddS`'s both-strings contract rely on typed-bytecode guarantees. Assert
|
|
242
|
+
`IsObject` / string tag on the inputs. Lower priority: these validate the
|
|
243
|
+
typed front-end rather than the JIT, and typed mode has its own checking
|
|
244
|
+
story, but the hooks are cheap once the primitive exists.
|
|
245
|
+
|
|
246
|
+
## Failure path and diagnostics
|
|
247
|
+
|
|
248
|
+
Each `emitTypeAssert` call registers a compile-time record and embeds its
|
|
249
|
+
index:
|
|
250
|
+
|
|
251
|
+
```cpp
|
|
252
|
+
struct TypeAssertSite { // one entry per emitted check
|
|
253
|
+
CodeBlock *codeBlock;
|
|
254
|
+
uint32_t bytecodeOfs; // codeBlock_->getOffsetOf(emittingIP)
|
|
255
|
+
uint16_t frIndex;
|
|
256
|
+
TypePred pred;
|
|
257
|
+
};
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Emitted failure sequence per site (placed with the slow paths, out of
|
|
261
|
+
line — the inline cost is one conditional branch per predicate leg):
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
fail_N: mov w0, #N
|
|
265
|
+
b typeAssertFailLab
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
There is no per-function metadata mechanism to hang the table on —
|
|
269
|
+
`addToRuntime` returns a bare `JITCompiledFunctionPtr` into
|
|
270
|
+
`setJITCompiled` — and inventing a registry for a fatal-only debugging
|
|
271
|
+
feature is overkill. Instead: **leak** the per-function
|
|
272
|
+
`std::vector<TypeAssertSite>` *object* (the handler never returns, and
|
|
273
|
+
JIT code is never freed anyway), store its address as one RO-data 64-bit
|
|
274
|
+
constant, and have the shared per-function tail materialize it:
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
typeAssertFailLab:
|
|
278
|
+
ldr x1, [RO_DATA + siteTableOfs] // w0 = site idx, set per stub
|
|
279
|
+
bl _jit_type_assert_failed // noreturn
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Leak the vector object, not its buffer: the buffer's address is not final
|
|
283
|
+
until the last site is registered, which is long after the RO-data
|
|
284
|
+
constant has to be emitted, whereas the object's address is stable from
|
|
285
|
+
first use and needs no back-patching.
|
|
286
|
+
|
|
287
|
+
`_jit_type_assert_failed(uint32_t siteIdx, const
|
|
288
|
+
std::vector<TypeAssertSite> *sites)` formats "JIT type assert failed:
|
|
289
|
+
function F, bytecode offset O, rN, expected <pred>", and `hermes_fatal`s.
|
|
290
|
+
It takes no `SHRuntime *`: the site record alone names the function, via
|
|
291
|
+
`CodeBlock::getFunctionID` and `getNameString`. Being noreturn, it needs
|
|
292
|
+
no register/frame preservation, and the call may safely use the normal
|
|
293
|
+
`callRuntime` shape; no change to `addToRuntime`.
|
|
294
|
+
(A bare `brk #N` is an acceptable fallback first implementation — the
|
|
295
|
+
site index in the brk immediate plus the dump-jitcode listing already
|
|
296
|
+
localizes the failure — but the C++ handler costs little and removes the
|
|
297
|
+
need for a debugger to triage.)
|
|
298
|
+
|
|
299
|
+
## Configuration and rollout
|
|
300
|
+
|
|
301
|
+
- **A separate flag, default off** (`-Xjit-emit-type-asserts`, its own
|
|
302
|
+
`emitTypeAsserts_` bool), *not* a rider on `emitAsserts_`:
|
|
303
|
+
`-Xjit-emit-asserts` defaults to **true in debug builds**
|
|
304
|
+
(`RuntimeFlags.h`), so piggybacking would emit the checks in every debug
|
|
305
|
+
lit run, in a feature whose whole premise is that it perturbs nothing
|
|
306
|
+
until asked. A separate opt-in bit also lets a bring-up failure be
|
|
307
|
+
bisected by check class. (Consider subdividing further — A/B vs. C — if
|
|
308
|
+
that bisection proves useful in practice.)
|
|
309
|
+
- Rollout order: land the primitive + Class A/B/C on arm64; run `test/jit`
|
|
310
|
+
(with `HERMESVM_ALLOW_JIT=2`), test262, and the benchmark suite under
|
|
311
|
+
`-Xjit-emit-type-asserts` to certify the *existing* type plumbing; then treat
|
|
312
|
+
a clean assert run as a gating check during x86-64 bring-up.
|
|
313
|
+
|
|
314
|
+
## Verifying the checks can fail
|
|
315
|
+
|
|
316
|
+
A green run proves only that the suite ran. Before trusting the feature,
|
|
317
|
+
mutate and observe the trap (throwaway build):
|
|
318
|
+
|
|
319
|
+
1. Flip one emitter's claim — e.g. make `loadConstString` declare
|
|
320
|
+
`FRType::Number` — and confirm a Class C trap naming that FR.
|
|
321
|
+
2. Weaken one elision — e.g. force `isFRKnownNumber` to return true for one
|
|
322
|
+
FR in `arithBinOp` — and confirm a Class B trap at the consumption site.
|
|
323
|
+
3. Run one `*N` test with the mutation in (2) applied to the `jLessN` path
|
|
324
|
+
to confirm Class A coverage.
|
|
325
|
+
|
|
326
|
+
These three mutations cover the three insertion classes; record the
|
|
327
|
+
expected trap message for each in the commit message of the feature.
|
|
328
|
+
|
|
329
|
+
## Cost
|
|
330
|
+
|
|
331
|
+
- Production builds: zero (everything is behind `emitTypeAsserts_`, which is a
|
|
332
|
+
compile-of-the-JS-function-time flag, not a build-time flag; the checks
|
|
333
|
+
simply are not emitted).
|
|
334
|
+
- With the flag on (in any build): 2-5 instructions per elided check plus
|
|
335
|
+
2 per out-of-line fail stub; site-table memory proportional to check
|
|
336
|
+
count. JIT compile time impact negligible.
|
|
337
|
+
- One new invariant on emitter authors: `emitTypeAssert` must be placed
|
|
338
|
+
while flags are dead. This is enforced socially (it is called from ~10
|
|
339
|
+
central places, not per-emitter) and documented at the primitive.
|
|
340
|
+
|
|
341
|
+
## x86-64 notes
|
|
342
|
+
|
|
343
|
+
- The design requires one (occasionally two) non-allocated scratch GPRs.
|
|
344
|
+
x86-64 has no ABI-reserved analogue of x16/x17, so the port's register
|
|
345
|
+
convention must reserve a caller-saved scratch (r11, optionally r10)
|
|
346
|
+
outside the temp allocator — for this, and for the call-target/IP
|
|
347
|
+
materialization duties x16/x17 already serve on arm64. Decide this up
|
|
348
|
+
front; retrofitting a reserved scratch after the allocator hands out all
|
|
349
|
+
16 GPRs is painful.
|
|
350
|
+
- Predicate sequences translate directly: `sar $47/$48` + `cmp` for tag
|
|
351
|
+
tests, `mov r11, imm64` + `cmp` for the double bound; `ucomisd`-based
|
|
352
|
+
shapes are not needed (all checks are integer tag tests on the raw bits,
|
|
353
|
+
via `movq r11←xmm` for vector-resident values).
|
|
354
|
+
- Class C's write recording (`frUpdatedWithHW`, `movFRFromHW`,
|
|
355
|
+
`syncFrameOutParam`) lives in `JitEmitter-regalloc.cpp` — the
|
|
356
|
+
register-file engine the file split isolated, and the piece proposed for
|
|
357
|
+
cross-arch sharing (cleanup item A3). If that extraction lands first,
|
|
358
|
+
the recording half of Class C is written once for both backends. The
|
|
359
|
+
emission half is the instruction-boundary hook, which each backend calls
|
|
360
|
+
from its own `compileBB` dispatch loop.
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Design: the x86-64 JIT backend
|
|
2
|
+
|
|
3
|
+
## Scope and goals
|
|
4
|
+
|
|
5
|
+
A second JIT backend targeting x86-64 SysV (Linux, macOS, Android
|
|
6
|
+
emulators, server-side Hermes). Windows x64 is explicitly out of scope —
|
|
7
|
+
neither backend supports it today; both will need it eventually, and this
|
|
8
|
+
design avoids gratuitously blocking it (the register convention and ABI
|
|
9
|
+
assumptions live in one place per backend) without designing for it.
|
|
10
|
+
|
|
11
|
+
Both heap modes are supported from the start: HV64, and HV32 (compressed
|
|
12
|
+
pointers with contiguous heap), matching the arm64 gate. Android emulators
|
|
13
|
+
run what ships on Android — HV32 — so an emulator-targeted backend that
|
|
14
|
+
only did HV64 would be testing the wrong configuration.
|
|
15
|
+
|
|
16
|
+
The fast/slow-path structure (what is inlined, what calls a runtime
|
|
17
|
+
helper, how ICs tier) is a property of the runtime model, not the ISA, and
|
|
18
|
+
carries over from arm64 unchanged. Only instruction selection is
|
|
19
|
+
per-CPU. Success for v1 is: full `test/jit` plus the differential stress
|
|
20
|
+
matrix passing natively under ASan, in both heap modes, with perf "sane";
|
|
21
|
+
a measured perf-tuning pass comes after.
|
|
22
|
+
|
|
23
|
+
## Register convention
|
|
24
|
+
|
|
25
|
+
| Role | arm64 | x86-64 SysV |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| xRuntime | x19 | r15 (callee-saved) |
|
|
28
|
+
| xFrame | x20 | r14 (callee-saved) |
|
|
29
|
+
| Native frame pointer | x29 (+x30 record) | rbp (`push rbp; mov rbp, rsp`) |
|
|
30
|
+
| GPR globals | x21–x28 (8) | rbx, r12, r13 (3) |
|
|
31
|
+
| Vector globals | d8–d15 (8) | none (see below) |
|
|
32
|
+
| GPR temps (`TempRegAlloc`) | x0–x15 (16) | rax, rcx, rdx, rsi, rdi, r8, r9, r10 (8) |
|
|
33
|
+
| Vector temps | d0–d7, d16–d31 (24) | xmm0–xmm15 (16) |
|
|
34
|
+
| Reserved scratch, never allocated | x16, x17 | r11 |
|
|
35
|
+
| Helper args / return | x0–x7 / x0 | rdi, rsi, rdx, rcx, r8, r9 / rax |
|
|
36
|
+
|
|
37
|
+
The helper argument registers sit inside the temp pool exactly as x0–x7 do
|
|
38
|
+
on arm64, so `callRuntime`'s sync/free discipline carries over
|
|
39
|
+
unchanged. r11 takes the x16/x17 role: assert and instrumentation
|
|
40
|
+
emission, call-target materialization — anything that must not disturb
|
|
41
|
+
`TempRegAlloc` state. r11 is the traditional linker scratch and never
|
|
42
|
+
carries an argument. rsp stays 16-byte aligned at every call site: the
|
|
43
|
+
fixed frame (after the `push rbp`) is sized to a multiple of 16. No
|
|
44
|
+
red-zone use — emitted code makes calls, so the red zone is unusable
|
|
45
|
+
anyway.
|
|
46
|
+
|
|
47
|
+
rbp is a real frame pointer, not a fourth global. Native unwindability
|
|
48
|
+
through JIT frames (debugger backtraces, `perf` with jitdump, crash
|
|
49
|
+
reports) matters on every target this backend exists for; a 33% bump to
|
|
50
|
+
the scarcest register class does not outweigh it.
|
|
51
|
+
|
|
52
|
+
### Number globals: callee-saved GPRs only
|
|
53
|
+
|
|
54
|
+
SysV has zero callee-saved vector registers, so arm64's "number FRs live
|
|
55
|
+
in d8–d15 for the whole function" mechanism has no direct equivalent. The
|
|
56
|
+
chosen design: the global-assignment loop hands out the three callee-saved
|
|
57
|
+
GPRs to number and non-pointer FRs alike. A number FR's global holds the
|
|
58
|
+
double as raw 64 bits; arithmetic does `movq xmm, gpr` / `movq gpr, xmm`
|
|
59
|
+
(1–2 cycles each way, once per FR per BB with local caching — cheaper than
|
|
60
|
+
a frame round trip, and the value survives calls). This is not new
|
|
61
|
+
machinery: it is arm64's existing overflow behavior (number FRs spill into
|
|
62
|
+
GpX globals when VecD runs out) promoted to the only case. The FR model,
|
|
63
|
+
its invariants, and the eligibility rules from the bytecode header's
|
|
64
|
+
number/non-pointer register counts are unchanged; there is simply one
|
|
65
|
+
global register class instead of two.
|
|
66
|
+
|
|
67
|
+
Alternatives considered and rejected for v1:
|
|
68
|
+
|
|
69
|
+
- **Frame-resident numbers with per-BB xmm caching only.** Loses register
|
|
70
|
+
residency for exactly the bread-and-butter case: loop-carried variables
|
|
71
|
+
reload from the frame at every BB boundary and after every call.
|
|
72
|
+
- **Vector globals by private convention** (reserve xmm8–15, spill live
|
|
73
|
+
ones to their frame slots around every emitted call). Preserves the
|
|
74
|
+
arm64 two-class shape and is free in call-free code, but: (a) the cost
|
|
75
|
+
placement is backwards — real callee-saved registers charge the callee
|
|
76
|
+
once per activation and only if used, while this charges every call site
|
|
77
|
+
of every caller per call executed, and unconditional JS→JS calls are the
|
|
78
|
+
hot path; (b) it weakens the load-bearing invariant that a global
|
|
79
|
+
register is valid whenever `globalRegUpToDate`, adding "unless inside a
|
|
80
|
+
call window" to every consumer, including the type-assert read
|
|
81
|
+
protocol; (c) it halves the vector temp pool while still requiring the
|
|
82
|
+
GPR-global machinery. A targeted refinement — xmm globals only for
|
|
83
|
+
functions whose fast paths contain no unconditional calls, with
|
|
84
|
+
spill/reload confined to cold out-of-line slow paths — is recorded as
|
|
85
|
+
future work if profiles ever show FP-dense call-light loops suffering.
|
|
86
|
+
|
|
87
|
+
## Source tree and sharing strategy
|
|
88
|
+
|
|
89
|
+
New parallel tree `lib/VM/JIT/x86-64/` plus
|
|
90
|
+
`include/hermes/VM/JIT/x86-64/JIT.h` (the dispatcher in
|
|
91
|
+
`include/hermes/VM/JIT/JIT.h` already expects that path and
|
|
92
|
+
`namespace x86_64`), mirroring the arm64 file split one-for-one:
|
|
93
|
+
`JIT.cpp`, `JitEmitter.h`, `JitEmitter-{internal,regalloc,alloc,const,
|
|
94
|
+
object,property,call,env,array,arith,control}`, `JitImpl.h`.
|
|
95
|
+
|
|
96
|
+
Sharing is decided by *how* a piece is shared, not by wish:
|
|
97
|
+
|
|
98
|
+
- **Shared by construction: the Compiler decode driver.** It reads
|
|
99
|
+
bytecode operands (arch-independent by definition) and forwards to
|
|
100
|
+
`Emitter` methods; even its asmjit types (`asmjit::Label`) are
|
|
101
|
+
core-asmjit, not per-arch. It moves to a shared `.cpp` under
|
|
102
|
+
`lib/VM/JIT/`, compiled once against the current arch's emitter via a
|
|
103
|
+
small dispatch header (`JitCurArch.h` defines `HERMESVM_JIT_ARCH_NS`
|
|
104
|
+
and includes the arch's emitter headers under the same `#if`s as
|
|
105
|
+
`JIT/JIT.h`; the driver is compiled inside that namespace, so the
|
|
106
|
+
Compiler stays a nested private class of the arch's `JITContext` with
|
|
107
|
+
zero identifier changes -- a `using` alias cannot express a nested
|
|
108
|
+
class). Not a template: only one arch is ever compiled per binary, and
|
|
109
|
+
the namespace-macro form keeps it an ordinary debuggable class; the
|
|
110
|
+
template conversion is trivial if a both-arches-in-one-binary harness
|
|
111
|
+
is ever wanted. This extraction happens as a prep refactor on the arm64
|
|
112
|
+
side **before** x86-64 work begins, gated on byte-identical arm64
|
|
113
|
+
emission (qemu + goldens). Side effect: the emitter method surface — the
|
|
114
|
+
porting contract — becomes compiler-enforced, and x86-64 bring-up starts
|
|
115
|
+
from an all-stubs `Emitter` where every unimplemented method calls
|
|
116
|
+
`unsupported()` (longjmp to don't-JIT, the existing mechanism).
|
|
117
|
+
- **Shared by likelihood: everything else conceptually common.** The FR
|
|
118
|
+
model and `TempRegAlloc` (`JitEmitter.h`, `-regalloc.cpp`), slow-path/
|
|
119
|
+
catch-table/RO-data emission, `JitImpl.h`, the type-assert machinery:
|
|
120
|
+
same shapes and invariants, but `HWReg` encoding, the global-assignment
|
|
121
|
+
loop, and the LRU pools legitimately differ. These are **copied and
|
|
122
|
+
rewritten in place**; forcing sharing here would constrain both
|
|
123
|
+
backends. Extraction of whatever remains identical happens after both
|
|
124
|
+
backends have settled, from two working instances. Where a copied file
|
|
125
|
+
diverges for a reason (not just encoding), the site gets a
|
|
126
|
+
`// x86-64:` comment so the eventual extraction pass is grep, not
|
|
127
|
+
archaeology.
|
|
128
|
+
- **Already shared, used as-is:** DiscoverBB, RuntimeOffsets, JitHandlers,
|
|
129
|
+
JitCounters, PerfJitDump, and the `_sh_ljs_*` runtime helpers.
|
|
130
|
+
- **Interface contract, not sharing:** `x86_64::JITContext` stays
|
|
131
|
+
method-for-method identical to `arm64::JITContext` — the interpreter and
|
|
132
|
+
ConsoleHost compile against whichever the dispatcher picks. Its methods
|
|
133
|
+
(`compileImpl` policy, `markRoots`, `dumpCounters`) are duplicated
|
|
134
|
+
per-arch for now; they are small, entangled with each arch's `Impl`, and
|
|
135
|
+
in the extract-later bucket.
|
|
136
|
+
|
|
137
|
+
## Emitter specifics
|
|
138
|
+
|
|
139
|
+
**Baseline ISA: AVX, gated by CPUID.** Legacy SSE scalar FP is
|
|
140
|
+
two-operand and destructive, forcing every FP emitter through a
|
|
141
|
+
copy-then-operate shim with aliasing hazards (dst aliasing src2 is
|
|
142
|
+
clobbered by the initial mov). VEX encodings are three-operand
|
|
143
|
+
(`vaddsd dst, src1, src2`), so the FP emitters — most of the arithmetic
|
|
144
|
+
surface — mirror the arm64 code shape one-for-one with no hazard
|
|
145
|
+
class. AVX is universal on every stated target (anything since 2011); on a
|
|
146
|
+
non-AVX CPU a CPUID check at `JITContext` construction leaves the JIT
|
|
147
|
+
disabled and the interpreter carries on — no crash, no build split, the
|
|
148
|
+
existing `enabled_` mechanism. VEX is used consistently for all vector
|
|
149
|
+
instructions; legacy-SSE encodings are never mixed in (transition
|
|
150
|
+
stalls). Integer ops remain two-operand regardless; a small `emit3op`
|
|
151
|
+
helper in `-internal.h` encapsulates mov+op+aliasing so emitter bodies
|
|
152
|
+
stay three-operand in shape.
|
|
153
|
+
|
|
154
|
+
Idiom mappings (details verified at implementation time; the spec fixes
|
|
155
|
+
the approach):
|
|
156
|
+
|
|
157
|
+
- **Frame addressing:** `[r14 + disp32]` reaches every frame slot; the
|
|
158
|
+
`isAddSubImm`/`emit_add_imm_u24` fallback family has no equivalent and
|
|
159
|
+
is not ported.
|
|
160
|
+
- **RO data:** RIP-relative `disp32` reaches data appended to the code
|
|
161
|
+
block by construction; the `ldr`-literal range machinery is not ported.
|
|
162
|
+
- **Tag tests:** same NaN-box algebra; `sar`/`shr` by 47–48 plus `cmp`
|
|
163
|
+
replace `asr` plus `cmn`. The implementation carries a mapping table
|
|
164
|
+
from each arm64 tag-test helper to its x86 sequence.
|
|
165
|
+
- **NaN-aware conditions:** `ucomisd` reports unordered as ZF=PF=CF=1, so
|
|
166
|
+
above-family conditions (`ja`/`jae`) are NaN-safe-false, below-family
|
|
167
|
+
are not, and `jp` takes over arm64's `b.vs` routing role. The full
|
|
168
|
+
condition mapping table is written down in `-internal.h` next to its
|
|
169
|
+
helpers and covered by type asserts from day one.
|
|
170
|
+
- **Calls:** `movabs r11, imm64; call r11` (the reserved scratch doing its
|
|
171
|
+
job); direct `rel32` calls are not assumed reachable.
|
|
172
|
+
|
|
173
|
+
## Testing
|
|
174
|
+
|
|
175
|
+
The backend is developed natively under the repo-default ASan+Debug
|
|
176
|
+
build — the "no ASan under qemu" limitation of arm64 development on this
|
|
177
|
+
host does not apply, and `HERMESVM_SANITIZE_HANDLES` runs at full speed.
|
|
178
|
+
|
|
179
|
+
- **Differential matrix:** `aarch64/jit-stress.js` must print identically
|
|
180
|
+
across {interpreter, arm64 JIT (qemu), x86-64 JIT (native)} × {HV64,
|
|
181
|
+
HV32, BOXED} × {± `-Xjit-emit-type-asserts`}. BOXED forces the
|
|
182
|
+
boxed-double paths on a 64-bit host — where HV32 emitter bugs hide.
|
|
183
|
+
- **Golden tests split by arch:** `test/jit/` keeps all behavior-checking
|
|
184
|
+
tests arch-neutral; emitted-code goldens move to `test/jit/arm64/` and
|
|
185
|
+
grow siblings in `test/jit/x86-64/`, gated by a new lit feature
|
|
186
|
+
`jit_arch` (derived from the target processor in CMake, next to
|
|
187
|
+
`jit_enabled`). Golden files are full-line asm listings; interleaving
|
|
188
|
+
two ISAs via CHECK prefixes was rejected as unmaintainable. Duplicating
|
|
189
|
+
the small JS sources between arch dirs is acceptable — a golden's JS
|
|
190
|
+
exists only to pin emission.
|
|
191
|
+
- **Stubs-first ratchet:** the full `test/jit` suite runs from milestone 1
|
|
192
|
+
(unimplemented opcodes fall back to the interpreter); progress is
|
|
193
|
+
measured by how much of `jit-stress.js` compiles under
|
|
194
|
+
`-Xjit=force -Xjit-crash-on-error`, not a hand-kept checklist.
|
|
195
|
+
- **Cross-arch oracles are behavioral:** the differential matrix, the JIT
|
|
196
|
+
counters (`NumCall`/`NumCallSlow` should match across backends for the
|
|
197
|
+
same workload — an arch-neutral decision-level signal), and the type
|
|
198
|
+
asserts. `jit-diff.sh` remains same-arch tooling: it gates the arm64
|
|
199
|
+
prep refactor (byte-identical) and regression-checks x86-vs-x86 during
|
|
200
|
+
development. Cross-arch, `jit-dump.sh` output is a side-by-side reading
|
|
201
|
+
aid while writing emitters, not a diffable artifact.
|
|
202
|
+
- **CI shape:** native x86-64 {ASan+Debug HV64, ASan+Debug HV32, Release
|
|
203
|
+
HV64} × (`test/jit` + stress), plus the existing qemu arm64 job as the
|
|
204
|
+
cross-check.
|
|
205
|
+
|
|
206
|
+
## Build gating
|
|
207
|
+
|
|
208
|
+
`Config.h` gains the x86-64 arm: `HERMESVM_JIT=1` when
|
|
209
|
+
`__x86_64__`/`_M_X64`, not Windows, same heap condition as arm64 (no
|
|
210
|
+
compressed pointers unless contiguous heap), existing Apple clause
|
|
211
|
+
(macOS/Mac Catalyst only) unchanged. CMake keeps the current pattern: both
|
|
212
|
+
arch subtrees are listed under `HERMESVM_ALLOW_JIT` and every file
|
|
213
|
+
self-guards with `#if HERMESVM_JIT` plus its arch test — no CMake
|
|
214
|
+
arch-dispatch logic. The AVX CPUID check is runtime, not build-time.
|
|
215
|
+
|
|
216
|
+
As implemented, `Config.h` defines `HERMESVM_JIT_ARM64` /
|
|
217
|
+
`HERMESVM_JIT_X86_64` selectors and each arch-specific translation unit
|
|
218
|
+
guards on its own selector; shared files guard on `HERMESVM_JIT`.
|
|
219
|
+
|
|
220
|
+
## Bring-up milestones
|
|
221
|
+
|
|
222
|
+
0. **arm64 prep:** extract the shared Compiler driver (`JitCurArch.h`
|
|
223
|
+
dispatch). Gate: byte-identical arm64 emission via qemu + goldens.
|
|
224
|
+
1. **Skeleton:** Config/CMake/tree, all-stub `Emitter`, `enter`/`leave`,
|
|
225
|
+
param/const loads, `Ret`. An empty function JITs and returns; all else
|
|
226
|
+
falls back.
|
|
227
|
+
2. **Arithmetic, comparisons, branches:** the NaN-routing table plus its
|
|
228
|
+
type asserts; the arith sections of `jit-stress.js` under
|
|
229
|
+
`-Xjit=force -Xjit-crash-on-error`.
|
|
230
|
+
3. **Calls, environments, closures:** the SH ABI frame dance.
|
|
231
|
+
4. **Property access + ICs, literals, young-gen allocation:** the
|
|
232
|
+
GC-facing milestone; HV32/BOXED differential runs become load-bearing.
|
|
233
|
+
5. **Exceptions, switches, iterators/generators, `arguments`:** full
|
|
234
|
+
`jit-stress.js` and full `test/jit` green.
|
|
235
|
+
6. **x86-64 goldens, perf sanity pass, CI matrix wiring.**
|
|
236
|
+
|
|
237
|
+
## Future work (recorded, not designed)
|
|
238
|
+
|
|
239
|
+
- xmm globals for functions whose fast paths contain no unconditional
|
|
240
|
+
calls (spill/reload confined to cold slow paths).
|
|
241
|
+
- An arch-neutral emission-trace mode (one line per bytecode instruction:
|
|
242
|
+
opcode, tier chosen, slow path emitted) for automated decision-level
|
|
243
|
+
cross-arch comparison, if perf gaps ever call for it.
|
|
244
|
+
- Windows x64, in both backends.
|
|
245
|
+
- Extraction of the shared-by-likelihood pieces once both backends have
|
|
246
|
+
settled.
|