mirror of
https://github.com/mii443/wasmer.git
synced 2025-09-04 08:29:16 +00:00
Optimized ModuleInfo usage
This commit is contained in:
@ -8,6 +8,7 @@ use crate::EngineInner;
|
||||
use crate::Features;
|
||||
use crate::{ModuleEnvironment, ModuleMiddlewareChain};
|
||||
use enumset::EnumSet;
|
||||
use std::sync::Arc;
|
||||
use wasmer_types::entity::PrimaryMap;
|
||||
#[cfg(feature = "compiler")]
|
||||
use wasmer_types::CompileModuleInfo;
|
||||
@ -57,7 +58,7 @@ impl ArtifactBuild {
|
||||
middlewares.apply_on_module_info(&mut module);
|
||||
|
||||
let compile_info = CompileModuleInfo {
|
||||
module,
|
||||
module: Arc::new(module),
|
||||
features,
|
||||
memory_styles,
|
||||
table_styles,
|
||||
@ -195,10 +196,21 @@ impl ArtifactBuild {
|
||||
}
|
||||
|
||||
impl ArtifactCreate for ArtifactBuild {
|
||||
fn create_module_info(&self) -> ModuleInfo {
|
||||
fn create_module_info(&self) -> Arc<ModuleInfo> {
|
||||
self.serializable.compile_info.module.clone()
|
||||
}
|
||||
|
||||
fn set_module_info_name(&mut self, name: String) -> bool {
|
||||
Arc::get_mut(&mut self.serializable.compile_info.module).map_or(false, |mut module_info| {
|
||||
module_info.name = Some(name.to_string());
|
||||
true
|
||||
})
|
||||
}
|
||||
|
||||
fn module_info(&self) -> &ModuleInfo {
|
||||
&self.serializable.compile_info.module
|
||||
}
|
||||
|
||||
fn features(&self) -> &Features {
|
||||
&self.serializable.compile_info.features
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ impl Artifact {
|
||||
allocated: None,
|
||||
});
|
||||
}
|
||||
let module_info = artifact.create_module_info();
|
||||
let module_info = artifact.module_info();
|
||||
let (
|
||||
finished_functions,
|
||||
finished_function_call_trampolines,
|
||||
@ -237,10 +237,18 @@ impl Artifact {
|
||||
}
|
||||
|
||||
impl ArtifactCreate for Artifact {
|
||||
fn create_module_info(&self) -> ModuleInfo {
|
||||
fn set_module_info_name(&mut self, name: String) -> bool {
|
||||
self.artifact.set_module_info_name(name)
|
||||
}
|
||||
|
||||
fn create_module_info(&self) -> Arc<ModuleInfo> {
|
||||
self.artifact.create_module_info()
|
||||
}
|
||||
|
||||
fn module_info(&self) -> &ModuleInfo {
|
||||
self.artifact.module_info()
|
||||
}
|
||||
|
||||
fn features(&self) -> &Features {
|
||||
self.artifact.features()
|
||||
}
|
||||
@ -381,7 +389,7 @@ impl Artifact {
|
||||
|
||||
self.preinstantiate()?;
|
||||
|
||||
let module = Arc::new(self.create_module_info());
|
||||
let module = self.create_module_info();
|
||||
let imports = resolve_imports(
|
||||
&module,
|
||||
imports,
|
||||
@ -499,7 +507,7 @@ impl Artifact {
|
||||
.collect();
|
||||
|
||||
let compile_info = CompileModuleInfo {
|
||||
module,
|
||||
module: Arc::new(module),
|
||||
features: features.clone(),
|
||||
memory_styles,
|
||||
table_styles,
|
||||
@ -576,7 +584,7 @@ impl Artifact {
|
||||
features: &Features,
|
||||
) -> Result<
|
||||
(
|
||||
ModuleInfo,
|
||||
Arc<ModuleInfo>,
|
||||
Object<'data>,
|
||||
usize,
|
||||
Box<dyn wasmer_types::SymbolRegistry>,
|
||||
|
@ -13,7 +13,7 @@
|
||||
//! ```
|
||||
use std::cmp;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use wasmer_types::entity::{BoxedSlice, EntityRef, PrimaryMap};
|
||||
use wasmer_types::{CompiledFunctionFrameInfo, SourceLoc, TrapInformation};
|
||||
use wasmer_types::{LocalFunctionIndex, ModuleInfo};
|
||||
@ -54,7 +54,7 @@ pub struct GlobalFrameInfoRegistration {
|
||||
struct ModuleInfoFrameInfo {
|
||||
start: usize,
|
||||
functions: BTreeMap<usize, FunctionInfo>,
|
||||
module: ModuleInfo,
|
||||
module: Arc<ModuleInfo>,
|
||||
frame_infos: PrimaryMap<LocalFunctionIndex, CompiledFunctionFrameInfo>,
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ pub struct FunctionExtent {
|
||||
/// then `None` will be returned. Otherwise the returned object, when
|
||||
/// dropped, will be used to unregister all name information from this map.
|
||||
pub fn register(
|
||||
module: ModuleInfo,
|
||||
module: Arc<ModuleInfo>,
|
||||
finished_functions: &BoxedSlice<LocalFunctionIndex, FunctionExtent>,
|
||||
frame_infos: PrimaryMap<LocalFunctionIndex, CompiledFunctionFrameInfo>,
|
||||
) -> Option<GlobalFrameInfoRegistration> {
|
||||
|
@ -3,6 +3,7 @@
|
||||
use crate::Features;
|
||||
use enumset::EnumSet;
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
use wasmer_types::entity::PrimaryMap;
|
||||
use wasmer_types::SerializeError;
|
||||
use wasmer_types::{
|
||||
@ -17,7 +18,13 @@ use wasmer_types::{
|
||||
/// module at runtime, such as [`ModuleInfo`] and [`Features`].
|
||||
pub trait ArtifactCreate: Send + Sync + Upcastable {
|
||||
/// Create a `ModuleInfo` for instantiation
|
||||
fn create_module_info(&self) -> ModuleInfo;
|
||||
fn create_module_info(&self) -> Arc<ModuleInfo>;
|
||||
|
||||
/// Sets the `ModuleInfo` name
|
||||
fn set_module_info_name(&mut self, name: String) -> bool;
|
||||
|
||||
/// Returns the `ModuleInfo` for instantiation
|
||||
fn module_info(&self) -> &ModuleInfo;
|
||||
|
||||
/// Returns the features for this Artifact
|
||||
fn features(&self) -> &Features;
|
||||
|
Reference in New Issue
Block a user