Skip to content

Commit 79c99d7

Browse files
alexcrichtoncfallin
authored andcommitted
Don't store Arc<VMInterrupts> 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.
1 parent 1024068 commit 79c99d7

6 files changed

Lines changed: 9 additions & 14 deletions

File tree

crates/jit/src/instantiate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl CompiledModule {
250250
imports: Imports<'_>,
251251
signature_registry: &mut SignatureRegistry,
252252
mem_creator: Option<&dyn RuntimeMemoryCreator>,
253-
interrupts: Arc<VMInterrupts>,
253+
interrupts: *const VMInterrupts,
254254
host_state: Box<dyn Any>,
255255
externref_activations_table: *mut VMExternRefActivationsTable,
256256
stack_map_registry: *mut StackMapRegistry,

crates/runtime/src/instance.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ pub(crate) struct Instance {
6868
/// Hosts can store arbitrary per-instance information here.
6969
host_state: Box<dyn Any>,
7070

71-
/// Externally allocated data indicating how this instance will be
72-
/// interrupted.
73-
pub(crate) interrupts: Arc<VMInterrupts>,
74-
7571
/// Additional context used by compiled wasm code. This field is last, and
7672
/// represents a dynamically-sized array that extends beyond the nominal
7773
/// end of the struct (similar to a flexible array member).
@@ -824,7 +820,7 @@ impl InstanceHandle {
824820
mem_creator: Option<&dyn RuntimeMemoryCreator>,
825821
vmshared_signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
826822
host_state: Box<dyn Any>,
827-
interrupts: Arc<VMInterrupts>,
823+
interrupts: *const VMInterrupts,
828824
externref_activations_table: *mut VMExternRefActivationsTable,
829825
stack_map_registry: *mut StackMapRegistry,
830826
) -> Result<Self, InstantiationError> {
@@ -863,7 +859,6 @@ impl InstanceHandle {
863859
passive_data,
864860
trampolines,
865861
host_state,
866-
interrupts,
867862
vmctx: VMContext {},
868863
};
869864
let layout = instance.alloc_layout();
@@ -930,7 +925,7 @@ impl InstanceHandle {
930925
instance.builtin_functions_ptr() as *mut VMBuiltinFunctionsArray,
931926
VMBuiltinFunctionsArray::initialized(),
932927
);
933-
*instance.interrupts() = &*instance.interrupts;
928+
*instance.interrupts() = interrupts;
934929
*instance.externref_activations_table() = externref_activations_table;
935930
*instance.stack_map_registry() = stack_map_registry;
936931

crates/runtime/src/traphandlers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ impl<'a> CallThreadState<'a> {
453453
UnwindReason::JitTrap { backtrace, pc } => {
454454
debug_assert_eq!(ret, 0);
455455
let maybe_interrupted = unsafe {
456-
(*self.vmctx).instance().interrupts.stack_limit.load(SeqCst)
457-
== wasmtime_environ::INTERRUPTED
456+
let interrupts = (*self.vmctx).instance().interrupts();
457+
(**interrupts).stack_limit.load(SeqCst) == wasmtime_environ::INTERRUPTED
458458
};
459459
Err(Trap::Jit {
460460
pc,

crates/wasmtime/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn instantiate(
2222
imports,
2323
&mut store.signatures_mut(),
2424
config.memory_creator.as_ref().map(|a| a as _),
25-
store.interrupts().clone(),
25+
store.interrupts(),
2626
host,
2727
store.externref_activations_table() as *const VMExternRefActivationsTable as *mut _,
2828
store.stack_map_registry() as *const StackMapRegistry as *mut _,

crates/wasmtime/src/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ impl Store {
10301030
self.inner.signal_handler.borrow_mut()
10311031
}
10321032

1033-
pub(crate) fn interrupts(&self) -> &Arc<VMInterrupts> {
1033+
pub(crate) fn interrupts(&self) -> &VMInterrupts {
10341034
&self.inner.interrupts
10351035
}
10361036

@@ -1128,7 +1128,7 @@ impl Store {
11281128
pub fn interrupt_handle(&self) -> Result<InterruptHandle> {
11291129
if self.engine().config().tunables.interruptable {
11301130
Ok(InterruptHandle {
1131-
interrupts: self.interrupts().clone(),
1131+
interrupts: self.inner.interrupts.clone(),
11321132
})
11331133
} else {
11341134
bail!("interrupts aren't enabled for this `Store`")

crates/wasmtime/src/trampoline/create_handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) fn create_handle(
4242
store.memory_creator(),
4343
signatures.into_boxed_slice(),
4444
state,
45-
store.interrupts().clone(),
45+
store.interrupts(),
4646
store.externref_activations_table() as *const VMExternRefActivationsTable as *mut _,
4747
store.stack_map_registry() as *const StackMapRegistry as *mut _,
4848
)?;

0 commit comments

Comments
 (0)