Remove an Arc holding module code from InstanceHandle (#2374)
We've generally moved to a model where `InstanceHandle` doesn't hold ownership of its internals, instead relying on the caller to manage that. This removes an allocation on the `Func::wrap` path but otherwise shouldn't have much impact.
This commit is contained in:
@@ -246,7 +246,6 @@ impl CompiledModule {
|
|||||||
) -> Result<InstanceHandle, InstantiationError> {
|
) -> Result<InstanceHandle, InstantiationError> {
|
||||||
InstanceHandle::new(
|
InstanceHandle::new(
|
||||||
self.module.clone(),
|
self.module.clone(),
|
||||||
self.code.clone(),
|
|
||||||
&self.finished_functions.0,
|
&self.finished_functions.0,
|
||||||
imports,
|
imports,
|
||||||
mem_creator,
|
mem_creator,
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ pub(crate) struct Instance {
|
|||||||
/// The `Module` this `Instance` was instantiated from.
|
/// The `Module` this `Instance` was instantiated from.
|
||||||
module: Arc<Module>,
|
module: Arc<Module>,
|
||||||
|
|
||||||
/// The module's JIT code (if exists).
|
|
||||||
code: Arc<dyn Any>,
|
|
||||||
|
|
||||||
/// Offsets in the `vmctx` region.
|
/// Offsets in the `vmctx` region.
|
||||||
offsets: VMOffsets,
|
offsets: VMOffsets,
|
||||||
|
|
||||||
@@ -814,7 +811,6 @@ impl InstanceHandle {
|
|||||||
/// instance.
|
/// instance.
|
||||||
pub unsafe fn new(
|
pub unsafe fn new(
|
||||||
module: Arc<Module>,
|
module: Arc<Module>,
|
||||||
code: Arc<dyn Any>,
|
|
||||||
finished_functions: &PrimaryMap<DefinedFuncIndex, *mut [VMFunctionBody]>,
|
finished_functions: &PrimaryMap<DefinedFuncIndex, *mut [VMFunctionBody]>,
|
||||||
imports: Imports,
|
imports: Imports,
|
||||||
mem_creator: Option<&dyn RuntimeMemoryCreator>,
|
mem_creator: Option<&dyn RuntimeMemoryCreator>,
|
||||||
@@ -851,7 +847,6 @@ impl InstanceHandle {
|
|||||||
let handle = {
|
let handle = {
|
||||||
let instance = Instance {
|
let instance = Instance {
|
||||||
module,
|
module,
|
||||||
code,
|
|
||||||
offsets,
|
offsets,
|
||||||
memories,
|
memories,
|
||||||
tables,
|
tables,
|
||||||
|
|||||||
@@ -98,7 +98,11 @@ fn instantiate(
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
pub(crate) handle: StoreInstanceHandle,
|
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,
|
module: Module,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +174,6 @@ impl Instance {
|
|||||||
|
|
||||||
Ok(Instance {
|
Ok(Instance {
|
||||||
handle,
|
handle,
|
||||||
store: store.clone(),
|
|
||||||
module: module.clone(),
|
module: module.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -180,7 +183,7 @@ impl Instance {
|
|||||||
/// This is the [`Store`] that generally serves as a sort of global cache
|
/// This is the [`Store`] that generally serves as a sort of global cache
|
||||||
/// for various instance-related things.
|
/// for various instance-related things.
|
||||||
pub fn store(&self) -> &Store {
|
pub fn store(&self) -> &Store {
|
||||||
&self.store
|
&self.handle.store
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the list of exported items from this [`Instance`].
|
/// Returns the list of exported items from this [`Instance`].
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ pub(crate) fn create_handle(
|
|||||||
unsafe {
|
unsafe {
|
||||||
let handle = InstanceHandle::new(
|
let handle = InstanceHandle::new(
|
||||||
module,
|
module,
|
||||||
Arc::new(()),
|
|
||||||
&finished_functions,
|
&finished_functions,
|
||||||
imports,
|
imports,
|
||||||
store.memory_creator(),
|
store.memory_creator(),
|
||||||
|
|||||||
Reference in New Issue
Block a user