From 04e85b044e395f11b7774d72156f7ec5ba0aa8ba Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 Oct 2020 22:23:35 -0700 Subject: [PATCH] Don't store `Arc` in instances Similar to other data structures owned by the `Store` there's no need for `Instance` to have a strong `Arc` reference, instead it's sufficient for `Store` to have the owning reference. --- crates/jit/src/instantiate.rs | 2 +- crates/runtime/src/instance.rs | 9 ++------- crates/runtime/src/traphandlers.rs | 4 ++-- crates/wasmtime/src/instance.rs | 2 +- crates/wasmtime/src/runtime.rs | 4 ++-- crates/wasmtime/src/trampoline/create_handle.rs | 2 +- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/jit/src/instantiate.rs b/crates/jit/src/instantiate.rs index 3320fec25e..5dfe603137 100644 --- a/crates/jit/src/instantiate.rs +++ b/crates/jit/src/instantiate.rs @@ -250,7 +250,7 @@ impl CompiledModule { imports: Imports<'_>, signature_registry: &mut SignatureRegistry, mem_creator: Option<&dyn RuntimeMemoryCreator>, - interrupts: Arc, + interrupts: *const VMInterrupts, host_state: Box, externref_activations_table: *mut VMExternRefActivationsTable, stack_map_registry: *mut StackMapRegistry, diff --git a/crates/runtime/src/instance.rs b/crates/runtime/src/instance.rs index a0aa85a549..41ace18d1f 100644 --- a/crates/runtime/src/instance.rs +++ b/crates/runtime/src/instance.rs @@ -71,10 +71,6 @@ pub(crate) struct Instance { /// Hosts can store arbitrary per-instance information here. host_state: Box, - /// Externally allocated data indicating how this instance will be - /// interrupted. - pub(crate) interrupts: Arc, - /// Additional context used by compiled wasm code. This field is last, and /// represents a dynamically-sized array that extends beyond the nominal /// end of the struct (similar to a flexible array member). @@ -827,7 +823,7 @@ impl InstanceHandle { mem_creator: Option<&dyn RuntimeMemoryCreator>, vmshared_signatures: BoxedSlice, host_state: Box, - interrupts: Arc, + interrupts: *const VMInterrupts, externref_activations_table: *mut VMExternRefActivationsTable, stack_map_registry: *mut StackMapRegistry, ) -> Result { @@ -867,7 +863,6 @@ impl InstanceHandle { finished_functions, trampolines, host_state, - interrupts, vmctx: VMContext {}, }; let layout = instance.alloc_layout(); @@ -934,7 +929,7 @@ impl InstanceHandle { instance.builtin_functions_ptr() as *mut VMBuiltinFunctionsArray, VMBuiltinFunctionsArray::initialized(), ); - *instance.interrupts() = &*instance.interrupts; + *instance.interrupts() = interrupts; *instance.externref_activations_table() = externref_activations_table; *instance.stack_map_registry() = stack_map_registry; diff --git a/crates/runtime/src/traphandlers.rs b/crates/runtime/src/traphandlers.rs index f7ee445a1d..4cea12eaac 100644 --- a/crates/runtime/src/traphandlers.rs +++ b/crates/runtime/src/traphandlers.rs @@ -453,8 +453,8 @@ impl<'a> CallThreadState<'a> { UnwindReason::JitTrap { backtrace, pc } => { debug_assert_eq!(ret, 0); let maybe_interrupted = unsafe { - (*self.vmctx).instance().interrupts.stack_limit.load(SeqCst) - == wasmtime_environ::INTERRUPTED + let interrupts = (*self.vmctx).instance().interrupts(); + (**interrupts).stack_limit.load(SeqCst) == wasmtime_environ::INTERRUPTED }; Err(Trap::Jit { pc, diff --git a/crates/wasmtime/src/instance.rs b/crates/wasmtime/src/instance.rs index 2ca3aa421c..7efe78fab4 100644 --- a/crates/wasmtime/src/instance.rs +++ b/crates/wasmtime/src/instance.rs @@ -22,7 +22,7 @@ fn instantiate( imports, &mut store.signatures_mut(), config.memory_creator.as_ref().map(|a| a as _), - store.interrupts().clone(), + store.interrupts(), host, store.externref_activations_table() as *const VMExternRefActivationsTable as *mut _, store.stack_map_registry() as *const StackMapRegistry as *mut _, diff --git a/crates/wasmtime/src/runtime.rs b/crates/wasmtime/src/runtime.rs index 5d0df2f6c8..a72ac18b0e 100644 --- a/crates/wasmtime/src/runtime.rs +++ b/crates/wasmtime/src/runtime.rs @@ -1030,7 +1030,7 @@ impl Store { self.inner.signal_handler.borrow_mut() } - pub(crate) fn interrupts(&self) -> &Arc { + pub(crate) fn interrupts(&self) -> &VMInterrupts { &self.inner.interrupts } @@ -1128,7 +1128,7 @@ impl Store { pub fn interrupt_handle(&self) -> Result { if self.engine().config().tunables.interruptable { Ok(InterruptHandle { - interrupts: self.interrupts().clone(), + interrupts: self.inner.interrupts.clone(), }) } else { bail!("interrupts aren't enabled for this `Store`") diff --git a/crates/wasmtime/src/trampoline/create_handle.rs b/crates/wasmtime/src/trampoline/create_handle.rs index e876240908..02f391bb78 100644 --- a/crates/wasmtime/src/trampoline/create_handle.rs +++ b/crates/wasmtime/src/trampoline/create_handle.rs @@ -42,7 +42,7 @@ pub(crate) fn create_handle( store.memory_creator(), signatures.into_boxed_slice(), state, - store.interrupts().clone(), + store.interrupts(), store.externref_activations_table() as *const VMExternRefActivationsTable as *mut _, store.stack_map_registry() as *const StackMapRegistry as *mut _, )?;