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
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
2
|
+
use std::time::Duration;
|
|
3
|
+
|
|
4
|
+
use crate::control::CallbackReply;
|
|
5
|
+
use crate::{EngineError, JsError, JsErrorKind, TerminationCause};
|
|
6
|
+
|
|
7
|
+
/// What a context has done since it was made; a forked child that takes it
|
|
8
|
+
/// over counts on from its parent's counts.
|
|
9
|
+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
10
|
+
pub struct Counts {
|
|
11
|
+
/// Requests sent to the runner, nested ones included: evals, calls and
|
|
12
|
+
/// their await forms, attaches, heap statistics and snapshots, low memory
|
|
13
|
+
/// notifications, microtask checkpoints and pumps; not the context's own
|
|
14
|
+
/// setup or dispose.
|
|
15
|
+
pub dispatches: u64,
|
|
16
|
+
/// Attached Ruby callables run for JavaScript.
|
|
17
|
+
pub callbacks: u64,
|
|
18
|
+
/// An eval's source in the encoding it was sent in, a call's or attach's
|
|
19
|
+
/// request and a callback's value in V8's wire format, and the message of
|
|
20
|
+
/// an error a callback raised.
|
|
21
|
+
pub bytes_to_js: u64,
|
|
22
|
+
/// Each result the runner answered with and each callback's arguments.
|
|
23
|
+
pub bytes_from_js: u64,
|
|
24
|
+
/// The runner's time on evals, calls, attaches, microtask checkpoints and
|
|
25
|
+
/// pumps, short of its waits for Ruby callbacks, for a task an await
|
|
26
|
+
/// needs and for a fork.
|
|
27
|
+
pub js_ns: u64,
|
|
28
|
+
/// V8's scavenges, minor mark-sweeps and mark-compacts on the context's
|
|
29
|
+
/// isolate, in a dispatch or not.
|
|
30
|
+
pub gc_count: u64,
|
|
31
|
+
/// The runner's time inside them, from V8's prologue to its epilogue.
|
|
32
|
+
pub gc_ns: u64,
|
|
33
|
+
pub terminated: Terminations,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Dispatches a termination ended, by the cause the engine reported for each.
|
|
37
|
+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
38
|
+
pub struct Terminations {
|
|
39
|
+
pub stop: u64,
|
|
40
|
+
pub timeout: u64,
|
|
41
|
+
/// The caller abandoned the wait: an exception raised into it, or a throw
|
|
42
|
+
/// or kill out of a callback.
|
|
43
|
+
pub interrupt: u64,
|
|
44
|
+
pub max_memory: u64,
|
|
45
|
+
pub heap_exhausted: u64,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// A context's counts, in the control block. Each half has one writer at a
|
|
49
|
+
/// time, so an increment is a load and a store rather than a locked add: the
|
|
50
|
+
/// thread dispatching, which holds the context, or the runner. Readers on any
|
|
51
|
+
/// thread see each value on its own, never torn.
|
|
52
|
+
#[derive(Default)]
|
|
53
|
+
pub struct Counters {
|
|
54
|
+
caller: Caller,
|
|
55
|
+
runner: Runner,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 128 bytes apart, as x86's prefetcher fetches 64-byte lines in pairs and
|
|
59
|
+
// Apple's cores have 128-byte lines, so the two writers never share one.
|
|
60
|
+
#[derive(Default)]
|
|
61
|
+
#[repr(align(128))]
|
|
62
|
+
struct Caller {
|
|
63
|
+
dispatches: AtomicU64,
|
|
64
|
+
callbacks: AtomicU64,
|
|
65
|
+
bytes_to_js: AtomicU64,
|
|
66
|
+
bytes_from_js: AtomicU64,
|
|
67
|
+
terminated: [AtomicU64; 5],
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[derive(Default)]
|
|
71
|
+
#[repr(align(128))]
|
|
72
|
+
struct Runner {
|
|
73
|
+
js_ns: AtomicU64,
|
|
74
|
+
gc_count: AtomicU64,
|
|
75
|
+
gc_ns: AtomicU64,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fn add(counter: &AtomicU64, amount: u64) {
|
|
79
|
+
counter.store(
|
|
80
|
+
counter.load(Ordering::Relaxed).wrapping_add(amount),
|
|
81
|
+
Ordering::Relaxed,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fn read(counter: &AtomicU64) -> u64 {
|
|
86
|
+
counter.load(Ordering::Relaxed)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fn copied(counter: &AtomicU64) -> AtomicU64 {
|
|
90
|
+
AtomicU64::new(read(counter))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fn length(bytes: usize) -> u64 {
|
|
94
|
+
u64::try_from(bytes).unwrap_or(u64::MAX)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const fn slot(cause: TerminationCause) -> usize {
|
|
98
|
+
match cause {
|
|
99
|
+
TerminationCause::Stop => 0,
|
|
100
|
+
TerminationCause::Timeout => 1,
|
|
101
|
+
TerminationCause::Cancelled => 2,
|
|
102
|
+
TerminationCause::MaxMemory => 3,
|
|
103
|
+
TerminationCause::HeapExhausted => 4,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
impl Counters {
|
|
108
|
+
#[must_use]
|
|
109
|
+
pub fn read(&self) -> Counts {
|
|
110
|
+
let caller = &self.caller;
|
|
111
|
+
let terminated = |cause| read(&caller.terminated[slot(cause)]);
|
|
112
|
+
Counts {
|
|
113
|
+
dispatches: read(&caller.dispatches),
|
|
114
|
+
callbacks: read(&caller.callbacks),
|
|
115
|
+
bytes_to_js: read(&caller.bytes_to_js),
|
|
116
|
+
bytes_from_js: read(&caller.bytes_from_js),
|
|
117
|
+
js_ns: read(&self.runner.js_ns),
|
|
118
|
+
gc_count: read(&self.runner.gc_count),
|
|
119
|
+
gc_ns: read(&self.runner.gc_ns),
|
|
120
|
+
terminated: Terminations {
|
|
121
|
+
stop: terminated(TerminationCause::Stop),
|
|
122
|
+
timeout: terminated(TerminationCause::Timeout),
|
|
123
|
+
interrupt: terminated(TerminationCause::Cancelled),
|
|
124
|
+
max_memory: terminated(TerminationCause::MaxMemory),
|
|
125
|
+
heap_exhausted: terminated(TerminationCause::HeapExhausted),
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// The counts so far, for a forked child taking the context over, read
|
|
131
|
+
/// from atomics alone.
|
|
132
|
+
#[must_use]
|
|
133
|
+
pub fn inherited(&self) -> Self {
|
|
134
|
+
let caller = &self.caller;
|
|
135
|
+
Self {
|
|
136
|
+
caller: Caller {
|
|
137
|
+
dispatches: copied(&caller.dispatches),
|
|
138
|
+
callbacks: copied(&caller.callbacks),
|
|
139
|
+
bytes_to_js: copied(&caller.bytes_to_js),
|
|
140
|
+
bytes_from_js: copied(&caller.bytes_from_js),
|
|
141
|
+
terminated: std::array::from_fn(|at| copied(&caller.terminated[at])),
|
|
142
|
+
},
|
|
143
|
+
runner: Runner {
|
|
144
|
+
js_ns: copied(&self.runner.js_ns),
|
|
145
|
+
gc_count: copied(&self.runner.gc_count),
|
|
146
|
+
gc_ns: copied(&self.runner.gc_ns),
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
pub(crate) fn dispatched(&self, bytes: usize) {
|
|
152
|
+
add(&self.caller.dispatches, 1);
|
|
153
|
+
add(&self.caller.bytes_to_js, length(bytes));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
pub(crate) fn asked(&self, bytes: usize) {
|
|
157
|
+
add(&self.caller.bytes_from_js, length(bytes));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
pub(crate) fn called_back(&self) {
|
|
161
|
+
add(&self.caller.callbacks, 1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
pub(crate) fn replied(&self, reply: &CallbackReply) {
|
|
165
|
+
let bytes = match reply {
|
|
166
|
+
CallbackReply::Value(bytes) => bytes.len(),
|
|
167
|
+
CallbackReply::Raised(message) => message.byte_len(),
|
|
168
|
+
CallbackReply::Abort => return,
|
|
169
|
+
};
|
|
170
|
+
add(&self.caller.bytes_to_js, length(bytes));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// A dispatch's response as its caller gets it. A nested dispatch its
|
|
174
|
+
/// caller abandoned was ended without a cause of its own
|
|
175
|
+
/// (`TermCell::interrupt`), so its termination is the interrupt's, which
|
|
176
|
+
/// outranks every cause but the memory ones, as the engine ranks them.
|
|
177
|
+
pub(crate) fn answered(&self, response: &Result<Vec<u8>, EngineError>, abandoned: bool) {
|
|
178
|
+
match response {
|
|
179
|
+
Ok(bytes) => add(&self.caller.bytes_from_js, length(bytes.len())),
|
|
180
|
+
Err(EngineError::Js(JsError {
|
|
181
|
+
kind: JsErrorKind::Terminated(cause),
|
|
182
|
+
..
|
|
183
|
+
})) => {
|
|
184
|
+
let cause = match *cause {
|
|
185
|
+
memory @ (TerminationCause::MaxMemory | TerminationCause::HeapExhausted) => {
|
|
186
|
+
memory
|
|
187
|
+
}
|
|
188
|
+
_ if abandoned => TerminationCause::Cancelled,
|
|
189
|
+
other => other,
|
|
190
|
+
};
|
|
191
|
+
add(&self.caller.terminated[slot(cause)], 1);
|
|
192
|
+
}
|
|
193
|
+
Err(_) => {}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
pub(crate) fn ran_js(&self, nanoseconds: u64) {
|
|
198
|
+
add(&self.runner.js_ns, nanoseconds);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
pub(crate) fn collected(&self, took: Duration) {
|
|
202
|
+
add(&self.runner.gc_count, 1);
|
|
203
|
+
add(
|
|
204
|
+
&self.runner.gc_ns,
|
|
205
|
+
u64::try_from(took.as_nanos()).unwrap_or(u64::MAX),
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
mod context;
|
|
2
2
|
mod control;
|
|
3
|
+
mod counters;
|
|
3
4
|
mod error;
|
|
4
5
|
mod fast_calls;
|
|
5
6
|
mod notify;
|
|
@@ -18,6 +19,7 @@ mod text;
|
|
|
18
19
|
|
|
19
20
|
pub use context::{ContextHandle, Host, Unparker, WaitHandle, WaitOutcome};
|
|
20
21
|
pub use control::{CallRequest, CallbackReply, ContextConfig, JsText};
|
|
22
|
+
pub use counters::{Counts, Terminations};
|
|
21
23
|
pub use error::{
|
|
22
24
|
EngineError, FlagError, InvalidSnapshot, JsError, JsErrorKind, SourceMapError, TerminationCause,
|
|
23
25
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
use std::borrow::Cow;
|
|
2
|
+
use std::cell::Cell;
|
|
2
3
|
use std::collections::hash_map::RandomState;
|
|
3
4
|
use std::hash::BuildHasher;
|
|
4
5
|
use std::panic::{AssertUnwindSafe, catch_unwind};
|
|
5
|
-
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
|
6
|
+
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, Ordering};
|
|
6
7
|
use std::sync::{Arc, Mutex};
|
|
7
|
-
use std::time::Duration;
|
|
8
|
+
use std::time::{Duration, Instant};
|
|
8
9
|
|
|
9
10
|
use mini_racer_sourcemap::{Frame, Match, Placement, SourceMap};
|
|
10
11
|
use mini_racer_sync::{
|
|
@@ -74,6 +75,58 @@ struct Runtime {
|
|
|
74
75
|
frames: Mutex<Vec<v8::Global<v8::Array>>>,
|
|
75
76
|
// Scripts that hold a bundle with a source map, latest last.
|
|
76
77
|
matched: Mutex<Vec<Matched>>,
|
|
78
|
+
// When the runner's current stretch of JavaScript began, in nanoseconds
|
|
79
|
+
// after `clock`, or `STOPPED`; only the runner touches it.
|
|
80
|
+
clock: Instant,
|
|
81
|
+
since: AtomicU64,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const STOPPED: u64 = u64::MAX;
|
|
85
|
+
|
|
86
|
+
// Times the runner's JavaScript: started for a request that runs scripts,
|
|
87
|
+
// and paused while a callback waits for Ruby, an await sleeps until a task is
|
|
88
|
+
// due or a script waits out a fork. Each restores what it found, so a request
|
|
89
|
+
// nested in a callback is timed inside the pause.
|
|
90
|
+
struct Timing<'a> {
|
|
91
|
+
runtime: &'a Runtime,
|
|
92
|
+
was_running: bool,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
impl Drop for Timing<'_> {
|
|
96
|
+
fn drop(&mut self) {
|
|
97
|
+
self.runtime.switch(self.was_running);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The collections V8 runs on a runner's isolate. Kept apart from the
|
|
102
|
+
// runtime, which needs the isolate's contexts, so a collection while they
|
|
103
|
+
// are made counts too.
|
|
104
|
+
struct Collections {
|
|
105
|
+
block: Arc<ControlBlock>,
|
|
106
|
+
began: Cell<Option<Instant>>,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
impl Collections {
|
|
110
|
+
fn new(block: &Arc<ControlBlock>) -> Self {
|
|
111
|
+
Self {
|
|
112
|
+
block: Arc::clone(block),
|
|
113
|
+
began: Cell::new(None),
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
pub fn collection_began(isolate: &v8::Isolate) {
|
|
119
|
+
if let Some(collections) = isolate.get_slot::<Collections>() {
|
|
120
|
+
collections.began.set(Some(Instant::now()));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
pub fn collection_ended(isolate: &v8::Isolate) {
|
|
125
|
+
if let Some(collections) = isolate.get_slot::<Collections>()
|
|
126
|
+
&& let Some(began) = collections.began.take()
|
|
127
|
+
{
|
|
128
|
+
collections.block.counters.collected(began.elapsed());
|
|
129
|
+
}
|
|
77
130
|
}
|
|
78
131
|
|
|
79
132
|
#[derive(Clone)]
|
|
@@ -168,6 +221,30 @@ impl Runtime {
|
|
|
168
221
|
hoisting: Mutex::default(),
|
|
169
222
|
frames: Mutex::default(),
|
|
170
223
|
matched: Mutex::default(),
|
|
224
|
+
clock: Instant::now(),
|
|
225
|
+
since: AtomicU64::new(STOPPED),
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Charges the stretch running so far, if one is, and starts or stops the
|
|
230
|
+
// next; returns whether one was running. A load and a store, as only the
|
|
231
|
+
// runner writes either.
|
|
232
|
+
fn switch(&self, run: bool) -> bool {
|
|
233
|
+
let now = u64::try_from(self.clock.elapsed().as_nanos()).unwrap_or(STOPPED - 1);
|
|
234
|
+
let since = self.since.load(Ordering::Relaxed);
|
|
235
|
+
self.since
|
|
236
|
+
.store(if run { now } else { STOPPED }, Ordering::Relaxed);
|
|
237
|
+
if since == STOPPED {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
self.block.counters.ran_js(now.saturating_sub(since));
|
|
241
|
+
true
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
fn timing(&self, run: bool) -> Timing<'_> {
|
|
245
|
+
Timing {
|
|
246
|
+
runtime: self,
|
|
247
|
+
was_running: self.switch(run),
|
|
171
248
|
}
|
|
172
249
|
}
|
|
173
250
|
}
|
|
@@ -236,6 +313,7 @@ pub fn check_heap(isolate: &mut v8::Isolate) {
|
|
|
236
313
|
|
|
237
314
|
pub fn park_for_fork(isolate: &v8::Isolate) {
|
|
238
315
|
if let Some(runtime) = isolate.get_slot::<Arc<Runtime>>() {
|
|
316
|
+
let _paused = runtime.timing(false);
|
|
239
317
|
runtime.generation.pause(&runtime.block);
|
|
240
318
|
}
|
|
241
319
|
}
|
|
@@ -264,6 +342,8 @@ fn serve(block: &Arc<ControlBlock>, generation: &'static Generation) -> bool {
|
|
|
264
342
|
None => params,
|
|
265
343
|
};
|
|
266
344
|
let mut isolate = v8::Isolate::new(params);
|
|
345
|
+
isolate.set_slot(Collections::new(block));
|
|
346
|
+
sys::count_collections(&mut isolate);
|
|
267
347
|
if block.config.max_memory.is_some() {
|
|
268
348
|
sys::watch_heap(&mut isolate);
|
|
269
349
|
}
|
|
@@ -329,6 +409,8 @@ fn adopt(
|
|
|
329
409
|
lock(&runtime.matched).clone_from(&matched);
|
|
330
410
|
}
|
|
331
411
|
locker.set_slot(Arc::clone(&runtime));
|
|
412
|
+
// The parent's callbacks stay registered and now count here.
|
|
413
|
+
locker.set_slot(Collections::new(block));
|
|
332
414
|
runtime
|
|
333
415
|
};
|
|
334
416
|
block
|
|
@@ -568,6 +650,7 @@ fn handle(
|
|
|
568
650
|
runtime: &Runtime,
|
|
569
651
|
request: Request,
|
|
570
652
|
) -> Result<Vec<u8>, EngineError> {
|
|
653
|
+
let _timing = request.runs_script().then(|| runtime.timing(true));
|
|
571
654
|
match request {
|
|
572
655
|
Request::Init { depth } => match depth {
|
|
573
656
|
Depth::Outermost(dispatch) => ended(runtime, dispatch),
|
|
@@ -1301,6 +1384,7 @@ fn await_promise<'s>(
|
|
|
1301
1384
|
// Waiting, the runner holds its isolate but runs nothing in it, so a fork need
|
|
1302
1385
|
// not wait for it.
|
|
1303
1386
|
fn wait_for_task(runtime: &Runtime) {
|
|
1387
|
+
let _paused = runtime.timing(false);
|
|
1304
1388
|
runtime.block.phase.set(Phase::Parked);
|
|
1305
1389
|
runtime.block.tasks.wait();
|
|
1306
1390
|
runtime.generation.resume(&runtime.block);
|
|
@@ -1570,6 +1654,7 @@ fn callback<'s>(
|
|
|
1570
1654
|
let Some(bytes) = serialize::write(scope, request.into()) else {
|
|
1571
1655
|
return;
|
|
1572
1656
|
};
|
|
1657
|
+
let waiting = runtime.timing(false);
|
|
1573
1658
|
if runtime.block.channel.callback(bytes).is_err() {
|
|
1574
1659
|
terminate(scope, runtime);
|
|
1575
1660
|
return;
|
|
@@ -1599,6 +1684,7 @@ fn callback<'s>(
|
|
|
1599
1684
|
return;
|
|
1600
1685
|
}
|
|
1601
1686
|
};
|
|
1687
|
+
drop(waiting);
|
|
1602
1688
|
// A nested dispatch that was halted leaves its termination to unwind
|
|
1603
1689
|
// this script too, as mini_racer restores it.
|
|
1604
1690
|
let terminating = scope.is_execution_terminating();
|
|
@@ -32,8 +32,8 @@ pub extern "C" fn __wrap_madvise(
|
|
|
32
32
|
/// runner to drop.
|
|
33
33
|
pub fn share(isolate: v8::OwnedIsolate) -> Result<v8::SharedIsolate, v8::OwnedIsolate> {
|
|
34
34
|
// SAFETY: the runner calls this on the thread that created `isolate`, with
|
|
35
|
-
// no reference from `Global::open` live, and the only
|
|
36
|
-
// `Arc<Runtime
|
|
35
|
+
// no reference from `Global::open` live, and the only slots it sets, an
|
|
36
|
+
// `Arc<Runtime>` and its `Collections`, are Send.
|
|
37
37
|
let shared = unsafe { isolate.try_into_shared() };
|
|
38
38
|
shared.map_err(v8::IntoSharedError::into_isolate)
|
|
39
39
|
}
|
|
@@ -208,6 +208,51 @@ unsafe extern "C" fn after_gc(
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/// Has V8 report the start and end of each collection on `isolate` for its
|
|
212
|
+
/// runner's counters: scavenges, minor mark-sweeps and mark-compacts, not the
|
|
213
|
+
/// start of incremental marking or the processing of weak callbacks, which
|
|
214
|
+
/// collect nothing.
|
|
215
|
+
pub fn count_collections(isolate: &mut v8::Isolate) {
|
|
216
|
+
let collections = v8::GCType::kGCTypeScavenge
|
|
217
|
+
| v8::GCType::kGCTypeMinorMarkSweep
|
|
218
|
+
| v8::GCType::kGCTypeMarkSweepCompact;
|
|
219
|
+
isolate.add_gc_prologue_callback(collection_began, std::ptr::null_mut(), collections);
|
|
220
|
+
isolate.add_gc_epilogue_callback(collection_ended, std::ptr::null_mut(), collections);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
unsafe extern "C" fn collection_began(
|
|
224
|
+
isolate: v8::UnsafeRawIsolatePtr,
|
|
225
|
+
_type: v8::GCType,
|
|
226
|
+
_flags: v8::GCCallbackFlags,
|
|
227
|
+
_data: *mut c_void,
|
|
228
|
+
) {
|
|
229
|
+
let counted = std::panic::catch_unwind(|| {
|
|
230
|
+
// SAFETY: V8 calls a GC prologue callback on the thread that has the
|
|
231
|
+
// isolate entered, with its own non-null pointer to it.
|
|
232
|
+
let isolate = unsafe { v8::Isolate::ref_from_raw_isolate_ptr(&isolate) };
|
|
233
|
+
crate::runner::collection_began(isolate);
|
|
234
|
+
});
|
|
235
|
+
if counted.is_err() {
|
|
236
|
+
std::process::abort();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
unsafe extern "C" fn collection_ended(
|
|
241
|
+
isolate: v8::UnsafeRawIsolatePtr,
|
|
242
|
+
_type: v8::GCType,
|
|
243
|
+
_flags: v8::GCCallbackFlags,
|
|
244
|
+
_data: *mut c_void,
|
|
245
|
+
) {
|
|
246
|
+
let counted = std::panic::catch_unwind(|| {
|
|
247
|
+
// SAFETY: as in `collection_began`, for the epilogue.
|
|
248
|
+
let isolate = unsafe { v8::Isolate::ref_from_raw_isolate_ptr(&isolate) };
|
|
249
|
+
crate::runner::collection_ended(isolate);
|
|
250
|
+
});
|
|
251
|
+
if counted.is_err() {
|
|
252
|
+
std::process::abort();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
211
256
|
/// Asks the isolate's runner to park for a pending fork the next time V8
|
|
212
257
|
/// checks for interrupts, where JavaScript may be running for a long time.
|
|
213
258
|
pub fn interrupt_for_fork(handle: &v8::IsolateHandle) {
|
|
@@ -10,6 +10,8 @@ end
|
|
|
10
10
|
TARGETS = {
|
|
11
11
|
%w[x86_64 linux] => "x86_64-unknown-linux-gnu",
|
|
12
12
|
%w[aarch64 linux] => "aarch64-unknown-linux-gnu",
|
|
13
|
+
%w[x86_64 linux-musl] => "x86_64-unknown-linux-musl",
|
|
14
|
+
%w[aarch64 linux-musl] => "aarch64-unknown-linux-musl",
|
|
13
15
|
%w[arm64 darwin] => "aarch64-apple-darwin",
|
|
14
16
|
%w[aarch64 darwin] => "aarch64-apple-darwin",
|
|
15
17
|
%w[x86_64 darwin] => "x86_64-apple-darwin",
|
|
@@ -18,13 +20,13 @@ MINIMUM_RUST = Gem::Version.new("1.91.0")
|
|
|
18
20
|
|
|
19
21
|
host_os = RbConfig::CONFIG["host_os"]
|
|
20
22
|
os = case host_os
|
|
21
|
-
when /linux-musl/ then
|
|
23
|
+
when /linux-musl/ then "linux-musl"
|
|
22
24
|
when /linux/ then "linux"
|
|
23
25
|
when /darwin/ then "darwin"
|
|
24
26
|
end
|
|
25
27
|
target = os && TARGETS[[RbConfig::CONFIG["host_cpu"], os]]
|
|
26
28
|
unless target
|
|
27
|
-
abort "mini_racer_rs supports Linux (glibc) on x86_64 and aarch64 and macOS on arm64 and x86_64; " \
|
|
29
|
+
abort "mini_racer_rs supports Linux (glibc or musl) on x86_64 and aarch64 and macOS on arm64 and x86_64; " \
|
|
28
30
|
"#{RbConfig::CONFIG["host_cpu"]}-#{host_os} is not supported"
|
|
29
31
|
end
|
|
30
32
|
|
|
@@ -74,5 +76,8 @@ require "rb_sys/mkmf"
|
|
|
74
76
|
|
|
75
77
|
create_rust_makefile("mini_racer_rs/mini_racer_rs") do |r|
|
|
76
78
|
r.extra_cargo_args += ["--locked"]
|
|
79
|
+
# rb_sys hands -crt-static to rustc alone, but cargo refuses a musl cdylib
|
|
80
|
+
# from RUSTFLAGS before rustc runs.
|
|
81
|
+
r.extra_rustflags += ["-C", "target-feature=-crt-static"] if os == "linux-musl"
|
|
77
82
|
r.env.merge!(build_env)
|
|
78
83
|
end
|
|
@@ -11,7 +11,7 @@ use magnus::{
|
|
|
11
11
|
Class, DataTypeFunctions, Error, Fixnum, Module, RArray, RHash, RModule, RString, Ruby, Symbol,
|
|
12
12
|
TypedData, Value,
|
|
13
13
|
};
|
|
14
|
-
use mini_racer_engine::{ContextConfig, ContextHandle, EngineError, JsText};
|
|
14
|
+
use mini_racer_engine::{ContextConfig, ContextHandle, Counts, EngineError, JsText};
|
|
15
15
|
|
|
16
16
|
use crate::encode;
|
|
17
17
|
use crate::gc_root::OwnedRoot;
|
|
@@ -197,6 +197,10 @@ fn config(ruby: &Ruby, keywords: RHash) -> Result<ContextConfig, Error> {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
impl Context {
|
|
200
|
+
pub fn counters(&self, ruby: &Ruby) -> Result<Counts, Error> {
|
|
201
|
+
Ok(self.handle(ruby)?.counters())
|
|
202
|
+
}
|
|
203
|
+
|
|
200
204
|
fn handle(&self, ruby: &Ruby) -> Result<&ContextHandle, Error> {
|
|
201
205
|
self.handle
|
|
202
206
|
.get()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
use magnus::{Error, Object, RHash, RModule, Ruby};
|
|
2
|
+
|
|
3
|
+
use crate::context::Context;
|
|
4
|
+
use crate::export;
|
|
5
|
+
|
|
6
|
+
pub fn init(rs: RModule) -> Result<(), Error> {
|
|
7
|
+
rs.define_singleton_method("counters", export!(function counters, 1))?;
|
|
8
|
+
Ok(())
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Read without the context's lock, so a thread can read a context another
|
|
12
|
+
// thread is running.
|
|
13
|
+
fn counters(ruby: &Ruby, context: &Context) -> Result<RHash, Error> {
|
|
14
|
+
let counts = context.counters(ruby)?;
|
|
15
|
+
let terminated = counts.terminated;
|
|
16
|
+
let causes = ruby.hash_new();
|
|
17
|
+
for (name, count) in [
|
|
18
|
+
("stop", terminated.stop),
|
|
19
|
+
("timeout", terminated.timeout),
|
|
20
|
+
("interrupt", terminated.interrupt),
|
|
21
|
+
("max_memory", terminated.max_memory),
|
|
22
|
+
("heap_exhausted", terminated.heap_exhausted),
|
|
23
|
+
] {
|
|
24
|
+
causes.aset(ruby.to_symbol(name), count)?;
|
|
25
|
+
}
|
|
26
|
+
let hash = ruby.hash_new();
|
|
27
|
+
for (name, count) in [
|
|
28
|
+
("dispatches", counts.dispatches),
|
|
29
|
+
("callbacks", counts.callbacks),
|
|
30
|
+
("bytes_to_js", counts.bytes_to_js),
|
|
31
|
+
("bytes_from_js", counts.bytes_from_js),
|
|
32
|
+
("js_ns", counts.js_ns),
|
|
33
|
+
("gc_count", counts.gc_count),
|
|
34
|
+
("gc_ns", counts.gc_ns),
|
|
35
|
+
] {
|
|
36
|
+
hash.aset(ruby.to_symbol(name), count)?;
|
|
37
|
+
}
|
|
38
|
+
hash.aset(ruby.to_symbol("terminated"), causes)?;
|
|
39
|
+
Ok(hash)
|
|
40
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
mod context;
|
|
2
|
+
mod counters;
|
|
2
3
|
mod decode;
|
|
3
4
|
mod encode;
|
|
4
5
|
mod errors;
|
|
@@ -48,6 +49,7 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
48
49
|
context::init(ruby, racer)?;
|
|
49
50
|
snapshot::init(ruby, racer)?;
|
|
50
51
|
source_maps::init(rs)?;
|
|
52
|
+
counters::init(rs)?;
|
|
51
53
|
fork::init(ruby, rs)?;
|
|
52
54
|
Ok(())
|
|
53
55
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
a4a5484444ad4b5f10dc7bed141236dd9dbeabf2006d14520f19b935d4db4227 librusty_v8_release_aarch64-apple-darwin.a.gz
|
|
2
2
|
c40196bbf182532e583f65b7daf0196fdbb3354e6fac59b31d0539c20f931f3d librusty_v8_release_aarch64-unknown-linux-gnu.a.gz
|
|
3
|
+
419a242557833151cf9dde82c12c8272c3c00015bfe7e340e48164a600d34039 librusty_v8_release_aarch64-unknown-linux-musl.a.gz
|
|
3
4
|
04cbc1c36c4cd5459c54049775d92889337c69d936fb0b011f9b26f1d454610d librusty_v8_release_x86_64-apple-darwin.a.gz
|
|
4
5
|
b6683e9afcb77fbd8cb2c3acf45d34d52029ab216b332522c95179c12f0fed3c librusty_v8_release_x86_64-unknown-linux-gnu.a.gz
|
|
6
|
+
68f284fb8184b9f9e8d7e23b8f2675dbe464f43f77c0bf152f705bf7ead29558 librusty_v8_release_x86_64-unknown-linux-musl.a.gz
|
|
5
7
|
b9d5652ebca515eb2bf4c2ee4a6551b2567117b5aa720f430d2032616dd7e3b5 src_binding_release_aarch64-apple-darwin.rs
|
|
6
8
|
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_release_aarch64-unknown-linux-gnu.rs
|
|
9
|
+
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_release_aarch64-unknown-linux-musl.rs
|
|
7
10
|
b9d5652ebca515eb2bf4c2ee4a6551b2567117b5aa720f430d2032616dd7e3b5 src_binding_release_x86_64-apple-darwin.rs
|
|
8
11
|
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_release_x86_64-unknown-linux-gnu.rs
|
|
12
|
+
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_release_x86_64-unknown-linux-musl.rs
|
data/licenses/v8/SOURCES.tsv
CHANGED
|
@@ -18,3 +18,4 @@ simdutf LICENSE https://chromium.googlesource.com/chromium/src/third_party/simdu
|
|
|
18
18
|
fast_float LICENSE-MIT https://chromium.googlesource.com/external/github.com/fastfloat/fast_float/+/34164f547b7df3f5d794ff67e9f885c36819ebfc/LICENSE-MIT e562f3f974ced7e69dd1db77b820b36bcf8f30377f1aa105723fba449c53c4e6
|
|
19
19
|
dragonbox LICENSE-Boost https://chromium.googlesource.com/external/github.com/jk-jeon/dragonbox/+/beeeef91cf6fef89a4d4ba5e95d47ca64ccb3a44/LICENSE-Boost c9bff75738922193e67fa726fa225535870d2aa1059f91452c411736284ad566
|
|
20
20
|
chromium-build LICENSE https://chromium.googlesource.com/chromium/src/+/refs/tags/152.0.7977.89/LICENSE 368cca1106be99d39ecd32a38d8305585d802a475effb66380b91ffc9bcf709b
|
|
21
|
+
musl COPYRIGHT https://git.musl-libc.org/cgit/musl/plain/COPYRIGHT?h=v1.2.5 f9bc4423732350eb0b3f7ed7e91d530298476f8fec0c6c427a1c04ade22655af
|
data/licenses/v8/components.tsv
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# Code compiled into rusty_v8's prebuilt archives. archive_path is a source
|
|
2
2
|
# directory the archives' debug strings name: a top-level directory, or one
|
|
3
3
|
# third_party/<name>. source is where its license comes from: a rusty_v8
|
|
4
|
-
# submodule at the release tag ("submodule:<path>"), or a pinned base URL
|
|
5
|
-
# with file "-" means another section
|
|
4
|
+
# submodule at the release tag ("submodule:<path>"), or a pinned base URL, whose
|
|
5
|
+
# query (a cgit ref) follows the file; "-" with file "-" means another section
|
|
6
|
+
# of THIRD_PARTY_NOTICES.md covers it.
|
|
6
7
|
# component archive_path source file
|
|
7
8
|
v8 v8 submodule:v8 LICENSE
|
|
8
9
|
v8 v8 submodule:v8 LICENSE.fdlibm
|
|
@@ -24,6 +25,9 @@ dragonbox third_party/dragonbox submodule:third_party/dragonbox/src LICENSE-Boos
|
|
|
24
25
|
# Chromium's build/ has no license file of its own; its sources defer to
|
|
25
26
|
# Chromium's, pinned at the release line matching V8 15.2.
|
|
26
27
|
chromium-build build https://chromium.googlesource.com/chromium/src/+/refs/tags/152.0.7977.89 LICENSE
|
|
28
|
+
# The musl archives compile against the musl headers of rusty_v8's release
|
|
29
|
+
# sysroot: musl 1.2.2 for x86_64, 1.2.5 for aarch64, whose COPYRIGHT files match.
|
|
30
|
+
musl musl-sysroot https://git.musl-libc.org/cgit/musl/plain?h=v1.2.5 COPYRIGHT
|
|
27
31
|
# rusty_v8's own bindings: the v8 crate in the Rust crates section.
|
|
28
32
|
rusty_v8 src - -
|
|
29
33
|
temporal_capi third_party/rust/chromium_crates_io/vendor/temporal_capi-v0_2 - -
|