mini_racer_rs 1.1.1 → 1.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/COMPATIBILITY.md +20 -2
- data/Cargo.lock +5 -5
- data/Cargo.toml +1 -1
- data/README.md +16 -14
- data/THIRD_PARTY_NOTICES.md +200 -0
- data/crates/mini_racer_engine/src/context.rs +45 -4
- data/crates/mini_racer_engine/src/control.rs +48 -3
- data/crates/mini_racer_engine/src/counters.rs +208 -0
- data/crates/mini_racer_engine/src/lib.rs +2 -0
- data/crates/mini_racer_engine/src/runner.rs +88 -2
- data/crates/mini_racer_engine/src/sys.rs +47 -2
- data/ext/mini_racer_rs/extconf.rb +7 -2
- data/ext/mini_racer_rs/src/context.rs +5 -1
- data/ext/mini_racer_rs/src/counters.rs +40 -0
- data/ext/mini_racer_rs/src/lib.rs +2 -0
- data/ext/mini_racer_rs/v8-archives.sha256 +4 -0
- data/lib/mini_racer_rs/version.rb +1 -1
- data/licenses/v8/SOURCES.tsv +1 -0
- data/licenses/v8/components.tsv +6 -2
- data/licenses/v8/musl/COPYRIGHT +193 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89724c314c6b6e76bcbf4766ee4bca491da165fb3a171a4810b31f67ef5c482b
|
|
4
|
+
data.tar.gz: 79363136b12b9284b9b7d7df8799d8228107d89fd3a60e708a153aef0cfd7efc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8ef0724b17c87ef891ff91e25673a8a98aba87b8e1f8ecad7cb9824b1e4e7ea39d60d5e5b30d6b435cc56eb06b3bd2a553f47b4f9182febf9cfe7b582a388a7
|
|
7
|
+
data.tar.gz: ef0ff9c5648543b82440b5fa12e4a90b3842df6bd3736a1da404ebf1aa1c0ce3e0a9d9a335447db14245e71467406a4fff10c4b0a8372602fcf28a4d79c3ad88
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.0](https://github.com/andymai/mini_racer_rs/compare/v1.2.0...v1.3.0) (2026-10-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add MiniRacerRs.counters for per-context activity counts ([#126](https://github.com/andymai/mini_racer_rs/issues/126)) ([d482a3f](https://github.com/andymai/mini_racer_rs/commit/d482a3fb9fb4ac5ba3c077e6d2deffe25402ef3d))
|
|
9
|
+
|
|
10
|
+
## [1.2.0](https://github.com/andymai/mini_racer_rs/compare/v1.1.1...v1.2.0) (2026-10-22)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **platforms:** native gems and CI for musl Linux ([#117](https://github.com/andymai/mini_racer_rs/issues/117)) ([5b565f2](https://github.com/andymai/mini_racer_rs/commit/5b565f2e7e5f2ef5f502c2ddf7d38fcbdcd68e35))
|
|
16
|
+
|
|
3
17
|
## [1.1.1](https://github.com/andymai/mini_racer_rs/compare/v1.1.0...v1.1.1) (2026-10-21)
|
|
4
18
|
|
|
5
19
|
|
data/COMPATIBILITY.md
CHANGED
|
@@ -82,6 +82,24 @@
|
|
|
82
82
|
| `smethod:MiniRacer::Platform.set_flags!` | done | done |
|
|
83
83
|
| `smethod:MiniRacer::Snapshot.load` | done | n/a |
|
|
84
84
|
|
|
85
|
+
## Additions
|
|
86
|
+
|
|
87
|
+
What mini_racer_rs adds under `MiniRacerRs`. An internal id is not for callers.
|
|
88
|
+
|
|
89
|
+
| Id | CRuby | TruffleRuby |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `class:MiniRacerRs::Pins < Object` | internal | n/a |
|
|
92
|
+
| `class:MiniRacerRs::Spill < Object` | internal | n/a |
|
|
93
|
+
| `const:MiniRacerRs::NATIVE_VERSION` | done | n/a |
|
|
94
|
+
| `const:MiniRacerRs::V8_VERSION` | done | n/a |
|
|
95
|
+
| `const:MiniRacerRs::VERSION` | done | done |
|
|
96
|
+
| `imethod:MiniRacerRs::ForkHook#_fork` | internal | n/a |
|
|
97
|
+
| `imethod:MiniRacerRs::ForkHook#daemon` | internal | n/a |
|
|
98
|
+
| `module:MiniRacerRs` | done | done |
|
|
99
|
+
| `module:MiniRacerRs::ForkHook` | internal | n/a |
|
|
100
|
+
| `smethod:MiniRacerRs.counters` | done | n/a |
|
|
101
|
+
| `smethod:MiniRacerRs.register_source_map` | done | n/a |
|
|
102
|
+
|
|
85
103
|
## Deviations
|
|
86
104
|
|
|
87
105
|
### `behavior:bigint-objects@ruby`
|
|
@@ -176,9 +194,9 @@ Approved 2026-10-16.
|
|
|
176
194
|
|
|
177
195
|
### `behavior:platforms@ruby`
|
|
178
196
|
|
|
179
|
-
mini_racer_rs
|
|
197
|
+
mini_racer_rs ships native gems for the platforms libv8-node publishes gems for, which mini_racer 0.22.1 uses: glibc and musl Linux on x86_64 and aarch64, and macOS on x86_64 and arm64. Neither supports Windows. On any other platform, mini_racer_rs's source gem stops installation with a message naming the supported platforms, while mini_racer can install libv8-node's source gem.
|
|
180
198
|
|
|
181
|
-
Approved 2026-10-
|
|
199
|
+
Approved 2026-10-22.
|
|
182
200
|
|
|
183
201
|
### `behavior:shared-source-heap-stats@ruby`
|
|
184
202
|
|
data/Cargo.lock
CHANGED
|
@@ -593,7 +593,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
|
593
593
|
|
|
594
594
|
[[package]]
|
|
595
595
|
name = "mini_racer_engine"
|
|
596
|
-
version = "1.
|
|
596
|
+
version = "1.3.0"
|
|
597
597
|
dependencies = [
|
|
598
598
|
"deno_core_icudata",
|
|
599
599
|
"libc",
|
|
@@ -606,7 +606,7 @@ dependencies = [
|
|
|
606
606
|
|
|
607
607
|
[[package]]
|
|
608
608
|
name = "mini_racer_rs"
|
|
609
|
-
version = "1.
|
|
609
|
+
version = "1.3.0"
|
|
610
610
|
dependencies = [
|
|
611
611
|
"magnus",
|
|
612
612
|
"mini_racer_engine",
|
|
@@ -617,7 +617,7 @@ dependencies = [
|
|
|
617
617
|
|
|
618
618
|
[[package]]
|
|
619
619
|
name = "mini_racer_sourcemap"
|
|
620
|
-
version = "1.
|
|
620
|
+
version = "1.3.0"
|
|
621
621
|
dependencies = [
|
|
622
622
|
"memchr",
|
|
623
623
|
"serde",
|
|
@@ -627,7 +627,7 @@ dependencies = [
|
|
|
627
627
|
|
|
628
628
|
[[package]]
|
|
629
629
|
name = "mini_racer_sync"
|
|
630
|
-
version = "1.
|
|
630
|
+
version = "1.3.0"
|
|
631
631
|
dependencies = [
|
|
632
632
|
"loom",
|
|
633
633
|
"thiserror",
|
|
@@ -635,7 +635,7 @@ dependencies = [
|
|
|
635
635
|
|
|
636
636
|
[[package]]
|
|
637
637
|
name = "mini_racer_wire"
|
|
638
|
-
version = "1.
|
|
638
|
+
version = "1.3.0"
|
|
639
639
|
dependencies = [
|
|
640
640
|
"criterion",
|
|
641
641
|
"proptest",
|
data/Cargo.toml
CHANGED
|
@@ -15,7 +15,7 @@ license = "MIT"
|
|
|
15
15
|
publish = false
|
|
16
16
|
repository = "https://github.com/andymai/mini_racer_rs"
|
|
17
17
|
rust-version = "1.91"
|
|
18
|
-
version = "1.
|
|
18
|
+
version = "1.3.0"
|
|
19
19
|
|
|
20
20
|
[workspace.dependencies]
|
|
21
21
|
criterion = {version = "0.8", default-features = false, features = ["cargo_bench_support"]}
|
data/README.md
CHANGED
|
@@ -27,7 +27,7 @@ mini_racer_rs implements the `MiniRacer` API from mini_racer 0.22.1. It defines
|
|
|
27
27
|
- **Memory:** A context holding the MUI bundle uses 44 MB vs 110 MB.
|
|
28
28
|
- **Forks:** After loading and rendering React: 20 of 20 clean mini_racer_rs exits vs 20 of 20 mini_racer aborts.
|
|
29
29
|
- **V8:** V8 15.2.124.1 vs V8 13.6.233.17 in mini_racer 0.22.1.
|
|
30
|
-
- **No compiler:** Native gems cover glibc Linux and macOS, both architectures, with Ruby 3.3, 3.4 and 4.0 extensions.
|
|
30
|
+
- **No compiler:** Native gems cover glibc and musl Linux, including Alpine, and macOS, on both architectures, with Ruby 3.3, 3.4 and 4.0 extensions.
|
|
31
31
|
- **Fiber scheduler:** Three 100 ms loops in separate contexts and fibers finish in 100 ms vs 300 ms.
|
|
32
32
|
- **Upstream suites:** mini_racer passes 171 of 174 with 3 skipped by itself; ExecJS passes 197 of 198 with 1 skipped.
|
|
33
33
|
- **Difficult values:** A `Map` with a function key returns an error Hash instead of aborting with SIGABRT.
|
|
@@ -46,7 +46,7 @@ Switch packages with one Gemfile line:
|
|
|
46
46
|
|
|
47
47
|
Run `bundle install`. Bundler is required because RubyGems may activate the original `mini_racer` first. Loading both gems raises a `LoadError` naming the conflict. Reverse the Gemfile change to switch back.
|
|
48
48
|
|
|
49
|
-
On x86_64-linux-gnu, aarch64-linux-gnu, arm64-darwin, and x86_64-darwin, `bundle install` installs a native gem without compiling. Elsewhere, the source gem requires Rust 1.91 or newer and libclang to build the extension. For a checkout, follow [CONTRIBUTING.md](CONTRIBUTING.md) and run `bin/setup`.
|
|
49
|
+
On x86_64-linux-gnu, aarch64-linux-gnu, x86_64-linux-musl, aarch64-linux-musl, arm64-darwin, and x86_64-darwin, `bundle install` installs a native gem without compiling. Elsewhere, the source gem requires Rust 1.91 or newer and libclang to build the extension. For a checkout, follow [CONTRIBUTING.md](CONTRIBUTING.md) and run `bin/setup`.
|
|
50
50
|
|
|
51
51
|
## Quick start
|
|
52
52
|
|
|
@@ -101,7 +101,8 @@ ExecJS.eval("[1, 2].map(x => x * 2)") # => [2, 4]
|
|
|
101
101
|
| `Context#pump_message_loop`, `#perform_microtask_checkpoint` | Runs pending V8 tasks and microtasks. |
|
|
102
102
|
| `Snapshot.new`, `#warmup!`, `#dump`, `Snapshot.load` | Creates, warms, serializes, and loads startup snapshots. |
|
|
103
103
|
| `Platform.set_flags!(*flags)` | Sets V8 flags before the first context. |
|
|
104
|
-
| `MiniRacerRs.register_source_map(bundle, map)` | Registers a source map for a bundle, so `MiniRacer::RuntimeError` backtraces show its original files and positions. |
|
|
104
|
+
| `MiniRacerRs.register_source_map(bundle, map)` | Registers a source map for a bundle, so `MiniRacer::RuntimeError` backtraces show its original files and positions. CRuby only. |
|
|
105
|
+
| `MiniRacerRs.counters(context)` | Returns per-context activity counters without dispatching or taking the context lock, including while a script runs and after disposal. CRuby only. |
|
|
105
106
|
|
|
106
107
|
`Context.new` accepts these options:
|
|
107
108
|
|
|
@@ -112,7 +113,7 @@ ExecJS.eval("[1, 2].map(x => x * 2)") # => [2, 4]
|
|
|
112
113
|
| `ensure_gc_after_idle:` | Idle milliseconds before one full garbage collection. `0` disables it. |
|
|
113
114
|
| `snapshot:` | A `MiniRacer::Snapshot` used to initialize the context. |
|
|
114
115
|
|
|
115
|
-
|
|
116
|
+
`MiniRacer::EvalError` is the parent of `MiniRacer::ParseError`, `MiniRacer::ScriptTerminatedError`, `MiniRacer::V8OutOfMemoryError`, `MiniRacer::RuntimeError`, and `MiniRacer::ScriptError`. On CRuby, `MiniRacer::InternalError` also descends from `MiniRacer::EvalError` and reports a failure inside the gem rather than in JavaScript. `MiniRacer::ContextDisposedError`, `MiniRacer::SnapshotError`, and `MiniRacer::PlatformAlreadyInitialized` descend directly from `MiniRacer::Error`. Everything descends from `MiniRacer::Error`. `MiniRacer::RuntimeError` includes JavaScript frames in its backtrace.
|
|
116
117
|
|
|
117
118
|
**Source maps.** Bundles must be UTF-8 Strings of at least 1,024 bytes. Maps must be JSON Strings in source map v3 format. When a context evaluates UTF-8 source containing a registered bundle, mini_racer_rs rewrites `MiniRacer::RuntimeError` backtraces. V8 positions inside the bundle become mapped original file, line, and column positions. V8 function names remain.
|
|
118
119
|
|
|
@@ -120,6 +121,8 @@ V8 positions remain for async frames and frames after the tenth. They also remai
|
|
|
120
121
|
|
|
121
122
|
Detailed stack capture makes creating and throwing errors more expensive in affected contexts. Measured React and MUI server renders were unchanged. Registration is process wide and holds at most eight bundles. Maps cannot be removed. Registering a bundle again replaces its map. Trust bundles and maps like application code because source names appear in Ruby backtraces.
|
|
122
123
|
|
|
124
|
+
**Counters.** `MiniRacerRs.counters(context)` returns a Hash of symbol-keyed counts for activity since context creation. It reads without a dispatch or the context lock, so another thread can inspect it while a script runs. After `dispose`, it returns the last counts. A forked child that takes a context over continues from the parent's counts. Values are read individually, so an in-flight request can appear in `dispatches` before its result bytes. Keys are `dispatches` (runner requests, including nested callback requests), `callbacks` (Ruby callables run for JavaScript), `bytes_to_js` (sources, requests, callback returns and errors), `bytes_from_js` (results and callback arguments), `js_ns` (runner time excluding callback, await task and fork waits), `gc_count` and `gc_ns` (V8 collections and time), and `terminated` (counts by `stop`, `timeout`, `interrupt`, `max_memory` and `heap_exhausted`). A non-context argument raises `TypeError`. CRuby only. In release builds, timing `js_ns` added about 30 ns to a roughly 0.72 µs call round trip. Counting alone measured within noise.
|
|
125
|
+
|
|
123
126
|
## Switching from mini_racer
|
|
124
127
|
|
|
125
128
|
### What changes
|
|
@@ -148,9 +151,7 @@ See [COMPATIBILITY.md](COMPATIBILITY.md) for every difference.
|
|
|
148
151
|
|
|
149
152
|
### Stay on mini_racer if
|
|
150
153
|
|
|
151
|
-
-
|
|
152
|
-
|
|
153
|
-
- Download size matters more than compile time. The largest native gem is 65.6 MB because it contains three Ruby extensions. mini_racer downloads 47.1 MB on x86_64 Linux, then compiles.
|
|
154
|
+
- Download size matters more than compile time. The largest native gem is 66.2 MB because it contains three Ruby extensions. mini_racer downloads 47.1 MB on x86_64 Linux, then compiles.
|
|
154
155
|
|
|
155
156
|
### Gems that depend on mini_racer
|
|
156
157
|
|
|
@@ -161,11 +162,11 @@ gem "mini_racer_rs"
|
|
|
161
162
|
gem "mini_racer", github: "andymai/mini_racer_rs", tag: "vX.Y.Z", glob: "shim/*.gemspec"
|
|
162
163
|
```
|
|
163
164
|
|
|
164
|
-
The repository tests `path:` shim
|
|
165
|
+
The repository tests the `path:` form of the shim with rtlcss in `test/consumers/transitive/`. A dependency excluding `mini_racer` 0.22.1 cannot use the shim.
|
|
165
166
|
|
|
166
167
|
### Forking servers such as Puma
|
|
167
168
|
|
|
168
|
-
Before forking, evaluate each bundle of 1
|
|
169
|
+
Before forking, evaluate each bundle of 1 MiB or more twice in the master, then dispose those contexts. Use the renderer's exact source text and file name. The second evaluation builds the process-wide V8 code cache. Matching evaluations compile from it, and forked children inherit it. For Babel's 2.3 MB bundle at commit `5e13c1c`, a forked child's first load took 60.8 ms without a parent load. It took 65.5 ms after one load and 25.0 ms after two. These are medians across 5 trials. Prime a `react-rails` app by building its server renderer twice. Children do not use parent contexts. Only the cache carries over.
|
|
169
170
|
|
|
170
171
|
For Ruby's `fork`, `IO.popen("-")`, or `Process.daemon`, mini_racer_rs waits for context runners, pauses its worker pool and waits for running tasks. An async `WebAssembly.compile` in a new default-mode child completes on the child's own pool. On Ubuntu 24.04 with glibc 2.39, 20 of 20 mini_racer children aborted with signal 6 after React rendering; all mini_racer_rs children exited cleanly. On Fedora, mini_racer hung within 50 `test/stress/fork_busy.rb` forks; mini_racer_rs completed 300 per run on Fedora and Ubuntu.
|
|
171
172
|
|
|
@@ -187,7 +188,7 @@ With `mini_racer` 0.22.1, each worker compiles the bundle from source on its fir
|
|
|
187
188
|
|
|
188
189
|
Results are medians of 5 runs. Every workload produced identical output in both gems. The eight library workloads use the release build of commit `220bfe7`. The 44 MB production bundle load uses commit `2513a48`. Benchmarks ran on Ruby 3.4.2 and Linux with an AMD Ryzen 9 7950X3D. The governor was `performance`. Both gems were pinned to CPUs 0 through 7.
|
|
189
190
|
|
|
190
|
-
The per-call and memory figures below were measured on the same machine. Startup plus Babel, Babel context and MUI context figures come from commit `220bfe7`. One watchdog thread serves the whole process, making a call with `timeout:` fast. Scripts of 1
|
|
191
|
+
The per-call and memory figures below were measured on the same machine. Startup plus Babel, Babel context and MUI context figures come from commit `220bfe7`. One watchdog thread serves the whole process, making a call with `timeout:` fast. Scripts of 1 MiB or more use a process-wide V8 code cache. Contexts loading the same large script share one source copy.
|
|
191
192
|
|
|
192
193
|
| Measure | mini_racer 0.22.1 | mini_racer_rs |
|
|
193
194
|
|---|---:|---:|
|
|
@@ -239,12 +240,13 @@ mini_racer_rs uses the `v8` crate, rusty_v8 152.2.0, with magnus and rb-sys Ruby
|
|
|
239
240
|
|
|
240
241
|
A waiting Ruby thread spins with the GVL held, then without it. It then parks with the GVL released. After enough consecutive answers arrive beyond the spin budget, that context skips spinning and parks at once until an answer arrives within the budget. Under a fiber scheduler, only the waiting fiber parks. Values use V8's serialization format and decode directly into Ruby objects. There is no intermediate tree. Repeated objects keep their identity.
|
|
241
242
|
|
|
242
|
-
One watchdog thread per process enforces every context's `timeout:`. In
|
|
243
|
+
One watchdog thread per process enforces every context's `timeout:`. In both platform modes, a fork through Ruby waits for every runner to be idle or parked. Under `:single_threaded`, the child takes over contexts whose runners were idle at the fork, while contexts in use raise there. Default multi-threaded children refuse every inherited context. mini_racer_rs gives V8 a copied platform vtable in each process. Worker-thread slots post to its own pool. V8's platform has one worker thread, which receives no tasks. Forking pauses the pool. The parent resumes it afterward.
|
|
243
244
|
|
|
244
|
-
The implementation has
|
|
245
|
+
The implementation has five crates:
|
|
245
246
|
|
|
246
247
|
- `mini_racer_wire`: the wire codec, with no unsafe code.
|
|
247
248
|
- `mini_racer_sync`: the thread protocol, with no unsafe code and loom checking.
|
|
249
|
+
- `mini_racer_sourcemap`: source maps for JavaScript backtraces, with no unsafe code.
|
|
248
250
|
- `mini_racer_engine`: V8 process state and runners, and the only crate naming `v8`.
|
|
249
251
|
- `mini_racer_rs`: the Ruby extension, and the only crate naming magnus or rb-sys.
|
|
250
252
|
|
|
@@ -256,7 +258,7 @@ The release pipeline runs the full suites for every released extension.
|
|
|
256
258
|
|
|
257
259
|
mini_racer_rs does not:
|
|
258
260
|
|
|
259
|
-
- Run on Windows
|
|
261
|
+
- Run on Windows. It supports glibc and musl Linux, including Alpine, on x86_64 and aarch64, and macOS on arm64 and x86_64.
|
|
260
262
|
|
|
261
263
|
- Provide Node.js APIs. JavaScript runs in plain V8 without file system, network, or process access. It can reach only Ruby callables you `attach`.
|
|
262
264
|
|
|
@@ -272,7 +274,7 @@ Supported implementations are CRuby 3.3, 3.4, and 4.0, plus TruffleRuby through
|
|
|
272
274
|
|
|
273
275
|
| Document | Covers |
|
|
274
276
|
|---|---|
|
|
275
|
-
| [ARCHITECTURE.md](ARCHITECTURE.md) | Crates, a call end to end, values, termination, callbacks, promises, snapshots, forks, fiber schedulers,
|
|
277
|
+
| [ARCHITECTURE.md](ARCHITECTURE.md) | Crates, a call end to end, values, termination and limits, callbacks, promises and V8's tasks, snapshots, code cache, shared sources, fast calls, source maps, forks, fiber schedulers, rules that keep it safe, and how it is checked. |
|
|
276
278
|
| [COMPATIBILITY.md](COMPATIBILITY.md) | Every public API item and deliberate difference from mini_racer 0.22.1, with its reason. |
|
|
277
279
|
| [BENCHMARKS.md](BENCHMARKS.md) | Benchmark method and full results. |
|
|
278
280
|
| [STABILITY.md](STABILITY.md) | Versioning, the public API, unstable interfaces, and support policy. |
|
data/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -4559,3 +4559,203 @@ https://chromium.googlesource.com/chromium/src/+/refs/tags/152.0.7977.89/LICENSE
|
|
|
4559
4559
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4560
4560
|
```
|
|
4561
4561
|
|
|
4562
|
+
### musl
|
|
4563
|
+
|
|
4564
|
+
https://git.musl-libc.org/cgit/musl/plain/COPYRIGHT?h=v1.2.5
|
|
4565
|
+
|
|
4566
|
+
```text
|
|
4567
|
+
musl as a whole is licensed under the following standard MIT license:
|
|
4568
|
+
|
|
4569
|
+
----------------------------------------------------------------------
|
|
4570
|
+
Copyright © 2005-2020 Rich Felker, et al.
|
|
4571
|
+
|
|
4572
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4573
|
+
a copy of this software and associated documentation files (the
|
|
4574
|
+
"Software"), to deal in the Software without restriction, including
|
|
4575
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
4576
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
4577
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
4578
|
+
the following conditions:
|
|
4579
|
+
|
|
4580
|
+
The above copyright notice and this permission notice shall be
|
|
4581
|
+
included in all copies or substantial portions of the Software.
|
|
4582
|
+
|
|
4583
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
4584
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
4585
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
4586
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
4587
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
4588
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
4589
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
4590
|
+
----------------------------------------------------------------------
|
|
4591
|
+
|
|
4592
|
+
Authors/contributors include:
|
|
4593
|
+
|
|
4594
|
+
A. Wilcox
|
|
4595
|
+
Ada Worcester
|
|
4596
|
+
Alex Dowad
|
|
4597
|
+
Alex Suykov
|
|
4598
|
+
Alexander Monakov
|
|
4599
|
+
Andre McCurdy
|
|
4600
|
+
Andrew Kelley
|
|
4601
|
+
Anthony G. Basile
|
|
4602
|
+
Aric Belsito
|
|
4603
|
+
Arvid Picciani
|
|
4604
|
+
Bartosz Brachaczek
|
|
4605
|
+
Benjamin Peterson
|
|
4606
|
+
Bobby Bingham
|
|
4607
|
+
Boris Brezillon
|
|
4608
|
+
Brent Cook
|
|
4609
|
+
Chris Spiegel
|
|
4610
|
+
Clément Vasseur
|
|
4611
|
+
Daniel Micay
|
|
4612
|
+
Daniel Sabogal
|
|
4613
|
+
Daurnimator
|
|
4614
|
+
David Carlier
|
|
4615
|
+
David Edelsohn
|
|
4616
|
+
Denys Vlasenko
|
|
4617
|
+
Dmitry Ivanov
|
|
4618
|
+
Dmitry V. Levin
|
|
4619
|
+
Drew DeVault
|
|
4620
|
+
Emil Renner Berthing
|
|
4621
|
+
Fangrui Song
|
|
4622
|
+
Felix Fietkau
|
|
4623
|
+
Felix Janda
|
|
4624
|
+
Gianluca Anzolin
|
|
4625
|
+
Hauke Mehrtens
|
|
4626
|
+
He X
|
|
4627
|
+
Hiltjo Posthuma
|
|
4628
|
+
Isaac Dunham
|
|
4629
|
+
Jaydeep Patil
|
|
4630
|
+
Jens Gustedt
|
|
4631
|
+
Jeremy Huntwork
|
|
4632
|
+
Jo-Philipp Wich
|
|
4633
|
+
Joakim Sindholt
|
|
4634
|
+
John Spencer
|
|
4635
|
+
Julien Ramseier
|
|
4636
|
+
Justin Cormack
|
|
4637
|
+
Kaarle Ritvanen
|
|
4638
|
+
Khem Raj
|
|
4639
|
+
Kylie McClain
|
|
4640
|
+
Leah Neukirchen
|
|
4641
|
+
Luca Barbato
|
|
4642
|
+
Luka Perkov
|
|
4643
|
+
M Farkas-Dyck (Strake)
|
|
4644
|
+
Mahesh Bodapati
|
|
4645
|
+
Markus Wichmann
|
|
4646
|
+
Masanori Ogino
|
|
4647
|
+
Michael Clark
|
|
4648
|
+
Michael Forney
|
|
4649
|
+
Mikhail Kremnyov
|
|
4650
|
+
Natanael Copa
|
|
4651
|
+
Nicholas J. Kain
|
|
4652
|
+
orc
|
|
4653
|
+
Pascal Cuoq
|
|
4654
|
+
Patrick Oppenlander
|
|
4655
|
+
Petr Hosek
|
|
4656
|
+
Petr Skocik
|
|
4657
|
+
Pierre Carrier
|
|
4658
|
+
Reini Urban
|
|
4659
|
+
Rich Felker
|
|
4660
|
+
Richard Pennington
|
|
4661
|
+
Ryan Fairfax
|
|
4662
|
+
Samuel Holland
|
|
4663
|
+
Segev Finer
|
|
4664
|
+
Shiz
|
|
4665
|
+
sin
|
|
4666
|
+
Solar Designer
|
|
4667
|
+
Stefan Kristiansson
|
|
4668
|
+
Stefan O'Rear
|
|
4669
|
+
Szabolcs Nagy
|
|
4670
|
+
Timo Teräs
|
|
4671
|
+
Trutz Behn
|
|
4672
|
+
Valentin Ochs
|
|
4673
|
+
Will Dietz
|
|
4674
|
+
William Haddon
|
|
4675
|
+
William Pitcock
|
|
4676
|
+
|
|
4677
|
+
Portions of this software are derived from third-party works licensed
|
|
4678
|
+
under terms compatible with the above MIT license:
|
|
4679
|
+
|
|
4680
|
+
The TRE regular expression implementation (src/regex/reg* and
|
|
4681
|
+
src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
|
|
4682
|
+
under a 2-clause BSD license (license text in the source files). The
|
|
4683
|
+
included version has been heavily modified by Rich Felker in 2012, in
|
|
4684
|
+
the interests of size, simplicity, and namespace cleanliness.
|
|
4685
|
+
|
|
4686
|
+
Much of the math library code (src/math/* and src/complex/*) is
|
|
4687
|
+
Copyright © 1993,2004 Sun Microsystems or
|
|
4688
|
+
Copyright © 2003-2011 David Schultz or
|
|
4689
|
+
Copyright © 2003-2009 Steven G. Kargl or
|
|
4690
|
+
Copyright © 2003-2009 Bruce D. Evans or
|
|
4691
|
+
Copyright © 2008 Stephen L. Moshier or
|
|
4692
|
+
Copyright © 2017-2018 Arm Limited
|
|
4693
|
+
and labelled as such in comments in the individual source files. All
|
|
4694
|
+
have been licensed under extremely permissive terms.
|
|
4695
|
+
|
|
4696
|
+
The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
|
|
4697
|
+
The Android Open Source Project and is licensed under a two-clause BSD
|
|
4698
|
+
license. It was taken from Bionic libc, used on Android.
|
|
4699
|
+
|
|
4700
|
+
The AArch64 memcpy and memset code (src/string/aarch64/*) are
|
|
4701
|
+
Copyright © 1999-2019, Arm Limited.
|
|
4702
|
+
|
|
4703
|
+
The implementation of DES for crypt (src/crypt/crypt_des.c) is
|
|
4704
|
+
Copyright © 1994 David Burren. It is licensed under a BSD license.
|
|
4705
|
+
|
|
4706
|
+
The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
|
|
4707
|
+
originally written by Solar Designer and placed into the public
|
|
4708
|
+
domain. The code also comes with a fallback permissive license for use
|
|
4709
|
+
in jurisdictions that may not recognize the public domain.
|
|
4710
|
+
|
|
4711
|
+
The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
|
|
4712
|
+
Valentin Ochs and is licensed under an MIT-style license.
|
|
4713
|
+
|
|
4714
|
+
The x86_64 port was written by Nicholas J. Kain and is licensed under
|
|
4715
|
+
the standard MIT terms.
|
|
4716
|
+
|
|
4717
|
+
The mips and microblaze ports were originally written by Richard
|
|
4718
|
+
Pennington for use in the ellcc project. The original code was adapted
|
|
4719
|
+
by Rich Felker for build system and code conventions during upstream
|
|
4720
|
+
integration. It is licensed under the standard MIT terms.
|
|
4721
|
+
|
|
4722
|
+
The mips64 port was contributed by Imagination Technologies and is
|
|
4723
|
+
licensed under the standard MIT terms.
|
|
4724
|
+
|
|
4725
|
+
The powerpc port was also originally written by Richard Pennington,
|
|
4726
|
+
and later supplemented and integrated by John Spencer. It is licensed
|
|
4727
|
+
under the standard MIT terms.
|
|
4728
|
+
|
|
4729
|
+
All other files which have no copyright comments are original works
|
|
4730
|
+
produced specifically for use as part of this library, written either
|
|
4731
|
+
by Rich Felker, the main author of the library, or by one or more
|
|
4732
|
+
contibutors listed above. Details on authorship of individual files
|
|
4733
|
+
can be found in the git version control history of the project. The
|
|
4734
|
+
omission of copyright and license comments in each file is in the
|
|
4735
|
+
interest of source tree size.
|
|
4736
|
+
|
|
4737
|
+
In addition, permission is hereby granted for all public header files
|
|
4738
|
+
(include/* and arch/*/bits/*) and crt files intended to be linked into
|
|
4739
|
+
applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
|
|
4740
|
+
the copyright notice and permission notice otherwise required by the
|
|
4741
|
+
license, and to use these files without any requirement of
|
|
4742
|
+
attribution. These files include substantial contributions from:
|
|
4743
|
+
|
|
4744
|
+
Bobby Bingham
|
|
4745
|
+
John Spencer
|
|
4746
|
+
Nicholas J. Kain
|
|
4747
|
+
Rich Felker
|
|
4748
|
+
Richard Pennington
|
|
4749
|
+
Stefan Kristiansson
|
|
4750
|
+
Szabolcs Nagy
|
|
4751
|
+
|
|
4752
|
+
all of whom have explicitly granted such permission.
|
|
4753
|
+
|
|
4754
|
+
This file previously contained text expressing a belief that most of
|
|
4755
|
+
the files covered by the above exception were sufficiently trivial not
|
|
4756
|
+
to be subject to copyright, resulting in confusion over whether it
|
|
4757
|
+
negated the permissions granted in the license. In the spirit of
|
|
4758
|
+
permissive licensing, and of not having licensing issues being an
|
|
4759
|
+
obstacle to adoption, that text has been removed.
|
|
4760
|
+
```
|
|
4761
|
+
|
|
@@ -11,6 +11,7 @@ use mini_racer_sync::{
|
|
|
11
11
|
use crate::control::{
|
|
12
12
|
CallRequest, CallbackReply, ContextConfig, ControlBlock, Depth, JsText, Request, Wire,
|
|
13
13
|
};
|
|
14
|
+
use crate::counters::{Counters, Counts};
|
|
14
15
|
use crate::notify::NotifyFd;
|
|
15
16
|
use crate::process::fork::{self, Generation};
|
|
16
17
|
use crate::process::platform::Mode;
|
|
@@ -498,6 +499,26 @@ impl ContextHandle {
|
|
|
498
499
|
}
|
|
499
500
|
}
|
|
500
501
|
|
|
502
|
+
/// Read from atomics, without a dispatch or taking an inherited context
|
|
503
|
+
/// over: in a forked child that has not, the counts it inherited, and
|
|
504
|
+
/// after a dispose, the last ones.
|
|
505
|
+
#[must_use]
|
|
506
|
+
pub fn counters(&self) -> Counts {
|
|
507
|
+
let epoch = fork::epoch();
|
|
508
|
+
let mut lineage = &self.lineage;
|
|
509
|
+
let mut counted = None;
|
|
510
|
+
loop {
|
|
511
|
+
if let Held::Block(block) = &lineage.held {
|
|
512
|
+
counted = Some(&block.counters);
|
|
513
|
+
}
|
|
514
|
+
match lineage.next.get() {
|
|
515
|
+
Some(next) if lineage.epoch != epoch => lineage = next,
|
|
516
|
+
_ => break,
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
counted.map_or_else(Counts::default, Counters::read)
|
|
520
|
+
}
|
|
521
|
+
|
|
501
522
|
/// Answers without taking an inherited context over.
|
|
502
523
|
#[must_use]
|
|
503
524
|
pub fn is_disposed(&self) -> bool {
|
|
@@ -588,8 +609,15 @@ impl ContextHandle {
|
|
|
588
609
|
self.session.owner.store(thread, Ordering::Release);
|
|
589
610
|
let owning = Owning(&self.session.owner);
|
|
590
611
|
let wait = WaitHandle::new(block);
|
|
591
|
-
let
|
|
592
|
-
|
|
612
|
+
let request = request(Depth::Outermost(dispatch));
|
|
613
|
+
let payload = request.payload();
|
|
614
|
+
let result = match block.channel.request(request) {
|
|
615
|
+
Ok(()) => {
|
|
616
|
+
if let Some(bytes) = payload {
|
|
617
|
+
block.counters.dispatched(bytes);
|
|
618
|
+
}
|
|
619
|
+
self.await_response(block, &wait, false, host)
|
|
620
|
+
}
|
|
593
621
|
Err(error) => Err(channel(error)),
|
|
594
622
|
};
|
|
595
623
|
drop(owning);
|
|
@@ -628,11 +656,15 @@ impl ContextHandle {
|
|
|
628
656
|
return Err(error);
|
|
629
657
|
}
|
|
630
658
|
let wait = WaitHandle::new(block);
|
|
659
|
+
let payload = request.payload();
|
|
631
660
|
let result = block
|
|
632
661
|
.channel
|
|
633
662
|
.request(request)
|
|
634
663
|
.map_err(channel)
|
|
635
664
|
.and_then(|()| {
|
|
665
|
+
if let Some(bytes) = payload {
|
|
666
|
+
block.counters.dispatched(bytes);
|
|
667
|
+
}
|
|
636
668
|
let _waiting = Counted::enter(&self.session.waits);
|
|
637
669
|
self.await_response(block, &wait, true, host)
|
|
638
670
|
});
|
|
@@ -687,17 +719,21 @@ impl ContextHandle {
|
|
|
687
719
|
if nested && cancelled {
|
|
688
720
|
block.term.release();
|
|
689
721
|
}
|
|
690
|
-
|
|
722
|
+
let response = if disposed {
|
|
691
723
|
Err(EngineError::Disposed)
|
|
692
724
|
} else {
|
|
693
725
|
response
|
|
694
726
|
};
|
|
727
|
+
block.counters.answered(&response, nested && cancelled);
|
|
728
|
+
return response;
|
|
695
729
|
}
|
|
696
730
|
Ok(Some(ToRuby::Callback(request))) => {
|
|
731
|
+
block.counters.asked(request.len());
|
|
697
732
|
let reply = if cancelled {
|
|
698
733
|
CallbackReply::Abort
|
|
699
734
|
} else {
|
|
700
735
|
let _running = Counted::enter(&self.session.callbacks);
|
|
736
|
+
block.counters.called_back();
|
|
701
737
|
let reply = host.callback(&request);
|
|
702
738
|
if wait.forked() {
|
|
703
739
|
return Err(EngineError::Orphaned);
|
|
@@ -712,6 +748,7 @@ impl ContextHandle {
|
|
|
712
748
|
if matches!(reply, CallbackReply::Abort) && !cancelled {
|
|
713
749
|
abandon(&mut cancelled);
|
|
714
750
|
}
|
|
751
|
+
block.counters.replied(&reply);
|
|
715
752
|
block.channel.reply(reply).map_err(channel)?;
|
|
716
753
|
}
|
|
717
754
|
Ok(None) => {}
|
|
@@ -781,7 +818,11 @@ fn adopt(inherited: &ControlBlock, carried: Inherited) -> Held {
|
|
|
781
818
|
else {
|
|
782
819
|
return orphaned(true, false);
|
|
783
820
|
};
|
|
784
|
-
let block = Arc::new(ControlBlock::
|
|
821
|
+
let block = Arc::new(ControlBlock::adopted(
|
|
822
|
+
inherited.config.clone(),
|
|
823
|
+
tasks,
|
|
824
|
+
inherited.counters.inherited(),
|
|
825
|
+
));
|
|
785
826
|
*lock(&block.custody) = Some(isolate);
|
|
786
827
|
block.term.adopt(carried);
|
|
787
828
|
// The isolate keeps whatever termination V8 still held for it.
|
|
@@ -4,6 +4,7 @@ use std::time::{Duration, Instant};
|
|
|
4
4
|
|
|
5
5
|
use mini_racer_sync::{Channel, DispatchId, Protocol, RunnerPhase, TermCell, Terminator, lock};
|
|
6
6
|
|
|
7
|
+
use crate::counters::Counters;
|
|
7
8
|
use crate::notify::NotifyFd;
|
|
8
9
|
use crate::process::tasks::Tasks;
|
|
9
10
|
use crate::{EngineError, SnapshotBlob};
|
|
@@ -53,6 +54,14 @@ impl JsText {
|
|
|
53
54
|
Self::Utf16(units) => units.len(),
|
|
54
55
|
}
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
#[must_use]
|
|
59
|
+
pub const fn byte_len(&self) -> usize {
|
|
60
|
+
match self {
|
|
61
|
+
Self::Utf8(bytes) | Self::Latin1(bytes) => bytes.len(),
|
|
62
|
+
Self::Utf16(units) => units.len().saturating_mul(2),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
impl From<String> for JsText {
|
|
@@ -126,6 +135,39 @@ pub enum Request {
|
|
|
126
135
|
Dispose,
|
|
127
136
|
}
|
|
128
137
|
|
|
138
|
+
impl Request {
|
|
139
|
+
/// The bytes a counted dispatch hands JavaScript; `None` for the
|
|
140
|
+
/// context's own setup and dispose, which no caller asked for.
|
|
141
|
+
pub const fn payload(&self) -> Option<usize> {
|
|
142
|
+
match self {
|
|
143
|
+
Self::Init { .. } | Self::Dispose => None,
|
|
144
|
+
Self::Eval { source, .. } => Some(source.byte_len()),
|
|
145
|
+
Self::Call { request, .. } => Some(request.bytes.len()),
|
|
146
|
+
Self::Attach { request, .. } => Some(request.len()),
|
|
147
|
+
Self::Snapshot { code, .. } => Some(code.byte_len()),
|
|
148
|
+
Self::LowMemoryNotification { .. }
|
|
149
|
+
| Self::MicrotaskCheckpoint { .. }
|
|
150
|
+
| Self::HeapStats { .. }
|
|
151
|
+
| Self::HeapSnapshot { .. }
|
|
152
|
+
| Self::PumpMessageLoop { .. } => Some(0),
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/// Whether the runner's time on it counts as JavaScript's: the requests
|
|
157
|
+
/// that run scripts, not the heap's statistics, snapshot or full
|
|
158
|
+
/// collection, which can take far longer than the scripts.
|
|
159
|
+
pub const fn runs_script(&self) -> bool {
|
|
160
|
+
matches!(
|
|
161
|
+
self,
|
|
162
|
+
Self::Eval { .. }
|
|
163
|
+
| Self::Call { .. }
|
|
164
|
+
| Self::Attach { .. }
|
|
165
|
+
| Self::MicrotaskCheckpoint { .. }
|
|
166
|
+
| Self::PumpMessageLoop { .. }
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
129
171
|
pub struct IsolateTerminator {
|
|
130
172
|
handle: v8::IsolateHandle,
|
|
131
173
|
tasks: Arc<Tasks>,
|
|
@@ -205,6 +247,7 @@ pub struct ControlBlock {
|
|
|
205
247
|
// An idle single-threaded runner leaves its isolate here, its only owner
|
|
206
248
|
// then, so a forked child can hand it to a runner of its own.
|
|
207
249
|
pub custody: Mutex<Option<v8::SharedIsolate>>,
|
|
250
|
+
pub counters: Counters,
|
|
208
251
|
}
|
|
209
252
|
|
|
210
253
|
impl Drop for ControlBlock {
|
|
@@ -238,11 +281,12 @@ impl ControlBlock {
|
|
|
238
281
|
}
|
|
239
282
|
|
|
240
283
|
pub fn new(config: ContextConfig) -> Self {
|
|
241
|
-
Self::
|
|
284
|
+
Self::adopted(config, Tasks::default(), Counters::default())
|
|
242
285
|
}
|
|
243
286
|
|
|
244
|
-
/// For a forked child taking over an idle context with its queued tasks
|
|
245
|
-
|
|
287
|
+
/// For a forked child taking over an idle context with its queued tasks
|
|
288
|
+
/// and its counts.
|
|
289
|
+
pub fn adopted(config: ContextConfig, tasks: Tasks, counters: Counters) -> Self {
|
|
246
290
|
Self {
|
|
247
291
|
channel: Channel::default(),
|
|
248
292
|
term: TermCell::default(),
|
|
@@ -255,6 +299,7 @@ impl ControlBlock {
|
|
|
255
299
|
isolate: OnceLock::new(),
|
|
256
300
|
building: Mutex::new(None),
|
|
257
301
|
custody: Mutex::new(None),
|
|
302
|
+
counters,
|
|
258
303
|
}
|
|
259
304
|
}
|
|
260
305
|
}
|