summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-18 10:59:51 -0400
committerGitHub <noreply@github.com>2023-03-18 14:59:51 +0000
commitd11e89127d723d84afe6e5603b731c014a54f9da (patch)
tree06dbfe0b8d8eb965e477472cff223a8d335c50ad /core/runtime.rs
parent8af0c8351935ea7c6c0441055d5164908322c9d6 (diff)
Revert "perf(core): preserve ops between snapshots (#18080)" (#18267)
This reverts commit 4b6305f4f25fc76f974bbdcc9cdb139d5ab8f5f4.
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs66
1 files changed, 29 insertions, 37 deletions
diff --git a/core/runtime.rs b/core/runtime.rs
index f1aa63f23..a08e65134 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -319,7 +319,6 @@ impl JsRuntime {
DENO_INIT.call_once(move || v8_init(v8_platform, options.will_snapshot));
// Add builtins extension
- // TODO(bartlomieju): remove this in favor of `SnapshotOptions`.
let has_startup_snapshot = options.startup_snapshot.is_some();
if !has_startup_snapshot {
options
@@ -376,8 +375,12 @@ impl JsRuntime {
let op_ctxs = ops
.into_iter()
.enumerate()
- .map(|(id, decl)| {
- OpCtx::new(id, 0, Rc::new(decl), op_state.clone(), weak.clone())
+ .map(|(id, decl)| OpCtx {
+ id,
+ state: op_state.clone(),
+ runtime_state: weak.clone(),
+ decl: Rc::new(decl),
+ realm_idx: 0,
})
.collect::<Vec<_>>()
.into_boxed_slice();
@@ -386,7 +389,7 @@ impl JsRuntime {
options.startup_snapshot.is_some(),
options.will_snapshot,
);
- let refs = bindings::external_references(&op_ctxs);
+ let refs = bindings::external_references(&op_ctxs, snapshot_options);
// V8 takes ownership of external_references.
let refs: &'static v8::ExternalReferences = Box::leak(Box::new(refs));
let global_context;
@@ -395,7 +398,7 @@ impl JsRuntime {
let (mut isolate, snapshot_options) = if snapshot_options.will_snapshot() {
let snapshot_creator =
snapshot_util::create_snapshot_creator(refs, options.startup_snapshot);
- eprintln!("create snapshot {:#?}", snapshot_options);
+
let mut isolate = JsRuntime::setup_isolate(snapshot_creator);
{
let scope = &mut v8::HandleScope::new(&mut isolate);
@@ -457,7 +460,6 @@ impl JsRuntime {
isolate_ptr.write(isolate);
isolate_ptr.read()
};
-
global_context.open(&mut isolate).set_slot(
&mut isolate,
Rc::new(RefCell::new(ContextState {
@@ -618,14 +620,12 @@ impl JsRuntime {
.borrow()
.op_ctxs
.iter()
- .map(|op_ctx| {
- OpCtx::new(
- op_ctx.id,
- realm_idx,
- op_ctx.decl.clone(),
- op_ctx.state.clone(),
- op_ctx.runtime_state.clone(),
- )
+ .map(|op_ctx| OpCtx {
+ id: op_ctx.id,
+ state: op_ctx.state.clone(),
+ decl: op_ctx.decl.clone(),
+ runtime_state: op_ctx.runtime_state.clone(),
+ realm_idx,
})
.collect();
@@ -927,6 +927,18 @@ impl JsRuntime {
///
/// `Error` can usually be downcast to `JsError`.
pub fn snapshot(mut self) -> v8::StartupData {
+ // Nuke Deno.core.ops.* to avoid ExternalReference snapshotting issues
+ // TODO(@AaronO): make ops stable across snapshots
+ {
+ let scope = &mut self.handle_scope();
+ let o = Self::eval::<v8::Object>(scope, "Deno.core.ops").unwrap();
+ let names = o.get_own_property_names(scope, Default::default()).unwrap();
+ for i in 0..names.length() {
+ let key = names.get_index(scope, i).unwrap();
+ o.delete(scope, key);
+ }
+ }
+
self.state.borrow_mut().inspector.take();
// Serialize the module map and store its data in the snapshot.
@@ -3544,18 +3556,10 @@ pub mod tests {
}
}
- #[op]
- fn op_test() -> Result<String, Error> {
- Ok(String::from("test"))
- }
-
let loader = Rc::new(ModsLoader::default());
let mut runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(loader.clone()),
will_snapshot: true,
- extensions: vec![Extension::builder("text_ext")
- .ops(vec![op_test::decl()])
- .build()],
..Default::default()
});
@@ -3590,9 +3594,6 @@ pub mod tests {
module_loader: Some(loader.clone()),
will_snapshot: true,
startup_snapshot: Some(Snapshot::JustCreated(snapshot)),
- extensions: vec![Extension::builder("text_ext")
- .ops(vec![op_test::decl()])
- .build()],
..Default::default()
});
@@ -3608,9 +3609,6 @@ pub mod tests {
let mut runtime3 = JsRuntime::new(RuntimeOptions {
module_loader: Some(loader),
startup_snapshot: Some(Snapshot::JustCreated(snapshot2)),
- extensions: vec![Extension::builder("text_ext")
- .ops(vec![op_test::decl()])
- .build()],
..Default::default()
});
@@ -3618,7 +3616,7 @@ pub mod tests {
let source_code = r#"(async () => {
const mod = await import("file:///400.js");
- return mod.f400() + " " + Deno.core.ops.op_test();
+ return mod.f400();
})();"#
.to_string();
let val = runtime3.execute_script(".", &source_code).unwrap();
@@ -3627,7 +3625,7 @@ pub mod tests {
let scope = &mut runtime3.handle_scope();
let value = v8::Local::new(scope, val);
let str_ = value.to_string(scope).unwrap().to_rust_string_lossy(scope);
- assert_eq!(str_, "hello world test");
+ assert_eq!(str_, "hello world");
}
}
@@ -4602,13 +4600,7 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", {
Ok(String::from("Test"))
}
- deno_core::extension!(
- test_ext,
- ops = [op_test],
- customizer = |ext: &mut deno_core::ExtensionBuilder| {
- ext.force_op_registration();
- },
- );
+ deno_core::extension!(test_ext, ops = [op_test]);
let mut runtime = JsRuntime::new(RuntimeOptions {
startup_snapshot: Some(Snapshot::Boxed(snapshot)),
extensions: vec![test_ext::init_ops()],