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,22 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the MIT license found in the
|
|
4
|
+
# LICENSE file in the root directory of this source tree.
|
|
5
|
+
|
|
6
|
+
# If we have a multi-configuration build system, we create a copy of llvm-lit in
|
|
7
|
+
# every directory.
|
|
8
|
+
if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
|
|
9
|
+
foreach (BUILD_MODE ${CMAKE_CONFIGURATION_TYPES})
|
|
10
|
+
string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} bi ${HERMES_LIT_PATH})
|
|
11
|
+
configure_file(
|
|
12
|
+
hermes-lit.in
|
|
13
|
+
${bi}
|
|
14
|
+
)
|
|
15
|
+
endforeach ()
|
|
16
|
+
else ()
|
|
17
|
+
set(BUILD_MODE "${CMAKE_BUILD_MODE}")
|
|
18
|
+
configure_file(
|
|
19
|
+
hermes-lit.in
|
|
20
|
+
${HERMES_LIT_PATH}
|
|
21
|
+
)
|
|
22
|
+
endif ()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
#
|
|
4
|
+
# This source code is licensed under the MIT license found in the
|
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
# Make sure we can find the lit package.
|
|
11
|
+
sys.path.insert(0, os.path.join("@LLVH_SOURCE_DIR@", 'utils', 'lit'))
|
|
12
|
+
|
|
13
|
+
if __name__=='__main__':
|
|
14
|
+
from lit.main import main
|
|
15
|
+
main({})
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# JIT dump tools
|
|
2
|
+
|
|
3
|
+
Tools for checking that a change to the arm64 JIT emitter did not change the
|
|
4
|
+
code it emits.
|
|
5
|
+
|
|
6
|
+
- `jit-dump.sh` — capture a canonicalized dump of all JIT-emitted code from
|
|
7
|
+
one `hermes` binary.
|
|
8
|
+
- `jit-diff.sh` — capture from two binaries and compare, reporting comment
|
|
9
|
+
changes separately from instruction changes.
|
|
10
|
+
|
|
11
|
+
## Why not just diff `-Xdump-jitcode` output?
|
|
12
|
+
|
|
13
|
+
Because two runs of an **unchanged** binary produce different dumps.
|
|
14
|
+
|
|
15
|
+
`Emitter::loadBits64InGp` asks `isCheapConst()` whether a 64-bit value has at
|
|
16
|
+
most two non-zero 16-bit halfwords. If it does, the value is materialized
|
|
17
|
+
inline with `mov`/`movk`; if not, it is spilled to the read-only data section
|
|
18
|
+
and loaded with `ldr`. JIT-emitted code bakes in runtime pointers, and ASLR
|
|
19
|
+
moves those every run. So the emitter genuinely selects *different
|
|
20
|
+
instructions* from one run to the next, and every subsequent RO-data offset
|
|
21
|
+
shifts along with them.
|
|
22
|
+
|
|
23
|
+
You can see this for yourself:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
utils/jit/jit-dump.sh --raw -o /tmp/a.txt build/bin/hermes
|
|
27
|
+
utils/jit/jit-dump.sh --raw -o /tmp/b.txt build/bin/hermes
|
|
28
|
+
diff -u /tmp/a.txt /tmp/b.txt | grep -cE '^[-+]'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
That reports roughly 3,500 changed lines out of about 90,000 — from the same
|
|
32
|
+
binary, twice, with no code change at all. Disabling ASLR (running under lldb)
|
|
33
|
+
cuts it to a few dozen but does not eliminate it, because the contiguous
|
|
34
|
+
heap's base address comes from a separate randomized mmap.
|
|
35
|
+
|
|
36
|
+
`jit-dump.sh` therefore collapses constant materialization to a `CONST` token,
|
|
37
|
+
drops the RO-data contents, and normalizes any remaining wide hex literal to
|
|
38
|
+
`ADDR`. What survives is compared verbatim: instructions, registers, branches,
|
|
39
|
+
labels, ordering, and the emitter's own comments. In practice that is about
|
|
40
|
+
92% of the dump, and the same command without `--raw` reports zero
|
|
41
|
+
differences.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
Both tools take **binaries**, not a build directory, so they work regardless
|
|
46
|
+
of how you built.
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
# Build the "before" binary and stash it somewhere.
|
|
50
|
+
cmake --build build --target hermes
|
|
51
|
+
cp build/bin/hermes /tmp/hermes-before
|
|
52
|
+
|
|
53
|
+
# Make your change, rebuild, and compare.
|
|
54
|
+
utils/jit/jit-diff.sh /tmp/hermes-before build/bin/hermes
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Typical output for a refactor that should be behaviour-preserving:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
jit-diff: dumps are identical
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
and for one that touches only `Emitter::comment()` strings:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
jit-diff: 20 changed lines (+10 / -10)
|
|
67
|
+
comment lines: 20
|
|
68
|
+
instruction lines: 0
|
|
69
|
+
RESULT: comments only, no instruction changed
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`--comments-ok` makes that second case exit 0, which is useful when a change
|
|
73
|
+
deliberately edits a comment string.
|
|
74
|
+
|
|
75
|
+
If the "before" binary is gone but you kept its capture, compare the dumps
|
|
76
|
+
directly:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
utils/jit/jit-diff.sh --dumps /tmp/before.txt /tmp/after.txt
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
To capture a single dump, for example to read one function by hand:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
utils/jit/jit-dump.sh --raw -c test/jit/binops.js build/bin/hermes | less
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`--raw` skips canonicalization. Use it for reading, never for comparing.
|
|
89
|
+
|
|
90
|
+
## Corpus
|
|
91
|
+
|
|
92
|
+
By default the corpus is every `test/jit/*.js` plus three typed tests that
|
|
93
|
+
exercise paths the JIT tests do not:
|
|
94
|
+
|
|
95
|
+
- `test/shermes/array-typed.js`
|
|
96
|
+
- `test/hermes/flow/array-for-of.js`
|
|
97
|
+
- `test/hermes/flow/nbody.js`
|
|
98
|
+
|
|
99
|
+
Each `test/jit` file is run typed if and only if its own lit `RUN:` line
|
|
100
|
+
passes `-typed`. That matters more than it sounds: running a typed test
|
|
101
|
+
untyped does not just lose coverage, it fails to compile, so the file
|
|
102
|
+
contributes a syntax error to the dump instead of any JIT code.
|
|
103
|
+
|
|
104
|
+
Override with `-c FILE` (untyped) and `-t FILE` (compiled with `-typed`),
|
|
105
|
+
both repeatable. Supplying either replaces the whole default corpus.
|
|
106
|
+
|
|
107
|
+
A corpus file that exits nonzero aborts the capture. Its diagnostics would
|
|
108
|
+
otherwise land in the dump, where they are indistinguishable from emitted
|
|
109
|
+
code and will happily compare equal between two runs.
|
|
110
|
+
|
|
111
|
+
## Limitations
|
|
112
|
+
|
|
113
|
+
**Canonicalized lines are not compared.** A change that alters *which*
|
|
114
|
+
instruction form is chosen for a constant is invisible to these tools, because
|
|
115
|
+
that is exactly what gets collapsed to `CONST`. If your change touches
|
|
116
|
+
`isCheapConst`, `loadBits64InGp`, `uint64Const`, or RO-data layout, these tools
|
|
117
|
+
cannot verify it.
|
|
118
|
+
|
|
119
|
+
**Coverage is only as good as the corpus.** An emitter path no test reaches
|
|
120
|
+
will not appear in the dump. Notably, every function in the default corpus has
|
|
121
|
+
well under 4 KB of bytecode, so paths gated on large bytecode offsets — such as
|
|
122
|
+
the two-instruction `add` in `Emitter::getBytecodeIP` — are never exercised.
|
|
123
|
+
Add a targeted file with `-c` when working on one of those.
|
|
124
|
+
|
|
125
|
+
**A clean diff is not a correctness proof.** It shows the emitted code did not
|
|
126
|
+
change, which is the right check for a refactor. It says nothing about whether
|
|
127
|
+
the code was correct to begin with, and nothing about the emitter's own runtime
|
|
128
|
+
behaviour. Run the lit suite too.
|
|
129
|
+
|
|
130
|
+
**The JIT must be enabled** in the binaries under test
|
|
131
|
+
(`-DHERMESVM_ALLOW_JIT=1`); the tools force it on per-run with `-Xjit=force
|
|
132
|
+
-Xjit-threshold=1`, but cannot enable a compile-time-disabled JIT. If a binary
|
|
133
|
+
was built without it, `jit-dump.sh` fails with a message saying so rather than
|
|
134
|
+
silently producing an empty dump.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
#
|
|
4
|
+
# This source code is licensed under the MIT license found in the
|
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
# Compare the JIT-emitted code of two hermes binaries over the same corpus.
|
|
8
|
+
#
|
|
9
|
+
# Takes binaries rather than driving a build, so it works the same whether the
|
|
10
|
+
# binaries came from CMake, buck2, or anywhere else.
|
|
11
|
+
#
|
|
12
|
+
# Reports whether any *instruction* changed, separately from comment lines,
|
|
13
|
+
# because that is usually the question being asked of a refactor.
|
|
14
|
+
|
|
15
|
+
set -u
|
|
16
|
+
set -o pipefail
|
|
17
|
+
|
|
18
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
19
|
+
|
|
20
|
+
usage() {
|
|
21
|
+
cat <<'EOF'
|
|
22
|
+
Usage: jit-diff.sh [options] <hermes-before> <hermes-after>
|
|
23
|
+
|
|
24
|
+
Captures a canonicalized JIT dump from each binary and compares them,
|
|
25
|
+
reporting comment-line changes separately from instruction changes.
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
-k DIR Keep the captures and the diff in DIR instead of a temp dir.
|
|
29
|
+
-c FILE Add FILE to the corpus, run untyped. Repeatable.
|
|
30
|
+
-t FILE Add FILE to the corpus, run with -typed. Repeatable.
|
|
31
|
+
-n N Show at most N lines of the diff (default 40, 0 for all).
|
|
32
|
+
--comments-ok Exit 0 when only comment lines differ.
|
|
33
|
+
--dumps The two arguments are existing jit-dump.sh outputs rather
|
|
34
|
+
than binaries. Useful when the "before" binary is gone but
|
|
35
|
+
its capture was kept.
|
|
36
|
+
-h, --help Show this help.
|
|
37
|
+
|
|
38
|
+
Exit status:
|
|
39
|
+
0 dumps identical (or only comments differ, with --comments-ok)
|
|
40
|
+
1 dumps differ
|
|
41
|
+
2 usage or capture error
|
|
42
|
+
|
|
43
|
+
Example:
|
|
44
|
+
git stash && cmake --build build --target hermes && cp build/bin/hermes /tmp/h-before
|
|
45
|
+
git stash pop && cmake --build build --target hermes
|
|
46
|
+
utils/jit/jit-diff.sh /tmp/h-before build/bin/hermes
|
|
47
|
+
EOF
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
KEEP=""
|
|
51
|
+
MAXLINES=40
|
|
52
|
+
COMMENTS_OK=0
|
|
53
|
+
DUMPS=0
|
|
54
|
+
CORPUS=()
|
|
55
|
+
|
|
56
|
+
# Abort rather than loop forever when an option is given without its operand.
|
|
57
|
+
need_arg() {
|
|
58
|
+
if [ "$2" -lt 2 ]; then
|
|
59
|
+
echo "jit-diff: option $1 requires an argument" >&2
|
|
60
|
+
exit 2
|
|
61
|
+
fi
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
while [ $# -gt 0 ]; do
|
|
65
|
+
case "$1" in
|
|
66
|
+
-k) need_arg -k $#; KEEP="$2"; shift 2 ;;
|
|
67
|
+
-c) need_arg -c $#; CORPUS+=(-c "$2"); shift 2 ;;
|
|
68
|
+
-t) need_arg -t $#; CORPUS+=(-t "$2"); shift 2 ;;
|
|
69
|
+
-n) need_arg -n $#; MAXLINES="$2"; shift 2 ;;
|
|
70
|
+
--comments-ok) COMMENTS_OK=1; shift ;;
|
|
71
|
+
--dumps) DUMPS=1; shift ;;
|
|
72
|
+
-h|--help) usage; exit 0 ;;
|
|
73
|
+
-*) echo "jit-diff: unknown option: $1" >&2; usage >&2; exit 2 ;;
|
|
74
|
+
*) break ;;
|
|
75
|
+
esac
|
|
76
|
+
done
|
|
77
|
+
|
|
78
|
+
if [ $# -ne 2 ]; then
|
|
79
|
+
if [ "$DUMPS" -eq 1 ]; then
|
|
80
|
+
echo "jit-diff: expected two dump files" >&2
|
|
81
|
+
else
|
|
82
|
+
echo "jit-diff: expected two hermes binaries" >&2
|
|
83
|
+
fi
|
|
84
|
+
usage >&2
|
|
85
|
+
exit 2
|
|
86
|
+
fi
|
|
87
|
+
BEFORE="$1"
|
|
88
|
+
AFTER="$2"
|
|
89
|
+
|
|
90
|
+
if [ -n "$KEEP" ]; then
|
|
91
|
+
mkdir -p "$KEEP" || exit 2
|
|
92
|
+
D="$KEEP"
|
|
93
|
+
else
|
|
94
|
+
D="$(mktemp -d)"
|
|
95
|
+
trap 'rm -rf "$D"' EXIT
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
if [ "$DUMPS" -eq 1 ]; then
|
|
99
|
+
for f in "$BEFORE" "$AFTER"; do
|
|
100
|
+
if [ ! -f "$f" ] || [ ! -r "$f" ]; then
|
|
101
|
+
echo "jit-diff: cannot read dump file: $f" >&2
|
|
102
|
+
exit 2
|
|
103
|
+
fi
|
|
104
|
+
done
|
|
105
|
+
cp "$BEFORE" "$D/before.txt" || exit 2
|
|
106
|
+
cp "$AFTER" "$D/after.txt" || exit 2
|
|
107
|
+
else
|
|
108
|
+
echo "jit-diff: capturing 'before' from $BEFORE" >&2
|
|
109
|
+
"$SCRIPT_DIR/jit-dump.sh" ${CORPUS[@]+"${CORPUS[@]}"} -o "$D/before.txt" "$BEFORE" || exit 2
|
|
110
|
+
echo "jit-diff: capturing 'after' from $AFTER" >&2
|
|
111
|
+
"$SCRIPT_DIR/jit-dump.sh" ${CORPUS[@]+"${CORPUS[@]}"} -o "$D/after.txt" "$AFTER" || exit 2
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
# diff exits 0 for same, 1 for differing, >1 for trouble. Treating trouble as
|
|
115
|
+
# "differing" would report a misleading result for an unreadable capture.
|
|
116
|
+
diff -u "$D/before.txt" "$D/after.txt" > "$D/jit.diff"
|
|
117
|
+
DSTATUS=$?
|
|
118
|
+
if [ "$DSTATUS" -eq 0 ]; then
|
|
119
|
+
echo "jit-diff: dumps are identical"
|
|
120
|
+
exit 0
|
|
121
|
+
elif [ "$DSTATUS" -gt 1 ]; then
|
|
122
|
+
echo "jit-diff: diff failed with status $DSTATUS" >&2
|
|
123
|
+
exit 2
|
|
124
|
+
fi
|
|
125
|
+
|
|
126
|
+
# Classify each changed line. A line that begins with '//' after the diff
|
|
127
|
+
# marker is a comment emitted by Emitter::comment(); anything else is a label
|
|
128
|
+
# or an instruction.
|
|
129
|
+
changed=$(grep -cE '^[-+]' "$D/jit.diff")
|
|
130
|
+
headers=$(grep -cE '^(\+\+\+|---)' "$D/jit.diff")
|
|
131
|
+
changed=$((changed - headers))
|
|
132
|
+
added=$(grep -cE '^\+' "$D/jit.diff")
|
|
133
|
+
removed=$(grep -cE '^-' "$D/jit.diff")
|
|
134
|
+
added=$((added - 1))
|
|
135
|
+
removed=$((removed - 1))
|
|
136
|
+
comments=$(grep -E '^[-+]' "$D/jit.diff" | grep -vE '^(\+\+\+|---)' \
|
|
137
|
+
| sed -E 's/^[-+][[:space:]]*//' | grep -cE '^//' || true)
|
|
138
|
+
insns=$((changed - comments))
|
|
139
|
+
|
|
140
|
+
echo "jit-diff: $changed changed lines (+$added / -$removed)"
|
|
141
|
+
echo " comment lines: $comments"
|
|
142
|
+
echo " instruction lines: $insns"
|
|
143
|
+
if [ "$insns" -eq 0 ]; then
|
|
144
|
+
echo "RESULT: comments only, no instruction changed"
|
|
145
|
+
else
|
|
146
|
+
echo "RESULT: INSTRUCTIONS CHANGED"
|
|
147
|
+
fi
|
|
148
|
+
[ -n "$KEEP" ] && echo "captures and diff kept in $D"
|
|
149
|
+
|
|
150
|
+
if [ "$MAXLINES" -ne 0 ]; then
|
|
151
|
+
echo "--- first $MAXLINES diff lines ---"
|
|
152
|
+
head -n "$MAXLINES" "$D/jit.diff"
|
|
153
|
+
else
|
|
154
|
+
cat "$D/jit.diff"
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
if [ "$insns" -eq 0 ] && [ "$COMMENTS_OK" -eq 1 ]; then
|
|
158
|
+
exit 0
|
|
159
|
+
fi
|
|
160
|
+
exit 1
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
#
|
|
4
|
+
# This source code is licensed under the MIT license found in the
|
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
# Capture a canonicalized dump of all JIT-emitted code over a corpus of JS
|
|
8
|
+
# files, suitable for byte-for-byte comparison between two builds.
|
|
9
|
+
#
|
|
10
|
+
# The canonicalization is not optional for comparison purposes; see
|
|
11
|
+
# utils/jit/README.md for why two runs of an *unchanged* binary produce
|
|
12
|
+
# different raw dumps.
|
|
13
|
+
|
|
14
|
+
set -u
|
|
15
|
+
set -o pipefail
|
|
16
|
+
|
|
17
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
18
|
+
ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
19
|
+
|
|
20
|
+
usage() {
|
|
21
|
+
cat <<'EOF'
|
|
22
|
+
Usage: jit-dump.sh [options] <hermes-binary>
|
|
23
|
+
|
|
24
|
+
Runs <hermes-binary> over a corpus of JS files with the JIT forced on,
|
|
25
|
+
dumping every emitted function, and canonicalizes the output so that two
|
|
26
|
+
captures can be compared byte for byte.
|
|
27
|
+
|
|
28
|
+
Options:
|
|
29
|
+
-o FILE Write the dump to FILE (default: stdout).
|
|
30
|
+
-c FILE Add FILE to the corpus, run untyped. Repeatable.
|
|
31
|
+
-t FILE Add FILE to the corpus, run with -typed. Repeatable.
|
|
32
|
+
If neither -c nor -t is given, the default corpus is used:
|
|
33
|
+
test/jit/*.js plus a few typed tests.
|
|
34
|
+
--raw Skip canonicalization. Useful for reading a single dump,
|
|
35
|
+
useless for comparing two.
|
|
36
|
+
-q Do not print the summary line to stderr.
|
|
37
|
+
-h, --help Show this help.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
# Capture from a CMake build.
|
|
41
|
+
utils/jit/jit-dump.sh -o /tmp/before.txt ~/build/bin/hermes
|
|
42
|
+
|
|
43
|
+
# Compare two builds (see also jit-diff.sh).
|
|
44
|
+
utils/jit/jit-dump.sh -o /tmp/after.txt ./bin/hermes
|
|
45
|
+
diff -u /tmp/before.txt /tmp/after.txt
|
|
46
|
+
|
|
47
|
+
# Just one file, raw, to read by hand.
|
|
48
|
+
utils/jit/jit-dump.sh --raw -c test/jit/binops.js ./bin/hermes
|
|
49
|
+
EOF
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
OUT=""
|
|
53
|
+
RAW=0
|
|
54
|
+
QUIET=0
|
|
55
|
+
UNTYPED=()
|
|
56
|
+
TYPED=()
|
|
57
|
+
|
|
58
|
+
# Abort rather than loop forever when an option is given without its operand.
|
|
59
|
+
need_arg() {
|
|
60
|
+
if [ "$2" -lt 2 ]; then
|
|
61
|
+
echo "jit-dump: option $1 requires an argument" >&2
|
|
62
|
+
exit 2
|
|
63
|
+
fi
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
while [ $# -gt 0 ]; do
|
|
67
|
+
case "$1" in
|
|
68
|
+
-o) need_arg -o $#; OUT="$2"; shift 2 ;;
|
|
69
|
+
-c) need_arg -c $#; UNTYPED+=("$2"); shift 2 ;;
|
|
70
|
+
-t) need_arg -t $#; TYPED+=("$2"); shift 2 ;;
|
|
71
|
+
--raw) RAW=1; shift ;;
|
|
72
|
+
-q) QUIET=1; shift ;;
|
|
73
|
+
-h|--help) usage; exit 0 ;;
|
|
74
|
+
-*) echo "jit-dump: unknown option: $1" >&2; usage >&2; exit 2 ;;
|
|
75
|
+
*) break ;;
|
|
76
|
+
esac
|
|
77
|
+
done
|
|
78
|
+
|
|
79
|
+
if [ $# -ne 1 ]; then
|
|
80
|
+
echo "jit-dump: expected exactly one hermes binary" >&2
|
|
81
|
+
usage >&2
|
|
82
|
+
exit 2
|
|
83
|
+
fi
|
|
84
|
+
HERMES="$1"
|
|
85
|
+
|
|
86
|
+
if [ ! -x "$HERMES" ]; then
|
|
87
|
+
echo "jit-dump: not an executable: $HERMES" >&2
|
|
88
|
+
exit 2
|
|
89
|
+
fi
|
|
90
|
+
|
|
91
|
+
# Default corpus: every JIT test, plus a few typed tests that exercise paths
|
|
92
|
+
# the JIT tests do not.
|
|
93
|
+
#
|
|
94
|
+
# A JIT test is run typed iff its own lit RUN line passes -typed. Running a
|
|
95
|
+
# typed test untyped does not merely reduce coverage: it fails to compile, and
|
|
96
|
+
# the corpus then contributes a syntax error instead of any JIT code.
|
|
97
|
+
if [ ${#UNTYPED[@]} -eq 0 ] && [ ${#TYPED[@]} -eq 0 ]; then
|
|
98
|
+
while IFS= read -r f; do
|
|
99
|
+
if grep -qE '^// *RUN:.*[[:space:]]-typed([[:space:]]|$)' "$f"; then
|
|
100
|
+
TYPED+=("$f")
|
|
101
|
+
else
|
|
102
|
+
UNTYPED+=("$f")
|
|
103
|
+
fi
|
|
104
|
+
done < <(ls "$ROOT"/test/jit/*.js 2>/dev/null)
|
|
105
|
+
TYPED+=("$ROOT/test/shermes/array-typed.js")
|
|
106
|
+
TYPED+=("$ROOT/test/hermes/flow/array-for-of.js")
|
|
107
|
+
TYPED+=("$ROOT/test/hermes/flow/nbody.js")
|
|
108
|
+
if [ ${#UNTYPED[@]} -eq 0 ] && [ ${#TYPED[@]} -eq 3 ]; then
|
|
109
|
+
echo "jit-dump: default corpus is empty; no $ROOT/test/jit/*.js found" >&2
|
|
110
|
+
exit 2
|
|
111
|
+
fi
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
for f in ${UNTYPED[@]+"${UNTYPED[@]}"} ${TYPED[@]+"${TYPED[@]}"}; do
|
|
115
|
+
[ -f "$f" ] || { echo "jit-dump: no such corpus file: $f" >&2; exit 2; }
|
|
116
|
+
done
|
|
117
|
+
|
|
118
|
+
TMP="$(mktemp)"
|
|
119
|
+
trap 'rm -f "$TMP"' EXIT
|
|
120
|
+
|
|
121
|
+
# Canonicalize:
|
|
122
|
+
# - Collapse constant materialization to a CONST token. isCheapConst() picks
|
|
123
|
+
# between mov/movk and an RO-data load based on the *value*, and JIT code
|
|
124
|
+
# bakes in runtime pointers that ASLR moves every run.
|
|
125
|
+
# - Drop the RO_DATA contents, whose layout shifts with the above.
|
|
126
|
+
# - Normalize any remaining wide hex literal to ADDR.
|
|
127
|
+
canonicalize() {
|
|
128
|
+
if [ "$RAW" -eq 1 ]; then
|
|
129
|
+
cat
|
|
130
|
+
return
|
|
131
|
+
fi
|
|
132
|
+
sed -E \
|
|
133
|
+
-e 's/^( *)mov (x[0-9]+), 0x[0-9A-Fa-f]+$/\1CONST \2/' \
|
|
134
|
+
-e 's/^( *)ldr (x[0-9]+), \[RO_DATA(, [0-9]+)?\]$/\1CONST \2/' \
|
|
135
|
+
-e 's/^( *)ldr (d[0-9]+), \[RO_DATA(, [0-9]+)?\]$/\1CONST \2/' \
|
|
136
|
+
-e '/JIT total memory usage/d' \
|
|
137
|
+
-e '/^\.xword /d' \
|
|
138
|
+
-e '/^\/\/ Bytecode start$/d' \
|
|
139
|
+
-e '/^\/\/ RuntimeModule$/d' \
|
|
140
|
+
-e 's/0x[0-9A-Fa-f]{8,}/ADDR/g' \
|
|
141
|
+
| awk '/^RO_DATA:$/ {inro=1; next} inro && /^\/\// {next} inro {inro=0} {print}'
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
run_one() {
|
|
145
|
+
local label="$1" file="$2"; shift 2
|
|
146
|
+
local before after
|
|
147
|
+
# Snapshot the whole pipeline status: hermes failing and canonicalization
|
|
148
|
+
# failing both yield a dump that is wrong but looks plausible.
|
|
149
|
+
local -a pstatus
|
|
150
|
+
echo "===== $label =====" >> "$TMP"
|
|
151
|
+
before=$(wc -l < "$TMP")
|
|
152
|
+
"$HERMES" "$@" -Xjit=force -Xjit-threshold=1 -Xdump-jitcode=3 "$file" 2>&1 \
|
|
153
|
+
| canonicalize >> "$TMP"
|
|
154
|
+
pstatus=("${PIPESTATUS[@]}")
|
|
155
|
+
after=$(wc -l < "$TMP")
|
|
156
|
+
# A failing run still writes its diagnostics into the dump, where they are
|
|
157
|
+
# indistinguishable from emitted code. Never let that pass silently.
|
|
158
|
+
if [ "${pstatus[0]}" -ne 0 ]; then
|
|
159
|
+
echo "jit-dump: '$label' exited with status ${pstatus[0]}" >&2
|
|
160
|
+
echo " Its diagnostics, not JIT output, would have gone into the dump." >&2
|
|
161
|
+
echo " Last lines captured:" >&2
|
|
162
|
+
tail -n 3 "$TMP" | sed 's/^/ /' >&2
|
|
163
|
+
exit 1
|
|
164
|
+
fi
|
|
165
|
+
# Canonicalization is sed|awk writing to $TMP, so this catches a write
|
|
166
|
+
# failure (full disk, unwritable temp) that would silently truncate.
|
|
167
|
+
if [ "${pstatus[1]}" -ne 0 ]; then
|
|
168
|
+
echo "jit-dump: canonicalizing '$label' failed with status ${pstatus[1]}" >&2
|
|
169
|
+
echo " The dump is likely truncated; refusing to continue." >&2
|
|
170
|
+
exit 1
|
|
171
|
+
fi
|
|
172
|
+
if [ "$after" -le "$((before + 2))" ]; then
|
|
173
|
+
echo "jit-dump: '$label' emitted almost nothing." >&2
|
|
174
|
+
echo " Is $HERMES built with the JIT enabled (HERMESVM_ALLOW_JIT)?" >&2
|
|
175
|
+
exit 1
|
|
176
|
+
fi
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
for f in ${UNTYPED[@]+"${UNTYPED[@]}"}; do run_one "$(basename "$f")" "$f"; done
|
|
180
|
+
for f in ${TYPED[@]+"${TYPED[@]}"}; do run_one "typed $(basename "$f")" "$f" -typed; done
|
|
181
|
+
|
|
182
|
+
if [ "$QUIET" -eq 0 ]; then
|
|
183
|
+
total=$(wc -l < "$TMP" | tr -d ' ')
|
|
184
|
+
const=$(grep -c 'CONST ' "$TMP" || true)
|
|
185
|
+
pct=$(( total > 0 ? (total - const) * 100 / total : 0 ))
|
|
186
|
+
echo "jit-dump: $total lines, $const canonicalized (${pct}% compared verbatim)" >&2
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
if [ -n "$OUT" ]; then
|
|
190
|
+
cp "$TMP" "$OUT"
|
|
191
|
+
else
|
|
192
|
+
cat "$TMP"
|
|
193
|
+
fi
|