diff --git a/crates/jit/src/instantiate.rs b/crates/jit/src/instantiate.rs index 7807c80c39..0d27918f51 100644 --- a/crates/jit/src/instantiate.rs +++ b/crates/jit/src/instantiate.rs @@ -246,7 +246,6 @@ impl CompiledModule { ) -> Result { InstanceHandle::new( self.module.clone(), - self.code.clone(), &self.finished_functions.0, imports, mem_creator, diff --git a/crates/runtime/src/instance.rs b/crates/runtime/src/instance.rs index ad79721760..87e7c326fe 100644 --- a/crates/runtime/src/instance.rs +++ b/crates/runtime/src/instance.rs @@ -41,9 +41,6 @@ pub(crate) struct Instance { /// The `Module` this `Instance` was instantiated from. module: Arc, - /// The module's JIT code (if exists). - code: Arc, - /// Offsets in the `vmctx` region. offsets: VMOffsets, @@ -814,7 +811,6 @@ impl InstanceHandle { /// instance. pub unsafe fn new( module: Arc, - code: Arc, finished_functions: &PrimaryMap, imports: Imports, mem_creator: Option<&dyn RuntimeMemoryCreator>, @@ -851,7 +847,6 @@ impl InstanceHandle { let handle = { let instance = Instance { module, - code, offsets, memories, tables, diff --git a/crates/wasmtime/src/instance.rs b/crates/wasmtime/src/instance.rs index e2164153ea..a686e91672 100644 --- a/crates/wasmtime/src/instance.rs +++ b/crates/wasmtime/src/instance.rs @@ -98,7 +98,11 @@ fn instantiate( #[derive(Clone)] pub struct Instance { pub(crate) handle: StoreInstanceHandle, - store: Store, + // Note that this is required to keep the module's code memory alive while + // we have a handle to this `Instance`. We may eventually want to shrink + // this to only hold onto the bare minimum each instance needs to allow + // deallocating some `Module` resources early, but until then we just hold + // on to everything. module: Module, } @@ -170,7 +174,6 @@ impl Instance { Ok(Instance { handle, - store: store.clone(), module: module.clone(), }) } @@ -180,7 +183,7 @@ impl Instance { /// This is the [`Store`] that generally serves as a sort of global cache /// for various instance-related things. pub fn store(&self) -> &Store { - &self.store + &self.handle.store } /// Returns the list of exported items from this [`Instance`]. diff --git a/crates/wasmtime/src/trampoline/create_handle.rs b/crates/wasmtime/src/trampoline/create_handle.rs index 15d1d58460..874431861c 100644 --- a/crates/wasmtime/src/trampoline/create_handle.rs +++ b/crates/wasmtime/src/trampoline/create_handle.rs @@ -28,7 +28,6 @@ pub(crate) fn create_handle( unsafe { let handle = InstanceHandle::new( module, - Arc::new(()), &finished_functions, imports, store.memory_creator(),