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.
Files changed (181) hide show
  1. package/hermes/CMakeLists.txt +874 -0
  2. package/hermes/android/HostObjectJniTest.cpp +178 -0
  3. package/hermes/android/build-logic/build.gradle.kts +31 -0
  4. package/hermes/android/build-logic/settings.gradle.kts +17 -0
  5. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
  6. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
  7. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
  8. package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
  9. package/hermes/android/build.gradle.kts +332 -0
  10. package/hermes/android/cppruntime/build.gradle +72 -0
  11. package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
  12. package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
  13. package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
  14. package/hermes/android/cross-compile/swift-libicu.patch +13 -0
  15. package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
  16. package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
  17. package/hermes/android/gradle/libs.versions.toml +30 -0
  18. package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  19. package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  20. package/hermes/android/gradle.properties +3 -0
  21. package/hermes/android/gradlew +248 -0
  22. package/hermes/android/gradlew.bat +93 -0
  23. package/hermes/android/intltest/build.gradle +147 -0
  24. package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
  25. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
  26. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
  27. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
  28. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
  29. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
  30. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
  31. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
  32. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
  33. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
  34. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
  35. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
  36. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
  37. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
  38. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
  39. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
  40. package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
  41. package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
  42. package/hermes/android/settings.gradle.kts +27 -0
  43. package/hermes/cmake/modules/Hermes.cmake +481 -0
  44. package/hermes/cmake/modules/Lit.cmake +96 -0
  45. package/hermes/doc/Branches.md +38 -0
  46. package/hermes/doc/BuildingAndRunning.md +121 -0
  47. package/hermes/doc/CodingStandards.md +112 -0
  48. package/hermes/doc/CrossCompilation.md +79 -0
  49. package/hermes/doc/Design.md +217 -0
  50. package/hermes/doc/Emscripten.md +156 -0
  51. package/hermes/doc/Features.md +143 -0
  52. package/hermes/doc/GCSafeCoding.md +563 -0
  53. package/hermes/doc/GenGC.md +300 -0
  54. package/hermes/doc/Hades.md +344 -0
  55. package/hermes/doc/HighLevelOptimizations.md +37 -0
  56. package/hermes/doc/IR.md +1306 -0
  57. package/hermes/doc/IntlAPIs.md +196 -0
  58. package/hermes/doc/JIT.md +999 -0
  59. package/hermes/doc/LazyEvalCompilation.md +84 -0
  60. package/hermes/doc/MemoryProfilers.md +316 -0
  61. package/hermes/doc/Modules.md +144 -0
  62. package/hermes/doc/Optimizer.md +83 -0
  63. package/hermes/doc/PerfProfiling.md +29 -0
  64. package/hermes/doc/ProhibitInvoke.md +329 -0
  65. package/hermes/doc/ReactNative.md +40 -0
  66. package/hermes/doc/ReactNativeIntegration.md +94 -0
  67. package/hermes/doc/RegExp.md +24 -0
  68. package/hermes/doc/SpecIncompat.md +85 -0
  69. package/hermes/doc/Strings.md +140 -0
  70. package/hermes/doc/TypedLanguage.md +432 -0
  71. package/hermes/doc/VM.md +174 -0
  72. package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
  73. package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
  74. package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
  75. package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
  76. package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
  77. package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
  78. package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
  79. package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
  80. package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
  81. package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
  82. package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
  83. package/hermes/doc/blog/README.md +25 -0
  84. package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
  85. package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
  86. package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
  87. package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
  88. package/hermes/doc/icu_license.txt +420 -0
  89. package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
  90. package/hermes/doc/img/logo.svg +1 -0
  91. package/hermes/doc/img/object_captured_by_environment.png +0 -0
  92. package/hermes/doc/img/root_categories.png +0 -0
  93. package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
  94. package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
  95. package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
  96. package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
  97. package/hermes/doc/plans/ir-type/memory.md +48 -0
  98. package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
  99. package/hermes/doc/plans/ir-type/progress.md +239 -0
  100. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
  101. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
  102. package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
  103. package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
  104. package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
  105. package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
  106. package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
  107. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
  108. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
  109. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
  110. package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
  111. package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
  112. package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
  113. package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
  114. package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
  115. package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
  116. package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
  117. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
  118. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
  119. package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
  120. package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
  121. package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
  122. package/hermes/doc/typescript-stripping.md +90 -0
  123. package/hermes/external/CMakeLists.txt +20 -0
  124. package/hermes/utils/IntlGen/IntlGen.java +531 -0
  125. package/hermes/utils/bench_with_stats.py +827 -0
  126. package/hermes/utils/build-apple-framework.sh +323 -0
  127. package/hermes/utils/chrome_snapshot_parser.py +210 -0
  128. package/hermes/utils/cmake-dev-build.sh +18 -0
  129. package/hermes/utils/commons.sh +55 -0
  130. package/hermes/utils/dump-cpp-funcs.sh +3 -0
  131. package/hermes/utils/es5objects.js +198 -0
  132. package/hermes/utils/format.sh +145 -0
  133. package/hermes/utils/gen-promise-internal-bc.sh +66 -0
  134. package/hermes/utils/genUnicodeTable.py +2503 -0
  135. package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
  136. package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
  137. package/hermes/utils/jit/README.md +134 -0
  138. package/hermes/utils/jit/jit-diff.sh +160 -0
  139. package/hermes/utils/jit/jit-dump.sh +193 -0
  140. package/hermes/utils/lit-expect-gen/generate.py +217 -0
  141. package/hermes/utils/promise/index.js +15 -0
  142. package/hermes/utils/promise/package.json +13 -0
  143. package/hermes/utils/promise/rollup.config.js +19 -0
  144. package/hermes/utils/promise/yarn.lock +247 -0
  145. package/hermes/utils/scripts/hermes/consts.js +26 -0
  146. package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
  147. package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
  148. package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
  149. package/hermes/utils/scripts/hermes/package.json +6 -0
  150. package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
  151. package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
  152. package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
  153. package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
  154. package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
  155. package/hermes/utils/scripts/hermes/version-utils.js +98 -0
  156. package/hermes/utils/scripts/hermes/yarn.lock +240 -0
  157. package/hermes/utils/summarize_sizes.py +184 -0
  158. package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
  159. package/hermes/utils/test_runner.py +13 -0
  160. package/hermes/utils/testsuite/README.facebook +3 -0
  161. package/hermes/utils/testsuite/README.md +69 -0
  162. package/hermes/utils/testsuite/cli.py +547 -0
  163. package/hermes/utils/testsuite/es_ast.py +337 -0
  164. package/hermes/utils/testsuite/external/LICENSE +28 -0
  165. package/hermes/utils/testsuite/external/README.facebook +8 -0
  166. package/hermes/utils/testsuite/external/__init__.py +0 -0
  167. package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
  168. package/hermes/utils/testsuite/external/parse_test262.py +141 -0
  169. package/hermes/utils/testsuite/hermes.py +522 -0
  170. package/hermes/utils/testsuite/preprocess.py +365 -0
  171. package/hermes/utils/testsuite/progress.py +377 -0
  172. package/hermes/utils/testsuite/skiplist.json +4356 -0
  173. package/hermes/utils/testsuite/skiplist.py +270 -0
  174. package/hermes/utils/testsuite/test_run_defs.py +435 -0
  175. package/hermes/utils/testsuite/typing_defs.py +52 -0
  176. package/hermes/utils/testsuite/utils.py +214 -0
  177. package/hermes/utils/tidy.sh +22 -0
  178. package/hermes/utils/update-fbcode-hermes.sh +53 -0
  179. package/hermes/utils/updateErrorTest.py +193 -0
  180. package/hermes/utils/wasm-compile.sh +65 -0
  181. package/package.json +1 -1
@@ -0,0 +1,261 @@
1
+ # x86-64 JIT Calls, Environments and Closures (Milestone 3) Implementation Plan
2
+
3
+ > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+ **Goal:** The x86-64 JIT compiles and correctly executes function calls
6
+ (direct, N-ary, builtin, construct), environments and closures —
7
+ recursive and higher-order JS runs in machine code — including the
8
+ young-gen inline allocation path that environment creation requires,
9
+ verified natively under ASan.
10
+
11
+ **Architecture:** Port three arm64 files essentially whole:
12
+ `JitEmitter-alloc.cpp` (bump allocation + cell init; pulled forward from
13
+ the spec's milestone 4 because environments allocate inline),
14
+ `JitEmitter-env.cpp` (environments, closures, classes, generators), and
15
+ `JitEmitter-call.cpp` (the SH ABI frame dance, `callImpl`'s
16
+ JIT-to-JIT fast path, builtins, construct), plus the internal helpers
17
+ they use (GC-cell kind checks, compressed-pointer load/store in both
18
+ heap modes, environment init) and `emitIncrementCounter`.
19
+
20
+ **Tech Stack:** as milestone 2 (`cmake-build-x86jit` ASan native,
21
+ `cmake-build-arm64` qemu reference).
22
+
23
+ **Spec:** `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`.
24
+ The free-after-call invariant paragraph in `doc/JIT.md` (added by the
25
+ milestone-2 review) BINDS every emitter in this plan.
26
+
27
+ ## Global Constraints
28
+
29
+ Same as milestone 2 (worktree, no `cd`, x86-64-tree-only changes, arm64
30
+ files as reference with `// x86-64:` divergence comments, VEX only,
31
+ rsp%16==0 at every emitted call, differential lit-test pattern with
32
+ compile-status pinning, full x86 check-hermes + ASan + prove-can-fail
33
+ per task, 80-col, commit trailer). Additions:
34
+
35
+ - **Free-after-call:** every emitted call site must
36
+ `syncAllFRTempExcept`/`freeAllFRTempExcept` exactly as its arm64
37
+ counterpart; the type-assert build turns violations into spurious
38
+ traps, so run each new test with `-Xjit-emit-type-asserts` as a third
39
+ RUN line from the start.
40
+ - **ASan is load-bearing this milestone:** the young-gen bump-allocation
41
+ path must replicate arm64's shadow-memory handling
42
+ (`bumpAllocAndUnpoison`) exactly; our dev build exercises it on every
43
+ allocation. Port any sanitizer conditionals faithfully.
44
+ - **Register conventions for the call fast path** (translating arm64's
45
+ x0/x1/x2 usage in `callImpl`): rdi = Runtime (first SysV arg),
46
+ rsi = Callable* (second arg to the jitCall/compiled function), the
47
+ loaded call target goes in a third register — use rax or rdx (NOT r11
48
+ if the slow path needs the value across its own materializations;
49
+ choose and document). All temps are free at that point (arm64 relies
50
+ on the same fact).
51
+ - Compressed-pointer helpers (`emit_load_cp`/`emit_store_cp` etc.) are
52
+ ported with BOTH `#ifdef HERMESVM_COMPRESSED_POINTERS` branches for
53
+ arm64 parity, even though the dev build only exercises HV64; the HV32
54
+ build matrix arrives with the next milestone per the spec.
55
+
56
+ ---
57
+
58
+ ### Task 1: Allocation, environments, closures
59
+
60
+ **Files:**
61
+ - Create: `lib/VM/JIT/x86-64/JitEmitter-alloc.cpp`,
62
+ `lib/VM/JIT/x86-64/JitEmitter-env.cpp`
63
+ - Modify: `JitEmitter.h` (declarations), `JitEmitter-internal.h`
64
+ (helpers), `JitEmitter-stubs.cpp` (remove implemented stubs),
65
+ `lib/VM/CMakeLists.txt` (new sources)
66
+ - Create: `test/jit/x86-64/closures.js`
67
+
68
+ **Port sources (arm64):** `JitEmitter-alloc.cpp` whole (17-140:
69
+ `bumpAllocAndUnpoison`, `initGCCell`, `allocInYoung`, `alloc2InYoung`);
70
+ `JitEmitter-env.cpp` whole (16-453: createTopLevelEnvironment,
71
+ createFunctionEnvironment, createEnvironment, getParentEnvironment,
72
+ getEnvironment, getClosureEnvironment, loadFromEnvironment,
73
+ storeToEnvironment, createClosure, createBaseClass, createDerivedClass,
74
+ createGenerator); from `JitEmitter-internal.h` exactly the helpers these
75
+ bodies use (expect `emit_load_cp`/`emit_store_cp`/`emit_sh_cp_*`,
76
+ `emit_environment_init`, `emit_sh_ljs_object`, `emit_load_shv`/
77
+ `emit_store_shv`, plus whatever `allocInYoung` needs for the Hades
78
+ young-gen fields in `RuntimeOffsets`).
79
+
80
+ Emitters removed from stubs: CreateTopLevelEnvironment,
81
+ CreateFunctionEnvironment, CreateEnvironment, GetParentEnvironment,
82
+ GetEnvironment, GetClosureEnvironment, LoadFromEnvironment(L),
83
+ StoreToEnvironment(L)/StoreNPToEnvironment(L), CreateClosure
84
+ (+LongIndex), CreateBaseClass(+LongIndex), CreateDerivedClass
85
+ (+LongIndex), CreateGenerator(+LongIndex).
86
+
87
+ Translation notes: `ldur` with signed offsets → `mov` with negative
88
+ disp32 (frame slots below xFrame use the same `frMem` idiom milestone 1
89
+ established); the store-pair `stp` fills inside `emit_environment_init`
90
+ → paired `mov`/`vmovups` per milestone 1's fill-loop precedent; the
91
+ write barrier question does NOT arise here (arm64's env init relies on
92
+ young-gen allocation + the frame being the root — keep its structure
93
+ and its comments, which explain why).
94
+
95
+ - [ ] **Step 1: Port `JitEmitter-alloc.cpp` + its helpers; build.**
96
+ - [ ] **Step 2: Port `JitEmitter-env.cpp` in arm64's function order,
97
+ building after each function; remove stubs as implemented.**
98
+ - [ ] **Step 3: Test `test/jit/x86-64/closures.js`** — differential +
99
+ compile-status + type-asserts RUN lines. Body (no array/object
100
+ literals, no string ops — they still decline):
101
+
102
+ ```js
103
+ function mkCounter(start) {
104
+ var n = start;
105
+ return function () {
106
+ n = n + 1;
107
+ return n;
108
+ };
109
+ }
110
+ function mkAdder(a) {
111
+ return function (b) {
112
+ return a + b;
113
+ };
114
+ }
115
+ function nest(x) {
116
+ var y = x * 2;
117
+ function inner() {
118
+ var z = y + 1;
119
+ function innermost() {
120
+ return z + y + x;
121
+ }
122
+ return innermost();
123
+ }
124
+ return inner();
125
+ }
126
+ var c = mkCounter(10);
127
+ print(c());
128
+ print(c());
129
+ print(c());
130
+ var add5 = mkAdder(5);
131
+ print(add5(3));
132
+ print(add5(-0.5));
133
+ print(nest(7));
134
+ ```
135
+
136
+ Note `inner()`/`innermost()` CALLS decline in Task 1 (calls land in
137
+ Task 2) — so `nest` itself will not compile yet; keep it in the file
138
+ with its compile-status CHECK added in TASK 2, and in Task 1 pin only
139
+ `mkCounter`, `mkAdder`, and the two returned closures ("anonymous"
140
+ functions — get their real status-line names from the dump). The
141
+ returned closures ARE executed compiled (invoked via interpreter
142
+ dispatch from the global function), so the differential is real.
143
+ - [ ] **Step 4: Gates + prove-can-fail** — full x86 check-hermes, ASan.
144
+ Deliberate break: make `emit_environment_init` skip the slot-fill for
145
+ odd sizes (or off-by-one the loop); closures.js must fail (GC-visible
146
+ garbage or wrong values); revert, re-verify. Under ASan the
147
+ unpoison path is additionally exercised on every allocation — state in
148
+ the report whether any ASan-specific code was needed beyond arm64's.
149
+ - [ ] **Step 5: Commit** — "JIT: x86-64 environments, closures and
150
+ young-gen allocation".
151
+
152
+ ---
153
+
154
+ ### Task 2: Calls
155
+
156
+ **Files:**
157
+ - Create: `lib/VM/JIT/x86-64/JitEmitter-call.cpp`
158
+ - Modify: `JitEmitter.h`, `JitEmitter-internal.h` (gccell/cellkind
159
+ helpers), `JitEmitter.cpp` (`emitIncrementCounter`, standalone
160
+ `getBytecodeIP` if not already factored), `JitEmitter-stubs.cpp`,
161
+ `lib/VM/CMakeLists.txt`
162
+ - Create: `test/jit/x86-64/calls.js`
163
+ - Modify: `test/jit/x86-64/closures.js` (enable `nest`'s CHECK)
164
+
165
+ **Port sources (arm64):** `JitEmitter-call.cpp` whole (19-567:
166
+ createThis, selectObject, loadThisNS, coerceThisNS, getNewTarget,
167
+ callImpl, call, callN, callBuiltin, callWithNewTarget,
168
+ callWithNewTargetLong, callRequire, getBuiltinClosure) — note
169
+ `selectObject` carries an `emitTypeAssert` site (the 23rd; arm64
170
+ JitEmitter-call.cpp:513-ish) and its guard-ordering subtlety is
171
+ documented in the type-assert design docs; port verbatim.
172
+ `emitIncrementCounter` from arm64 `JitEmitter.cpp:606-` (loads the
173
+ counter array pointer from `RuntimeOffsets::runtimeJitCounters`, then a
174
+ 64-bit increment — on x86 a single
175
+ `inc qword ptr [reg + idx*8]` after the pointer load).
176
+ Helpers: `emit_gccell_get_kind`, `emit_cellkind_in_range` (the
177
+ sub+unsigned-compare range trick — translate to 32-bit `lea`/`sub` +
178
+ `cmp`+`ja`), `emit_load_builtin_closure`.
179
+
180
+ `callImpl` mapping (the milestone's core): outgoing frame slots are set
181
+ through the FR machinery exactly as arm64 (the outgoing area is part of
182
+ `frameRegs_`); object check → `emit_sh_ljs_get_pointer` → cell kind →
183
+ CodeBlockFunctionKind range check → `codeBlockJitPtr` null check →
184
+ direct `call`; slow path indexes `VTable::jitCallArray` by kind. The
185
+ called function (both paths) receives rdi = Runtime, rsi = Callable*;
186
+ keep the kind in the register the slow path expects (arm64 keeps kind in
187
+ x0, callee in x1, target in x2 — map to eax/rsi/+target and keep the
188
+ fast/slow register contract IDENTICAL between the two paths, as arm64
189
+ does; document the chosen mapping in one comment above `callImpl`).
190
+ `getBytecodeIP` on x86 is an absolute `mov reg, imm64` (the bytecode
191
+ address is a process constant — milestone 1 established this in
192
+ `callRuntimeWithSavedIP`; factor to share if not already).
193
+ The non-object-call shared slow path (`nonObjCallLabel_`) ports as-is.
194
+
195
+ - [ ] **Step 1: Port helpers + `emitIncrementCounter`; build.**
196
+ - [ ] **Step 2: Port `JitEmitter-call.cpp` in arm64 order, building per
197
+ function; remove stubs.**
198
+ - [ ] **Step 3: Test `test/jit/x86-64/calls.js`** — differential +
199
+ compile-status + type-asserts RUNs, PLUS a fourth RUN with
200
+ `-Xjit-emit-counters` FileCheck'ing `NumCall:` > 0 (match the exact
201
+ dumpCounters format; a plain `CHECK: NumCall: {{[1-9][0-9]*}}` is
202
+ enough). Body must cover:
203
+ - direct recursion (`fib(15)` iterative-free version),
204
+ - mutual recursion (`isEven`/`isOdd` on 20),
205
+ - Call1-4 arities (functions of 1-4 params called with exact arity),
206
+ - `new` observed through a compiled wrapper: `function C() {}` (an
207
+ empty constructor compiles — LoadConstUndefined+Ret) and
208
+ `function mk() { return new C(); }`; observe `mk() === mk()`
209
+ printing false (strict-equal on two distinct objects, already
210
+ ported) and `mk() === mk` printing false, which exercises
211
+ createThis + callWithNewTarget without property access,
212
+ - non-callable callees are NOT tested here — that path throws, and
213
+ exceptions are a later milestone; say so in the test header,
214
+ - higher-order: a compiled function taking a compiled callback and
215
+ invoking it in a loop.
216
+ Get all CHECK values from the interpreter.
217
+ - [ ] **Step 4: Static-builtins coverage.** Add a second test
218
+ `test/jit/x86-64/callbuiltin.js` whose RUN lines pass
219
+ `-fstatic-builtins` on BOTH the interpreter and JIT invocations, with
220
+ a body using `Math.floor`/`Math.abs`-style calls on numbers inside a
221
+ compiled function — this emits CallBuiltin/GetBuiltinClosure without
222
+ needing property access. Verify via `-Xdump-jitcode=2` CHECKs that the
223
+ function compiles (if the bytecode still contains unsupported opcodes,
224
+ adjust the body until it does; state the final opcode census in the
225
+ report).
226
+ - [ ] **Step 5: Enable `nest` in closures.js** (its calls now compile);
227
+ update its CHECKs.
228
+ - [ ] **Step 6: Gates + prove-can-fail.** Full suite, ASan. Deliberate
229
+ break: swap rsi/rdi in `callImpl`'s final call sequence — calls.js
230
+ must crash or miscompile loudly; revert, re-verify. ALSO re-run the
231
+ 497-file differential sweep from milestone 2 (script or loop over
232
+ test/hermes/*.js comparing interpreter vs -Xjit=force output) — with
233
+ calls landed, far more functions compile, making the sweep much
234
+ stronger; require zero diffs, and report how many files now compile at
235
+ least one function.
236
+ - [ ] **Step 7: Commit** — "JIT: x86-64 calls".
237
+
238
+ ---
239
+
240
+ ### Task 3: Docs and the arm64 cross-check
241
+
242
+ **Files:** `doc/JIT.md` (status paragraph: calls/env/closures; the
243
+ young-gen note that alloc moved up a milestone), nothing else.
244
+
245
+ - [ ] **Step 1: Update the status paragraph** (≤30 lines total now).
246
+ - [ ] **Step 2: arm64 insurance run** (same three commands as milestone
247
+ 2's Task 5; dumps must be identical to
248
+ `cmake-build-arm64/jit-baseline.dump`, 46 lit passes expected,
249
+ report the unsupported count).
250
+ - [ ] **Step 3: Commit** — "doc: x86-64 JIT milestone-3 status".
251
+
252
+ ---
253
+
254
+ ## Out of scope
255
+
256
+ Property access and ICs, object/array literals, strings (AddS,
257
+ addEmptyString), typeof/instanceof/in, switches, exceptions/try,
258
+ iterators/generators-resume (CreateGenerator only creates the object),
259
+ for-in, `arguments`, HV32/BOXED matrix, goldens. `jmpUndefined` remains
260
+ unreachable (for-in). Slow-path-only fallbacks stay wherever arm64 has
261
+ them.
@@ -0,0 +1,240 @@
1
+ # x86-64 JIT Property Access, ICs and Literals (Milestone 4) Implementation Plan
2
+
3
+ > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+ **Goal:** The x86-64 JIT compiles and correctly executes object and array
6
+ literals, property reads/writes through the three-tier inline caches,
7
+ globals, and the fast-array family — real object-oriented JS runs in
8
+ machine code — and the HV32/BOXED build matrix becomes load-bearing,
9
+ compiling the compressed-pointer branches for the first time.
10
+
11
+ **Architecture:** Port three arm64 files: `JitEmitter-object.cpp` whole
12
+ (literal buffers are `alloc2InYoung`'s first caller; needs
13
+ `initHCLazyIDMayAlloc` from arm64 `JitEmitter.cpp` — the HiddenClass
14
+ lazy-JIT-ID pinning through `usedHCs`), `JitEmitter-property.cpp` whole
15
+ (the `GetByIdImpl` IC engine: object-specialization, parent-
16
+ specialization, generic tiers; `putByIdImpl`; plus `getGlobalObject`/
17
+ `declareGlobalVar` from arm64 `JitEmitter.cpp`), and the array/fast-array
18
+ subset of `JitEmitter-array.cpp` (iterators/arguments/for-in stay in
19
+ milestone 5). Then stand up the HV32 and BOXED builds and make the
20
+ differential matrix pass.
21
+
22
+ **Tech Stack:** as before, plus two new build trees:
23
+ `cmake-build-x86jit-hv32` (`-DHERMESVM_HEAP_HV_MODE=HEAP_HV_PREFER32`)
24
+ and `cmake-build-x86jit-boxed` (`-DHERMESVM_HEAP_HV_MODE=HEAP_HV_BOXED`),
25
+ both ASan+Debug -O1 clang with `-DHERMESVM_ALLOW_JIT=2`.
26
+
27
+ **Spec:** `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`
28
+ (milestone 4; the Testing matrix). The free-after-call invariant and the
29
+ allocation-helper preconditions in `doc/JIT.md`/`JitEmitter.h` BIND all
30
+ emitters here.
31
+
32
+ ## Global Constraints
33
+
34
+ Same as milestones 2-3 (worktree, no `cd`, arm64 files as reference with
35
+ `// x86-64:` divergence comments, VEX only, rsp%16==0 at calls,
36
+ differential lit pattern with compile-status pinning at BOTH -O and -O0
37
+ where a -O0 RUN exists, full x86 check-hermes + ASan + prove-can-fail
38
+ per task, 80-col, commit trailer). Additions:
39
+
40
+ - **GC pinning discipline:** HiddenClass references from emitted code are
41
+ lazy JIT IDs, never raw pointers; every HC used gets pinned via
42
+ `initHCLazyIDMayAlloc`/`usedHCs` exactly as arm64 does. Any deviation
43
+ is a Critical review finding.
44
+ - **The allocation-helper preconditions** (no live vector temp, nothing
45
+ in r11, out/temp not r11 across `allocInYoung`/`alloc2InYoung`) now
46
+ have many new call sites — cite the precondition comment at each new
47
+ call site that is not a direct arm64 transcription.
48
+ - **Carry-over obligations embedded in this plan:** `alloc2InYoung`'s
49
+ first caller (Task 1); `createTopLevelEnvironment` coverage +
50
+ `getGlobalObject`/`declareGlobalVar` (Task 2); `emit_double_is_uint32`
51
+ port when the array paths need it (Task 3); the cp-helper HV32
52
+ branches' first compile (Task 4).
53
+
54
+ ---
55
+
56
+ ### Task 1: Objects and object-literal buffers
57
+
58
+ **Files:**
59
+ - Create: `lib/VM/JIT/x86-64/JitEmitter-object.cpp`
60
+ - Modify: `JitEmitter.h`, `JitEmitter-internal.h` (helpers:
61
+ `emit_jsobject_init`, `emit_load_slot16`, whatever `newObjectWithBuffer`
62
+ uses), `JitEmitter.cpp` (`initHCLazyIDMayAlloc` ported from arm64
63
+ `JitEmitter.cpp` — find it there), `JitEmitter-stubs.cpp`,
64
+ `lib/VM/CMakeLists.txt`
65
+ - Create: `test/jit/x86-64/objects.js`
66
+
67
+ **Port sources (arm64):** `JitEmitter-object.cpp` whole (19-663:
68
+ newObject, newObjectWithParent, newObjectWithBuffer +
69
+ newObjectWithBufferSlow, newObjectWithBufferAndParent,
70
+ newTypedObjectWithBuffer, loadParentNoTraps, typedLoadParent,
71
+ instanceOf); `initHCLazyIDMayAlloc` and its `hcIdLimit`/`kHCIdOverflow`
72
+ handling from arm64 `JitEmitter.cpp` (the `usedHCs` push + overflow
73
+ decline). `newObjectWithBuffer` is the milestone's hardest single
74
+ emitter (~320 lines: shape-table lookup, HC lazy-ID guard, inline
75
+ young-gen allocation of object + property storage via `alloc2InYoung`,
76
+ buffer-driven slot init) — port it last, building intermediates.
77
+
78
+ **Test `objects.js`:** object literals ({a:1,...} — compile at last!),
79
+ nested literals, `new` with property-storing constructors, prototype
80
+ reads via `loadParentNoTraps`? (that opcode comes from `Object.getPrototypeOf`
81
+ patterns — check what emits it and cover if reachable), `instanceof`
82
+ (now portable), shape variety (several literals with distinct shapes to
83
+ touch multiple HC ids), and a churn loop allocating literals under GC
84
+ pressure. Differential + compile-status + type-asserts (+ -O0 pinned)
85
+ RUN lines. CHECK values from the interpreter.
86
+
87
+ **Gates + prove-can-fail:** full suite + ASan; deliberate break: skip
88
+ the `usedHCs` pinning for one path (or mis-scale a buffer slot offset)
89
+ — objects.js must fail (GC stress churn should catch the pinning break;
90
+ if the pinning break is not observable within this test, escalate the
91
+ churn until it is or use the slot-offset break and RECORD the pinning
92
+ break's non-observability honestly for the review). Commit:
93
+ "JIT: x86-64 objects and object-literal buffers".
94
+
95
+ ---
96
+
97
+ ### Task 2: Property access, ICs and globals
98
+
99
+ **Files:**
100
+ - Create: `lib/VM/JIT/x86-64/JitEmitter-property.cpp`
101
+ - Modify: `JitEmitter.h` (GetByIdImpl class decl if arm64 declares it in
102
+ the header — mirror), `JitEmitter-internal.h`
103
+ (`emit_stringprim_get_length_and_flags` etc. as needed),
104
+ `JitEmitter.cpp` (getGlobalObject, declareGlobalVar — tiny, arm64
105
+ JitEmitter.cpp:847-864), `JitEmitter-stubs.cpp`, CMakeLists
106
+ - Create: `test/jit/x86-64/props.js`
107
+ - Modify: `test/jit/x86-64/closures.js` (createTopLevelEnvironment
108
+ coverage — see below)
109
+
110
+ **Port sources:** `JitEmitter-property.cpp` whole (25-1107). The
111
+ `GetByIdImpl` nested class (:236-598) is the IC engine — port its tier
112
+ structure, guard ordering, and cache-entry field accesses exactly;
113
+ `putByIdImpl` (:745-799) mirrors it for writes. All getById/putById/
114
+ tryGetById/tryPutById/defineOwn*/getOwnBySlotIdx/putOwnBySlotIdx/
115
+ getByVal/putByVal/delByVal/private-name/isIn emitters ride on those
116
+ impls or are runtime calls — port all. Then getGlobalObject +
117
+ declareGlobalVar from JitEmitter.cpp.
118
+
119
+ **createTopLevelEnvironment coverage (carry-over, MANDATORY):** with
120
+ globals landing, `global` may finally compile for simple scripts. Add to
121
+ closures.js (or a new globals.js if cleaner) a compile-status CHECK that
122
+ `global` itself compiles in at least one RUN configuration, which
123
+ executes createTopLevelEnvironment in compiled code. If `global` still
124
+ declines (name the blocking opcode from the dump), you MUST say so in
125
+ the report and the test header — do not silently drop the obligation.
126
+
127
+ **Test `props.js`:** the jit-stress props() pattern — constructor +
128
+ prototype method + getter via defineProperty (getter call goes through
129
+ the IC), monomorphic loop (object-specialization tier), shape transition
130
+ mid-loop (`p.extra = 1`), polymorphic then megamorphic call sites (several
131
+ shapes through one site), `delete`, `in`, string-keyed getByVal, global
132
+ variable reads/writes in compiled functions. Differential +
133
+ compile-status + type-asserts + counters(-Xjit-emit-counters, NumCallSlow
134
+ now moves too) RUNs; -O0 variants pinned.
135
+
136
+ **Gates + prove-can-fail:** full suite + ASan; deliberate break: corrupt
137
+ the IC guard (compare against the wrong cache field, e.g. read the
138
+ parent-specialization tier's class where the object tier's is meant) —
139
+ props.js's shape-transition case must produce wrong values or crash;
140
+ revert, re-verify. Commit: "JIT: x86-64 property access, inline caches
141
+ and globals".
142
+
143
+ ---
144
+
145
+ ### Task 3: Arrays and fast arrays
146
+
147
+ **Files:**
148
+ - Create: `lib/VM/JIT/x86-64/JitEmitter-array.cpp`
149
+ - Modify: `JitEmitter.h`, `JitEmitter-internal.h`
150
+ (`emit_double_is_uint32` — the deferred port; x86: vcvttsd2si +
151
+ cvtsi round-trip with an unsigned-range check — derive from the
152
+ arm64 fcvtzu structure and DOCUMENT the equivalence argument like
153
+ milestone 2's toInt32), `JitEmitter-stubs.cpp`, CMakeLists
154
+ - Create: `test/jit/x86-64/arrays.js`
155
+
156
+ **Port sources:** the array subset of arm64 `JitEmitter-array.cpp`:
157
+ newArray (:16), newArrayWithBuffer (:29), newFastArray (:58),
158
+ fastArrayLength (:75), fastArrayLoad (:108), fastArrayStore (:199),
159
+ fastArrayPush (:219), fastArrayAppend (:234). NOT in this milestone
160
+ (remove from stubs ONLY what you implement): getArgumentsLength,
161
+ iterator*, getPNameList/getNextPName, toPropertyKey,
162
+ getArgumentsPropByVal*, reifyArguments* — those are milestone 5.
163
+
164
+ **Test `arrays.js`:** array literals (small + large enough for the
165
+ buffer path), reads/writes in loops (fastArrayLoad/Store bounds checks:
166
+ in-bounds, out-of-bounds read producing undefined-or-throw per
167
+ semantics — match the interpreter), push in a loop (growth), length,
168
+ `fastArrayAppend` if reachable from source (check what emits it —
169
+ spread? — cover if reachable, else note), index types: int, double
170
+ (2.0 vs 2.5), negative, > 2^31 (exercises emit_double_is_uint32's
171
+ boundaries). Differential + status + type-asserts + -O0 pinned.
172
+
173
+ **Gates + prove-can-fail:** full suite + ASan; deliberate break: off-by
174
+ -one the fastArrayLoad bounds check (<= for <) — arrays.js's boundary
175
+ case must fail (ASan or wrong value); revert, re-verify. Commit:
176
+ "JIT: x86-64 arrays and fast arrays".
177
+
178
+ ---
179
+
180
+ ### Task 4: The HV32 and BOXED build matrix
181
+
182
+ **Files:**
183
+ - Modify: whatever the HV32/BOXED compiles reveal — expect fixes in the
184
+ `#ifdef HERMESVM_COMPRESSED_POINTERS` branches of
185
+ `JitEmitter-internal.h` and any emitter with heap-value-width
186
+ assumptions. Every fix carries a `// x86-64:` comment and must keep
187
+ the HV64 build byte-identical (verify by re-running the x86-64 lit
188
+ suite on the HV64 build after each fix).
189
+ - Modify: `doc/JIT.md` (document the two new build configurations in the
190
+ x86-64 dev-build recipe area)
191
+
192
+ **Steps:**
193
+ - [ ] Configure + build both trees:
194
+
195
+ ```bash
196
+ cmake -B /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit-hv32 -G Ninja \
197
+ -S /home/tmikov/work/hermes-x86-jit -DCMAKE_BUILD_TYPE=Debug \
198
+ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
199
+ -DHERMES_ENABLE_ADDRESS_SANITIZER=ON \
200
+ -DCMAKE_CXX_FLAGS="-O1" -DCMAKE_C_FLAGS="-O1" \
201
+ -DHERMESVM_ALLOW_JIT=2 -DHERMESVM_HEAP_HV_MODE=HEAP_HV_PREFER32
202
+ ```
203
+ (BOXED analogous with HEAP_HV_BOXED.) The HV32 branches of the cp
204
+ helpers compile for the FIRST time here — expect compile errors from
205
+ the blind transcription; fix minimally and faithfully vs arm64.
206
+ - [ ] Run the full x86-64 jit lit suite on BOTH new builds
207
+ (LIT_FILTER="jit/x86-64"): all tests must pass. Debug divergences
208
+ with -Xdump-jitcode=1 against the HV64 build's dump of the same test.
209
+ - [ ] Run the 497-file sweep on the HV32 build (and on BOXED if time
210
+ reasonable — say which); zero JIT-attributable diffs, using the
211
+ range-check method for the two stack-depth files (run the JIT side
212
+ 3 times, count must fall inside the interpreter's observed range).
213
+ - [ ] Full check-hermes on the HV32 build: zero unexpected failures.
214
+ - [ ] Prove-can-fail: in the HV32 build only, break one cp decode
215
+ (e.g. drop the base add), confirm the jit suite fails on HV32 while
216
+ the HV64 suite still passes (proving mode isolation); revert.
217
+ - [ ] Update doc/JIT.md's build-recipe area with both configure lines
218
+ and one sentence on what the matrix covers. Commit: "JIT: x86-64
219
+ HV32 and BOXED build matrix".
220
+
221
+ ---
222
+
223
+ ### Task 5: Docs and the arm64 cross-check
224
+
225
+ - [ ] doc/JIT.md status paragraph → milestone-4 state (objects, ICs,
226
+ globals, arrays, the matrix; updated still-declining list: iterators,
227
+ arguments, for-in, exceptions/try, switches, strings/AddS, typeof,
228
+ generator resume, eval/debugger).
229
+ - [ ] arm64 insurance: dump identical vs baseline + jit lit 46 passes
230
+ (report actual unsupported count), with pasted output in the report.
231
+ - [ ] Commit: "doc: x86-64 JIT milestone-4 status".
232
+
233
+ ---
234
+
235
+ ## Out of scope
236
+
237
+ Iterators/arguments/for-in/toPropertyKey (milestone 5 with exceptions
238
+ and switches), strings (AddS/addEmptyString), typeof/typeOfIs,
239
+ jmpBuiltinIs, goldens/CI (milestone 6). Any `test/jit` un-gating stays
240
+ out until coverage justifies it.