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,530 @@
|
|
|
1
|
+
# Split `JitEmitter.cpp` into logically separated translation units
|
|
2
|
+
|
|
3
|
+
Date: 2026-08-18
|
|
4
|
+
Status: Implemented
|
|
5
|
+
|
|
6
|
+
## Summary
|
|
7
|
+
|
|
8
|
+
Split `lib/VM/JIT/arm64/JitEmitter.cpp`, which is well over eight thousand
|
|
9
|
+
lines, into eleven translation units grouped by what they emit: register
|
|
10
|
+
allocation, object construction, the property protocol, arithmetic,
|
|
11
|
+
control flow, calls, environments, arrays, allocation and constants, with
|
|
12
|
+
the emitter machinery left behind in `JitEmitter.cpp`.
|
|
13
|
+
|
|
14
|
+
The ~40 free `emit_*` helpers currently in an anonymous namespace move
|
|
15
|
+
into a shared helper layer visible to all eleven TUs: the small hot ones
|
|
16
|
+
become `inline` in `JitEmitter-internal.h`, the bulky cold ones get
|
|
17
|
+
external linkage in `JitEmitter-internal.cpp`. Every helper stays reachable
|
|
18
|
+
from every emitter, as today.
|
|
19
|
+
|
|
20
|
+
The work lands as thirteen commits of code motion, each verified to emit
|
|
21
|
+
identical machine code, with measurement done at the end rather than as a
|
|
22
|
+
commit of its own.
|
|
23
|
+
|
|
24
|
+
## Motivation
|
|
25
|
+
|
|
26
|
+
`JitEmitter.cpp` holds two distinct things: a layer of ~40 free `emit_*`
|
|
27
|
+
helpers in an anonymous namespace, and the `Emitter::` definitions that
|
|
28
|
+
implement every JIT-emitted instruction, which are the bulk of the file.
|
|
29
|
+
|
|
30
|
+
The file is hard to navigate and slow to compile as a single translation
|
|
31
|
+
unit. The obstacle to splitting it is the helper layer: the helpers are
|
|
32
|
+
file-local today, so every method body can call any of them, and usage is
|
|
33
|
+
dense and scattered — from a couple of call sites for the rarest to a
|
|
34
|
+
couple of dozen for `emit_sh_ljs_get_pointer`. Splitting the methods
|
|
35
|
+
across translation units forces those helpers to become visible across TU
|
|
36
|
+
boundaries, and with that comes the risk of losing the inlining they get
|
|
37
|
+
today for free.
|
|
38
|
+
|
|
39
|
+
## Goals
|
|
40
|
+
|
|
41
|
+
- Group the emitters so that finding a given instruction is obvious from
|
|
42
|
+
the file name.
|
|
43
|
+
- Keep every file comfortably under ~2,000 lines.
|
|
44
|
+
- Every helper remains callable from every emitter, as today.
|
|
45
|
+
- The emitted machine code is unchanged, to the precision the harness can
|
|
46
|
+
establish (see Verification).
|
|
47
|
+
- No measurable regression in JIT compilation time or binary size.
|
|
48
|
+
|
|
49
|
+
### A note on sizes
|
|
50
|
+
|
|
51
|
+
This split is about logical grouping, not about hitting line targets.
|
|
52
|
+
Sizes in this document are deliberately qualitative: the bar is roughly
|
|
53
|
+
2,000 lines per file, and every grouping below clears it with room to
|
|
54
|
+
spare. Exact line and definition counts are not tracked here and should
|
|
55
|
+
not be added to this spec or to the implementation plan — they go stale
|
|
56
|
+
on every commit and distract from the only question that matters, which
|
|
57
|
+
is whether a file holds one coherent topic.
|
|
58
|
+
|
|
59
|
+
## Out of scope
|
|
60
|
+
|
|
61
|
+
- Splitting `JitEmitter.h`. It is a coherent set of declarations and is
|
|
62
|
+
not the pain point. It does gain four definitions below the class —
|
|
63
|
+
three member templates and the `comment` logger check — because those
|
|
64
|
+
have to be visible to every TU; see the commit stack.
|
|
65
|
+
- Any behavioural change. Every commit is pure code motion.
|
|
66
|
+
- Preparing for an x86-64 port. There is no `lib/VM/JIT/x86*` yet; that
|
|
67
|
+
work should drive its own restructuring when it arrives.
|
|
68
|
+
|
|
69
|
+
## Hard constraint: comments are preserved verbatim
|
|
70
|
+
|
|
71
|
+
Every comment, doc comment, `NOTE:`, and `FIXME` moves with its code
|
|
72
|
+
**unchanged**. This refactor does not reword, reflow, condense, or
|
|
73
|
+
"improve" any prose. The only permitted edits are:
|
|
74
|
+
|
|
75
|
+
- the file-header copyright block on each new file;
|
|
76
|
+
- a doc comment on a helper that moves from an anonymous namespace into a
|
|
77
|
+
header, if and only if it previously said something that the move makes
|
|
78
|
+
false;
|
|
79
|
+
- `\return` / parameter docs that name a type or linkage that the move
|
|
80
|
+
changes.
|
|
81
|
+
|
|
82
|
+
Anything else is out of scope. A reviewer should be able to diff the
|
|
83
|
+
concatenation of the new files against the old one and see only motion.
|
|
84
|
+
|
|
85
|
+
## Final layout
|
|
86
|
+
|
|
87
|
+
| File | Contents |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `JitEmitter.cpp` | prologue/epilogue and emitter machinery |
|
|
90
|
+
| `JitEmitter-regalloc.cpp` | register allocation and frame sync |
|
|
91
|
+
| `JitEmitter-alloc.cpp` | young-gen allocation, GC cell init |
|
|
92
|
+
| `JitEmitter-const.cpp` | constant materialization |
|
|
93
|
+
| `JitEmitter-object.cpp` | object construction and prototype |
|
|
94
|
+
| `JitEmitter-property.cpp` | property access protocol |
|
|
95
|
+
| `JitEmitter-arith.cpp` | conversions, arithmetic, comparison |
|
|
96
|
+
| `JitEmitter-control.cpp` | branches, switches, throw/catch |
|
|
97
|
+
| `JitEmitter-array.cpp` | arrays, iterators, arguments |
|
|
98
|
+
| `JitEmitter-call.cpp` | calls and `this` handling |
|
|
99
|
+
| `JitEmitter-env.cpp` | environments, closures, generators |
|
|
100
|
+
|
|
101
|
+
Plus the helper layer: `JitEmitter-internal.h` / `JitEmitter-internal.cpp`.
|
|
102
|
+
|
|
103
|
+
`JitEmitter-property.cpp` is the largest of these and
|
|
104
|
+
`JitEmitter-alloc.cpp` the smallest; both are fine.
|
|
105
|
+
|
|
106
|
+
### Naming
|
|
107
|
+
|
|
108
|
+
The `JitEmitter-<part>.cpp` form follows the convention already used for
|
|
109
|
+
split files elsewhere in the tree: `FlowChecker.cpp` alongside
|
|
110
|
+
`FlowChecker-expr.cpp` and `FlowChecker-scopetypes.cpp`, and
|
|
111
|
+
`ESTreeIRGen.cpp` alongside `ESTreeIRGen-expr.cpp`,
|
|
112
|
+
`ESTreeIRGen-stmt.cpp`, `ESTreeIRGen-func.cpp` and the rest. Suffixes are
|
|
113
|
+
lowercase, hyphenated where they need more than one word.
|
|
114
|
+
|
|
115
|
+
`JitEmitter-internal.h` follows the same convention, and there is a direct
|
|
116
|
+
precedent for a shared internal header in this exact shape:
|
|
117
|
+
`lib/VM/Interpreter.cpp` sits alongside `Interpreter-slowpaths.cpp` and
|
|
118
|
+
`Interpreter-internal.h`. The out-of-line helper bodies go in
|
|
119
|
+
`JitEmitter-internal.cpp`, so the whole helper layer is one base name and
|
|
120
|
+
one ordinary `.h`/`.cpp` pair. `Interpreter` has no `-internal.cpp`
|
|
121
|
+
because it has little out-of-line internal code; here there is enough that
|
|
122
|
+
it would sit oddly next to `frameSetup` and `emitROData` in the core file.
|
|
123
|
+
|
|
124
|
+
Whether a helper is hot or cold is then not a naming question at all: it
|
|
125
|
+
is just whether the header carries its body or only its declaration.
|
|
126
|
+
|
|
127
|
+
### Per-file contents
|
|
128
|
+
|
|
129
|
+
**`JitEmitter.cpp`** — `Emitter::Emitter`, `enter`, `commentV`,
|
|
130
|
+
`addToRuntime`, `assertPostInstructionInvariants`, `newBasicBlock`,
|
|
131
|
+
`getDebugFunctionName`, `frameSetup`, `leave`, `callThunk`,
|
|
132
|
+
`callThunkWithSavedIP`, `callWithoutThunk`, `emitIncrementCounter`,
|
|
133
|
+
`initHCLazyIDMayAlloc`, `loadFrameAddr`, `getBytecodeIP`, `unreachable`,
|
|
134
|
+
`profilePoint`, `directEval`, `mov`, `loadParam`, `getGlobalObject`,
|
|
135
|
+
`declareGlobalVar`, `debugger`, `createRegExp`, `newPrefLabel`,
|
|
136
|
+
`reserveData`, `uint64Const`, `registerThunk`, `emitCatchTable`,
|
|
137
|
+
`emitSlowPaths`, `emitThunks`, `emitROData`, and the `operator<<` at the
|
|
138
|
+
top of the file.
|
|
139
|
+
|
|
140
|
+
**`JitEmitter-regalloc.cpp`** — `_storeHWToFrame`,
|
|
141
|
+
`movHWFromFR`, `movHWFromMem`, `movFRFromHW`, `syncFrameOutParam`,
|
|
142
|
+
`freeReg`, `syncAndFreeTempReg`, `useReg`, `_spillTempForFR`,
|
|
143
|
+
`syncToFrame`, `syncAllFRTempExcept`, `freeAllFRTempExcept`, `freeFRTemp`,
|
|
144
|
+
`_assignAllocatedLocalHWReg`, `_isFRInRegister`, `getOrAllocFRInVecD`,
|
|
145
|
+
`getOrAllocFRInGpX`, `getOrAllocFRInAnyReg`, `frUpdatedWithHW`,
|
|
146
|
+
`frUpdateType`. Not `movHWFromHW` or `_allocTemp`: they are member
|
|
147
|
+
templates and their definitions live in `JitEmitter.h`.
|
|
148
|
+
|
|
149
|
+
**`JitEmitter-alloc.cpp`** — `bumpAllocAndUnpoison`, `initGCCell`,
|
|
150
|
+
`allocInYoung`, `alloc2InYoung`.
|
|
151
|
+
|
|
152
|
+
**`JitEmitter-const.cpp`** — `loadConstDouble`,
|
|
153
|
+
`loadSmallHermesValueInGpX`, `loadConstStringInGpX`, `loadConstBits64`,
|
|
154
|
+
`loadConstString`, `loadConstBigInt`. Not `loadBits64InGp`, which is a
|
|
155
|
+
member template defined in `JitEmitter.h`.
|
|
156
|
+
|
|
157
|
+
**`JitEmitter-object.cpp`** — `newObject`, `newObjectWithParent`,
|
|
158
|
+
`newObjectWithBuffer`, `newObjectWithBufferSlow`,
|
|
159
|
+
`newObjectWithBufferAndParent`, `newTypedObjectWithBuffer`,
|
|
160
|
+
`loadParentNoTraps`, `typedLoadParent`, `instanceOf`.
|
|
161
|
+
|
|
162
|
+
**`JitEmitter-property.cpp`** — the `GetByIdImpl` class, `getByIdImpl`,
|
|
163
|
+
`getByIdWithReceiver`, `getByVal`, `getByValWithReceiver`, `getByIndex`,
|
|
164
|
+
`putByIdImpl`, `putByValImpl`, `putByValWithReceiver`, `delByVal`,
|
|
165
|
+
`defineOwnById`, `defineOwnInDenseArray`, `defineOwnByIndex`,
|
|
166
|
+
`defineOwnByVal`, `defineOwnGetterSetterByVal`, `getOwnBySlotIdx`,
|
|
167
|
+
`putOwnBySlotIdx`, `addOwnPrivateBySym`, `getOwnPrivateBySym`,
|
|
168
|
+
`putOwnPrivateBySym`, `createPrivateName`, `isIn`, `privateIsIn`. Also the
|
|
169
|
+
`JITNumGetByIdSpec` statistic, whose only uses are here.
|
|
170
|
+
|
|
171
|
+
**`JitEmitter-arith.cpp`** — `toNumber`, `toNumeric`, `toInt32`,
|
|
172
|
+
`addEmptyString`, `arithUnop`, `booleanNot`, `bitNot`, `typeOf`, `addS`,
|
|
173
|
+
`mod`, `arithBinOp`, `bitBinOp`, `strictEqualImpl`, `compareImpl`.
|
|
174
|
+
|
|
175
|
+
**`JitEmitter-control.cpp`** — `jmpTypeOfIs`, `typeOfIs`, `uintSwitchImm`,
|
|
176
|
+
`stringSwitchImm`, `jmpTrueFalse`, `jmp`, `jmpUndefined`, `jmpBuiltinIs`,
|
|
177
|
+
`jCond`, `jStrictEqual`, `throwInst`, `throwIfEmptyUndefinedImpl`,
|
|
178
|
+
`throwIfThisInitialized`, `catchInst`, `ret`.
|
|
179
|
+
|
|
180
|
+
**`JitEmitter-array.cpp`** — `newArray`, `newArrayWithBuffer`, `newFastArray`,
|
|
181
|
+
`fastArrayLength`, `fastArrayLoad`, `fastArrayStore`, `fastArrayPush`,
|
|
182
|
+
`fastArrayAppend`, `iteratorBegin`, `iteratorNext`, `iteratorClose`,
|
|
183
|
+
`getPNameList`, `getNextPName`, `toPropertyKey`, `getArgumentsLength`,
|
|
184
|
+
`getArgumentsPropByValImpl`, `reifyArgumentsImpl`.
|
|
185
|
+
|
|
186
|
+
**`JitEmitter-call.cpp`** — `callImpl`, `call`, `callN`, `callBuiltin`,
|
|
187
|
+
`callWithNewTarget`, `callWithNewTargetLong`, `callRequire`,
|
|
188
|
+
`getBuiltinClosure`, `createThis`, `selectObject`, `loadThisNS`,
|
|
189
|
+
`coerceThisNS`, `getNewTarget`.
|
|
190
|
+
|
|
191
|
+
**`JitEmitter-env.cpp`** — `createTopLevelEnvironment`,
|
|
192
|
+
`createFunctionEnvironment`, `createEnvironment`, `getParentEnvironment`,
|
|
193
|
+
`getEnvironment`, `getClosureEnvironment`, `loadFromEnvironment`,
|
|
194
|
+
`storeToEnvironment`, `createClosure`, `createBaseClass`,
|
|
195
|
+
`createDerivedClass`, `createGenerator`.
|
|
196
|
+
|
|
197
|
+
### Two judgement calls
|
|
198
|
+
|
|
199
|
+
`isIn` goes to property rather than object: `isIn` and `privateIsIn` are
|
|
200
|
+
the same operator over public and private keys, and `privateIsIn` belongs
|
|
201
|
+
with the other private-name operations. `instanceOf` goes to object,
|
|
202
|
+
because it walks the prototype chain like `loadParentNoTraps` and
|
|
203
|
+
`typedLoadParent`.
|
|
204
|
+
|
|
205
|
+
## Helper layer
|
|
206
|
+
|
|
207
|
+
### Placement rule
|
|
208
|
+
|
|
209
|
+
Helpers are placed by kind, not by call site. Every free `emit_*` function
|
|
210
|
+
and every helper class lives in the helper layer and is visible to all
|
|
211
|
+
eleven TUs, regardless of how many callers it has today. The property that
|
|
212
|
+
any emitter can reach for any helper is preserved; only the linkage
|
|
213
|
+
changes.
|
|
214
|
+
|
|
215
|
+
Filing a helper into whichever TU happens to use it today is what erodes a
|
|
216
|
+
shared helper layer, and it removes the option of a future emitter picking
|
|
217
|
+
it up. Do not do it.
|
|
218
|
+
|
|
219
|
+
The one thing that stays TU-local is `Emitter::GetByIdImpl`, and it is not
|
|
220
|
+
a helper: it is a nested class of `Emitter` that *is* the GetById
|
|
221
|
+
implementation, already forward-declared in `JitEmitter.h` and marked
|
|
222
|
+
`HERMES_ATTRIBUTE_INTERNAL_LINKAGE`. It has no second consumer and no
|
|
223
|
+
reuse story. If it ever grows one it moves into the helper layer under the
|
|
224
|
+
rule above.
|
|
225
|
+
|
|
226
|
+
### `JitEmitter-internal.h`, everything `inline`
|
|
227
|
+
|
|
228
|
+
The small, hot helpers:
|
|
229
|
+
|
|
230
|
+
- HermesValue tag and encoding: `emit_sh_ljs_get_tag`,
|
|
231
|
+
`emit_sh_ljs_tag_is_pointer`, `emit_sh_ljs_tag_is_object`,
|
|
232
|
+
`emit_sh_ljs_tag_is_string`, `emit_sh_ljs_get_pointer`,
|
|
233
|
+
`emit_sh_ljs_object`, `emit_sh_ljs_object2`, `emit_sh_ljs_is_double`,
|
|
234
|
+
`emit_sh_ljs_string`, `emit_shv_string`, `emit_sh_ljs_is_object`,
|
|
235
|
+
`emit_sh_ljs_is_string`, `emit_sh_ljs_is_bigint`, `emit_sh_ljs_is_empty`,
|
|
236
|
+
`emit_sh_ljs_is_null`, `emit_sh_ljs_is_bool`, `emit_sh_ljs_is_undefined`,
|
|
237
|
+
`emit_sh_ljs_is_symbol`, `emit_sh_ljs_bool`, `emit_sh_ljs_bool_const`
|
|
238
|
+
- compressed pointers and memory: `emit_sh_cp_decode`,
|
|
239
|
+
`emit_sh_cp_decode_non_null`, `emit_sh_cp_encode_non_null`,
|
|
240
|
+
`emit_load_cp`, `emit_store_cp`, `emit_load_shv`, `emit_store_shv`,
|
|
241
|
+
`emit_load_from_base_offset`, `emit_load_slot16`, `maxNaturalBaseOffset`
|
|
242
|
+
- numeric and cell predicates: `emit_double_is_int`,
|
|
243
|
+
`emit_double_is_uint32`, `emit_gccell_get_kind`, `emit_cellkind_in_range`
|
|
244
|
+
- immediates: `emit_cmp_imm32`, `emit_add_imm_u24`, `isCheapConst`,
|
|
245
|
+
`isStpGpXImm`
|
|
246
|
+
- `class Emit_sh_shv_decode`: members, the inline constructor, and the
|
|
247
|
+
inline `emitAll`
|
|
248
|
+
- the free `emit_sh_shv_decode` wrapper
|
|
249
|
+
- the macros `EXPECT_ERROR`, `EMIT_RUNTIME_CALL`,
|
|
250
|
+
`EMIT_RUNTIME_CALL_WITHOUT_SAVED_IP`,
|
|
251
|
+
`EMIT_RUNTIME_CALL_WITHOUT_THUNK_AND_SAVED_IP`
|
|
252
|
+
- the `-Wmissing-designated-field-initializers` pragma
|
|
253
|
+
|
|
254
|
+
That last item is easy to miss. It currently sits at the top of
|
|
255
|
+
`JitEmitter.cpp` and is required by every TU that constructs a `SlowPath`
|
|
256
|
+
with designated initializers, which is most of them. Putting it in the
|
|
257
|
+
shared header keeps it in one place instead of copied into every TU.
|
|
258
|
+
|
|
259
|
+
### `JitEmitter-internal.h` / `JitEmitter-internal.cpp`
|
|
260
|
+
|
|
261
|
+
The bulky, rarely called helpers get external linkage:
|
|
262
|
+
`emit_jsobject_init`, `emit_environment_init`,
|
|
263
|
+
`emit_stringprim_get_length_and_flags`, `emit_load_builtin_closure`,
|
|
264
|
+
`Emit_sh_shv_decode::emitFirstCase`, `Emit_sh_shv_decode::emitRestCases`,
|
|
265
|
+
and the `OurErrorHandler` and `OurLogger` classes.
|
|
266
|
+
|
|
267
|
+
`Emit_sh_shv_decode` is already shaped for this split: the constructor and
|
|
268
|
+
`emitAll` are small and defined in-class today, while `emitFirstCase` and
|
|
269
|
+
`emitRestCases` are already defined out of line.
|
|
270
|
+
|
|
271
|
+
### Linkage change
|
|
272
|
+
|
|
273
|
+
The anonymous namespace disappears. Helpers move into
|
|
274
|
+
`hermes::vm::arm64` and rely on `inline` (header) or external linkage
|
|
275
|
+
(support). Names are unchanged.
|
|
276
|
+
|
|
277
|
+
## Build system
|
|
278
|
+
|
|
279
|
+
`BUCK` globs `lib/VM/**/*.cpp`, so **new TUs need no BUCK change**. The
|
|
280
|
+
glob is unconditional, which means every new `.cpp` must open with
|
|
281
|
+
|
|
282
|
+
```cpp
|
|
283
|
+
#include "hermes/VM/JIT/Config.h"
|
|
284
|
+
#if HERMESVM_JIT
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
and close with `#endif // HERMESVM_JIT`, exactly as `JitEmitter.cpp` does
|
|
288
|
+
today. Without the guard, non-JIT builds break.
|
|
289
|
+
|
|
290
|
+
`lib/VM/CMakeLists.txt` lists JIT sources explicitly and must be updated
|
|
291
|
+
with each new file.
|
|
292
|
+
|
|
293
|
+
These two facts pull in opposite directions and are the main way a commit
|
|
294
|
+
in this stack can go wrong. BUCK picks up a new `.cpp` on its own, so a
|
|
295
|
+
commit that forgets the CMake entry still builds and tests green under
|
|
296
|
+
`buck2` while being broken for everyone on CMake. The CMake build
|
|
297
|
+
therefore has to be checked per commit, not once at the end.
|
|
298
|
+
|
|
299
|
+
Where the CMake build directory lives depends on the checkout, and this
|
|
300
|
+
spec does not assume either case. On an EdenFS checkout, such as one under
|
|
301
|
+
`~/fbsource`, in-tree CMake build directories do not work, so the build
|
|
302
|
+
directory has to sit outside the repository. On an ordinary filesystem
|
|
303
|
+
checkout the usual in-tree `cmake -B cmake-build-...` is fine and is what
|
|
304
|
+
`CLAUDE.md` describes.
|
|
305
|
+
|
|
306
|
+
Check which one applies before configuring anything, and if it is not
|
|
307
|
+
obvious, ask rather than guessing. The two cases need different commands,
|
|
308
|
+
and a wrong guess costs a full configure and a confusing failure.
|
|
309
|
+
|
|
310
|
+
## Commit stack
|
|
311
|
+
|
|
312
|
+
Thirteen commits of code motion. Each keeps the build and the lit suite
|
|
313
|
+
green. Measurement happens after the last one and produces no commit,
|
|
314
|
+
because the two size fixes it turned up were folded back into the
|
|
315
|
+
commits that caused them rather than appended as cleanup.
|
|
316
|
+
|
|
317
|
+
| # | Commit | Effect |
|
|
318
|
+
| ---: | --- | --- |
|
|
319
|
+
| 1 | Extract hot helpers, macros and pragma to `JitEmitter-internal.h` | still one emitter TU |
|
|
320
|
+
| 2 | Extract cold helpers to `JitEmitter-internal.cpp` | still one emitter TU |
|
|
321
|
+
| 3 | Make the shared `Emitter` definitions visible in `JitEmitter.h` | still one emitter TU |
|
|
322
|
+
| 4 | Move register allocation to `JitEmitter-regalloc.cpp` | first TU split |
|
|
323
|
+
| 5 | Move allocation primitives to `JitEmitter-alloc.cpp` | |
|
|
324
|
+
| 6 | Move constant materialization to `JitEmitter-const.cpp` | |
|
|
325
|
+
| 7 | Move object construction to `JitEmitter-object.cpp` | |
|
|
326
|
+
| 8 | Move the property protocol to `JitEmitter-property.cpp` | |
|
|
327
|
+
| 9 | Move calls to `JitEmitter-call.cpp` | |
|
|
328
|
+
| 10 | Move environments and closures to `JitEmitter-env.cpp` | |
|
|
329
|
+
| 11 | Move arrays, iterators and arguments to `JitEmitter-array.cpp` | |
|
|
330
|
+
| 12 | Move arithmetic and comparison to `JitEmitter-arith.cpp` | |
|
|
331
|
+
| 13 | Move control flow to `JitEmitter-control.cpp` | |
|
|
332
|
+
|
|
333
|
+
Commits 1 and 2 are the load-bearing ones and land while there is still a
|
|
334
|
+
single emitter TU. If moving helpers into a header costs anything, it
|
|
335
|
+
shows up at commit 1, where the only variable is the header extraction and
|
|
336
|
+
nothing has been split yet. That is the cheapest possible place to find
|
|
337
|
+
out.
|
|
338
|
+
|
|
339
|
+
The hot helpers go first and the cold ones second, not the other way
|
|
340
|
+
round. The dependency runs one way: the cold helpers call the hot ones —
|
|
341
|
+
`emit_stringprim_get_length_and_flags` calls `emit_sh_ljs_get_pointer`,
|
|
342
|
+
`emit_jsobject_init` calls `emit_sh_cp_encode_non_null` and
|
|
343
|
+
`emit_store_cp` — and nothing calls back. Moving the cold helpers into
|
|
344
|
+
their own translation unit first would leave them calling helpers still
|
|
345
|
+
private to `JitEmitter.cpp`, and that unit would not compile.
|
|
346
|
+
|
|
347
|
+
Commit 3 exists because `JitEmitter.h` declares three member templates —
|
|
348
|
+
`movHWFromHW`, `_allocTemp` and `loadBits64InGp` — whose definitions live
|
|
349
|
+
in `JitEmitter.cpp`. A template is instantiated only where its definition
|
|
350
|
+
is visible. That is invisible while there is one translation unit and
|
|
351
|
+
becomes undefined references the moment callers live elsewhere. The
|
|
352
|
+
failure is not even uniform: `_allocTemp` is reached only through the
|
|
353
|
+
inline `allocTempGpX()`/`allocTempVecD()` wrappers in the header and is
|
|
354
|
+
instantiated nowhere in the register-allocation group, so it would be
|
|
355
|
+
undefined everywhere, while `loadBits64InGp<a64::GpX>` would happen to be
|
|
356
|
+
instantiated next to its own definition and link by accident, leaving only
|
|
357
|
+
`loadBits64InGp<a64::GpW>` broken. Moving the definitions into the header,
|
|
358
|
+
directly below the class that declares them, is the ordinary fix and needs
|
|
359
|
+
no instantiation list to maintain. It must land before commit 4.
|
|
360
|
+
|
|
361
|
+
Commit 3 also moves the logger check in `Emitter::comment` into the
|
|
362
|
+
header, for an unrelated reason discovered by measurement rather than
|
|
363
|
+
foreseen here: leaving the body in `JitEmitter.cpp` stopped release
|
|
364
|
+
builds from dead-stripping the debug-comment calls once their callers
|
|
365
|
+
moved to other TUs. See "Measured result".
|
|
366
|
+
|
|
367
|
+
Commits 4 through 13 are mechanical and independent of each other; their
|
|
368
|
+
order is not significant beyond doing the small ones first to shake out
|
|
369
|
+
the pattern.
|
|
370
|
+
|
|
371
|
+
## Verification
|
|
372
|
+
|
|
373
|
+
### Per commit
|
|
374
|
+
|
|
375
|
+
1. `buck2 build //xplat/static_h:hermes`
|
|
376
|
+
2. A CMake build of the `hermes` target, to catch a missing
|
|
377
|
+
`lib/VM/CMakeLists.txt` entry that `buck2` cannot see. Which build
|
|
378
|
+
directory to use depends on the checkout — see "Build system" above.
|
|
379
|
+
On the EdenFS checkout this design was written against it was
|
|
380
|
+
`cmake --build ~/work/hws/fbsource-sh-debug --target hermes`, an
|
|
381
|
+
out-of-tree directory configured against `xplat/static_h` with
|
|
382
|
+
`CMAKE_BUILD_TYPE=Debug`, Ninja and `HERMESVM_ALLOW_JIT=2` so that the
|
|
383
|
+
JIT is compiled; verified working on 2026-08-18. On a normal
|
|
384
|
+
filesystem checkout an in-tree build directory does the same job.
|
|
385
|
+
3. `buck2 test //xplat/static_h:lit` — on macOS arm64 this runs the suite
|
|
386
|
+
twice, plain and with `-Xjit=force`, because `jit_enabled` resolves to
|
|
387
|
+
`2` in `BUCK`.
|
|
388
|
+
4. `-Xdump-jitcode=3` output identical to the pre-split baseline over a
|
|
389
|
+
fixed corpus, after canonicalization (see below).
|
|
390
|
+
|
|
391
|
+
**The emitted code is not reproducible run to run, so "byte-identical"
|
|
392
|
+
needs qualifying.** `isCheapConst` in `JitEmitter.cpp` decides between
|
|
393
|
+
materializing a 64-bit constant inline with `mov`/`movk` and spilling it
|
|
394
|
+
to RO data by counting its non-zero 16-bit halfwords. JIT code bakes in
|
|
395
|
+
runtime pointers, so ASLR changes those values every run, the emitter
|
|
396
|
+
genuinely selects different instructions, and every subsequent RO_DATA
|
|
397
|
+
offset shifts with it. Two captures from an *unchanged* binary differed
|
|
398
|
+
in 1,902 lines out of 105,319.
|
|
399
|
+
|
|
400
|
+
Running under `lldb`, which disables ASLR, cuts that to 58 lines but
|
|
401
|
+
does not close it — the contiguous heap's base comes from a separate
|
|
402
|
+
randomized mmap and there is no flag to pin it. It also costs about four
|
|
403
|
+
times the wall clock and needs a macOS permission grant that hangs
|
|
404
|
+
unattended runs, so it was rejected.
|
|
405
|
+
|
|
406
|
+
What the harness therefore compares is the dump with constant
|
|
407
|
+
materialization canonicalized: `mov xN, 0x…` and `ldr xN, [RO_DATA…]`
|
|
408
|
+
collapse to a `CONST xN` token and the RO_DATA table is dropped. That
|
|
409
|
+
leaves **102,221 of 105,319 lines, about 91%, compared byte for byte** —
|
|
410
|
+
every instruction, register, branch, label, ordering and comment. What
|
|
411
|
+
is masked is whether a constant went inline or to RO data, and its
|
|
412
|
+
value. Deterministic across three consecutive captures.
|
|
413
|
+
|
|
414
|
+
Commits 1 through 13 are code motion, so for those *any* difference in
|
|
415
|
+
the canonicalized dump is a bug, not a judgement call.
|
|
416
|
+
|
|
417
|
+
### Measured result
|
|
418
|
+
|
|
419
|
+
Measured on `libhermesvm.dylib` built MinSizeRel, `HEAP_HV_PREFER32`,
|
|
420
|
+
`HERMES_IS_MOBILE_BUILD`, `HERMESVM_ALLOW_JIT=2` and
|
|
421
|
+
`HERMESVM_ALLOW_CONTIGUOUS_HEAP=ON`. Both of the last two matter:
|
|
422
|
+
without `ALLOW_JIT` none of this code is compiled into the library at
|
|
423
|
+
all and the delta is a meaningless zero, and HV32 without a contiguous
|
|
424
|
+
heap makes the JIT refuse to build.
|
|
425
|
+
|
|
426
|
+
| | shipping sections | vs pre-split |
|
|
427
|
+
| --- | ---: | ---: |
|
|
428
|
+
| pre-split | 2,470,898 | — |
|
|
429
|
+
| split, as first written | 2,483,737 | +12,839 (+0.520%) |
|
|
430
|
+
| after both fixes below | 2,474,572 | **+3,674 (+0.149%)** |
|
|
431
|
+
|
|
432
|
+
Two thirds of the initial regression came from something the design did
|
|
433
|
+
not anticipate, and it was not the helpers.
|
|
434
|
+
|
|
435
|
+
**`Emitter::comment` was the dominant cost, and it never moved.** It
|
|
436
|
+
opens with `if (!hasLogger()) return;`, and `hasLogger()` folds to a
|
|
437
|
+
constant false when `ASMJIT_NO_LOGGING` is defined, as it is in release
|
|
438
|
+
builds. While every caller shared a translation unit with the body, the
|
|
439
|
+
compiler deleted the call and dead-stripped the format string. Once the
|
|
440
|
+
callers moved away the body was no longer visible, so each had to
|
|
441
|
+
materialize and pass its string: 4.1KB of `__cstring` plus 4.4KB of
|
|
442
|
+
`__text` in call setup. Fixed by putting the logger check inline in
|
|
443
|
+
`JitEmitter.h` while leaving `vsnprintf` out of line in `commentV`, so
|
|
444
|
+
enabling logging does not duplicate the formatting per TU.
|
|
445
|
+
|
|
446
|
+
**`emit_load_from_base_offset` was the only helper that measurably lost
|
|
447
|
+
inlining**, about 760 bytes. Fixed with `JIT_EMIT_ALWAYS_INLINE`, which
|
|
448
|
+
applies `LLVM_ATTRIBUTE_ALWAYS_INLINE` only under `NDEBUG`.
|
|
449
|
+
|
|
450
|
+
Both fixes are folded into the commits that introduced the respective
|
|
451
|
+
regressions, so no commit in the stack carries one.
|
|
452
|
+
|
|
453
|
+
The residual +3,674 is +2,544 in `__text`, spread thin with no dominant
|
|
454
|
+
symbol, and +1,104 in `__const`. The `__const` share is asmjit
|
|
455
|
+
declaring its register constants as `static constexpr GpX x0 = GpX(0);`
|
|
456
|
+
at namespace scope in a header: `static` forces internal linkage, so
|
|
457
|
+
each of the nine TUs that use them gets a private 16-byte copy that the
|
|
458
|
+
linker may not merge. Nine registers times eight extra copies times 16
|
|
459
|
+
bytes is 1,152, against a measured 1,104. Fixing it means changing
|
|
460
|
+
vendored third-party code to `inline constexpr`.
|
|
461
|
+
|
|
462
|
+
**ThinLTO does not help; it makes both numbers worse.** Same
|
|
463
|
+
configuration plus `-flto=thin` on compile and link: the split costs
|
|
464
|
+
+7,488 bytes rather than +3,674, and the library grows about 39KB
|
|
465
|
+
(+1.58%) whether or not it is split. With twelve modules instead of one,
|
|
466
|
+
ThinLTO imports and inlines across more boundaries. This is a size
|
|
467
|
+
measurement only and says nothing about throughput, which is the usual
|
|
468
|
+
reason to enable it.
|
|
469
|
+
|
|
470
|
+
**On noise floors.** During this work a 64-byte "code size regression"
|
|
471
|
+
was chased down and turned out to be run-to-run variance — the unchanged
|
|
472
|
+
baseline produced the larger figure once in ten runs. The MinSizeRel
|
|
473
|
+
numbers above are from deterministic builds, but any timing comparison
|
|
474
|
+
must establish its spread on a single unchanged binary first.
|
|
475
|
+
|
|
476
|
+
## Risks
|
|
477
|
+
|
|
478
|
+
**Helpers reaching into `Emitter`.** RESOLVED before implementation: no
|
|
479
|
+
free helper touches `Emitter` state. They take `a64::Assembler &` and
|
|
480
|
+
register operands; `OurErrorHandler` holds an `asmjit::Error &` and a
|
|
481
|
+
`std::function`, `OurLogger` an `a64::Assembler &` and a `PerfJitDump *`.
|
|
482
|
+
None needed friendship.
|
|
483
|
+
|
|
484
|
+
**Rebase cost.** Thirteen commits over one large file conflict with any
|
|
485
|
+
concurrent JIT work. The stack should land promptly or be rebased often.
|
|
486
|
+
An auto-restack of C++ can merge cleanly into code that does not compile,
|
|
487
|
+
so build after every restack rather than trusting a conflict-free merge.
|
|
488
|
+
|
|
489
|
+
**A category may read badly as a unit.** The groupings above are drawn
|
|
490
|
+
from how the emitters relate, not from measurement, so one of them could
|
|
491
|
+
turn out to be a bag of unrelated things once it is a file of its own.
|
|
492
|
+
`JitEmitter-property.cpp` is the most likely candidate for a further split,
|
|
493
|
+
along `GetById` / `PutById` / `defineOwn` lines, if it reads that way.
|
|
494
|
+
|
|
495
|
+
**Two small TUs.** `JitEmitter-const.cpp` and `JitEmitter-alloc.cpp` are
|
|
496
|
+
small for standalone files. Both are single coherent concerns, which is
|
|
497
|
+
why they are split, but they are the first candidates to fold back into
|
|
498
|
+
`JitEmitter.cpp` if the file count becomes annoying.
|
|
499
|
+
|
|
500
|
+
## What the implementation actually taught
|
|
501
|
+
|
|
502
|
+
Every problem hit during this split came from the same root: something
|
|
503
|
+
that worked only because there was one translation unit. The design
|
|
504
|
+
foresaw two instances (templates defined in the `.cpp`, non-function
|
|
505
|
+
entities in the anonymous namespace). Three more surfaced only when code
|
|
506
|
+
started moving:
|
|
507
|
+
|
|
508
|
+
- **Ambient includes.** Each new TU exposed a different type that the
|
|
509
|
+
original file received through somebody else's header chain, not its
|
|
510
|
+
own include: `JSObject::maxYoungGenAllocationPropCount` from
|
|
511
|
+
`JSObject-inline.h`, `VTable`/`CellKind` via `Callable.h` →
|
|
512
|
+
`JSObject.h`, `SHRuntimeModule` from `JitHandlers.h`. The rule that
|
|
513
|
+
emerged: include the header that *defines* what you use.
|
|
514
|
+
- **Interprocedural dead-code elimination.** `Emitter::comment` linked
|
|
515
|
+
fine after the split but silently stopped being optimized away. A green
|
|
516
|
+
build proves nothing about this class of regression.
|
|
517
|
+
- **Removing an orphaned include can strand a type.** Deleting
|
|
518
|
+
`Callable.h` was correct, but it left `CellKind` — used four times in
|
|
519
|
+
the same file — arriving only transitively. Grep for the symbols a
|
|
520
|
+
header supplies, not for the header's name.
|
|
521
|
+
|
|
522
|
+
The general lesson: `verify.sh` catches behavioural change, and the
|
|
523
|
+
compiler catches missing declarations, but neither catches "this only
|
|
524
|
+
linked/optimized by accident". Those need reasoning about the code.
|
|
525
|
+
|
|
526
|
+
Known follow-ups, none blocking: `hermes/BCGen/SerializedLiteralParser.h`,
|
|
527
|
+
`hermes/VM/IdentifierTable.h`, `hermes/VM/Interpreter.h` and
|
|
528
|
+
`hermes/VM/StaticHUtils.h` are now unused in `JitEmitter.cpp` and can be
|
|
529
|
+
removed; `JitEmitter-object.cpp` uses `CellKind` without including
|
|
530
|
+
`CellKind.h`.
|