From b0ed1c96b3704a0f59c46556eff2ab5e410e92a4 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 22 Jun 2021 07:03:20 -0700 Subject: [PATCH 1/3] Remove FuncRef registry - WIP --- lib/api/src/externals/function.rs | 15 ++++---- lib/api/src/types.rs | 4 +-- lib/engine-dylib/src/artifact.rs | 11 ++---- lib/engine-dylib/src/engine.rs | 21 +---------- lib/engine-staticlib/src/artifact.rs | 11 +----- lib/engine-staticlib/src/engine.rs | 21 +---------- lib/engine-universal/src/artifact.rs | 9 +---- lib/engine-universal/src/engine.rs | 20 ++--------- lib/engine/src/artifact.rs | 8 ++--- lib/engine/src/engine.rs | 5 +-- lib/vm/src/func_data_registry.rs | 50 -------------------------- lib/vm/src/instance/mod.rs | 26 ++++++-------- lib/vm/src/lib.rs | 2 +- tests/lib/engine-dummy/src/artifact.rs | 10 ++---- tests/lib/engine-dummy/src/engine.rs | 16 +-------- 15 files changed, 34 insertions(+), 195 deletions(-) diff --git a/lib/api/src/externals/function.rs b/lib/api/src/externals/function.rs index 26061482f33..18a27eb317a 100644 --- a/lib/api/src/externals/function.rs +++ b/lib/api/src/externals/function.rs @@ -16,8 +16,8 @@ use std::sync::Arc; use wasmer_engine::{Export, ExportFunction, ExportFunctionMetadata}; use wasmer_vm::{ raise_user_trap, resume_panic, wasmer_call_trampoline, ImportInitializerFuncPtr, - VMCallerCheckedAnyfunc, VMDynamicFunctionContext, VMFuncRef, VMFunction, VMFunctionBody, - VMFunctionEnvironment, VMFunctionKind, VMTrampoline, + VMDynamicFunctionContext, VMFuncRef, VMFunction, VMFunctionBody, VMFunctionEnvironment, + VMFunctionKind, VMTrampoline, }; /// A WebAssembly `function` instance. @@ -538,15 +538,12 @@ impl Function { } } - pub(crate) fn vm_funcref(&self) -> VMFuncRef { + /*pub(crate) fn vm_funcref(&self) -> VMFuncRef { let engine = self.store.engine(); let vmsignature = engine.register_signature(&self.exported.vm_function.signature); - engine.register_function_metadata(VMCallerCheckedAnyfunc { - func_ptr: self.exported.vm_function.address, - type_index: vmsignature, - vmctx: self.exported.vm_function.vmctx, - }) - } + // with the new changes this method is no longer possible... it should be though + // so TODO: figure out how to make this work + }*/ /// Transform this WebAssembly function into a function with the /// native ABI. See [`NativeFunc`] to learn more. diff --git a/lib/api/src/types.rs b/lib/api/src/types.rs index 70c7a196173..4cf5496c629 100644 --- a/lib/api/src/types.rs +++ b/lib/api/src/types.rs @@ -53,7 +53,7 @@ impl ValFuncRef for Val { } Ok(match self { Self::FuncRef(None) => VMFuncRef::null(), - Self::FuncRef(Some(f)) => f.vm_funcref(), + Self::FuncRef(Some(_)) => VMFuncRef::null(), //f.vm_funcref(), _ => return Err(RuntimeError::new("val is not func ref")), }) } @@ -100,7 +100,7 @@ impl ValFuncRef for Val { wasmer_vm::TableElement::ExternRef(extern_ref.clone().into()) } Self::FuncRef(None) => wasmer_vm::TableElement::FuncRef(VMFuncRef::null()), - Self::FuncRef(Some(f)) => wasmer_vm::TableElement::FuncRef(f.vm_funcref()), + Self::FuncRef(Some(f)) => wasmer_vm::TableElement::FuncRef(VMFuncRef::null()), //wasmer_vm::TableElement::FuncRef(f.vm_funcref()), _ => return Err(RuntimeError::new("val is not reference")), }) } diff --git a/lib/engine-dylib/src/artifact.rs b/lib/engine-dylib/src/artifact.rs index e15220c8921..4ee0867eb5c 100644 --- a/lib/engine-dylib/src/artifact.rs +++ b/lib/engine-dylib/src/artifact.rs @@ -40,8 +40,8 @@ use wasmer_types::{ TableIndex, }; use wasmer_vm::{ - FuncDataRegistry, FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMFunctionBody, - VMSharedSignatureIndex, VMTrampoline, + FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMFunctionBody, VMSharedSignatureIndex, + VMTrampoline, }; /// A compiled Wasm module, ready to be instantiated. @@ -53,7 +53,6 @@ pub struct DylibArtifact { #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, - func_data_registry: Arc, signatures: BoxedSlice, frame_info_registration: Mutex>, } @@ -377,7 +376,6 @@ impl DylibArtifact { .into_boxed_slice(), finished_dynamic_function_trampolines: finished_dynamic_function_trampolines .into_boxed_slice(), - func_data_registry: Arc::new(FuncDataRegistry::new()), signatures: signatures.into_boxed_slice(), frame_info_registration: Mutex::new(None), }) @@ -482,7 +480,6 @@ impl DylibArtifact { .into_boxed_slice(), finished_dynamic_function_trampolines: finished_dynamic_function_trampolines .into_boxed_slice(), - func_data_registry: engine_inner.func_data().clone(), signatures: signatures.into_boxed_slice(), frame_info_registration: Mutex::new(None), }) @@ -761,10 +758,6 @@ impl Artifact for DylibArtifact { &self.signatures } - fn func_data_registry(&self) -> &FuncDataRegistry { - &self.func_data_registry - } - fn preinstantiate(&self) -> Result<(), InstantiationError> { Ok(()) } diff --git a/lib/engine-dylib/src/engine.rs b/lib/engine-dylib/src/engine.rs index 7825ae18987..a3238f38d40 100644 --- a/lib/engine-dylib/src/engine.rs +++ b/lib/engine-dylib/src/engine.rs @@ -13,9 +13,7 @@ use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables}; #[cfg(feature = "compiler")] use wasmer_types::Features; use wasmer_types::FunctionType; -use wasmer_vm::{ - FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex, -}; +use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex}; /// A WebAssembly `Dylib` Engine. #[derive(Clone, MemoryUsage)] @@ -37,7 +35,6 @@ impl DylibEngine { inner: Arc::new(Mutex::new(DylibEngineInner { compiler: Some(compiler), signatures: SignatureRegistry::new(), - func_data: Arc::new(FuncDataRegistry::new()), prefixer: None, features, is_cross_compiling, @@ -70,7 +67,6 @@ impl DylibEngine { #[cfg(feature = "compiler")] features: Features::default(), signatures: SignatureRegistry::new(), - func_data: Arc::new(FuncDataRegistry::new()), prefixer: None, is_cross_compiling: false, linker: Linker::None, @@ -120,11 +116,6 @@ impl Engine for DylibEngine { compiler.signatures().register(func_type) } - fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef { - let compiler = self.inner(); - compiler.func_data().register(func_data) - } - /// Lookup a signature fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option { let compiler = self.inner(); @@ -243,11 +234,6 @@ pub struct DylibEngineInner { /// performantly. signatures: SignatureRegistry, - /// The backing storage of `VMFuncRef`s. This centralized store ensures that 2 - /// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`. - /// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped. - func_data: Arc, - /// The prefixer returns the a String to prefix each of /// the functions in the shared object generated by the `DylibEngine`, /// so we can assure no collisions. @@ -311,11 +297,6 @@ impl DylibEngineInner { &self.signatures } - /// Shared func metadata registry. - pub(crate) fn func_data(&self) -> &Arc { - &self.func_data - } - pub(crate) fn is_cross_compiling(&self) -> bool { self.is_cross_compiling } diff --git a/lib/engine-staticlib/src/artifact.rs b/lib/engine-staticlib/src/artifact.rs index 0a7d03350b9..24a7bdeee41 100644 --- a/lib/engine-staticlib/src/artifact.rs +++ b/lib/engine-staticlib/src/artifact.rs @@ -28,8 +28,7 @@ use wasmer_types::{ TableIndex, }; use wasmer_vm::{ - FuncDataRegistry, FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMSharedSignatureIndex, - VMTrampoline, + FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMSharedSignatureIndex, VMTrampoline, }; /// A compiled wasm module, ready to be instantiated. @@ -42,7 +41,6 @@ pub struct StaticlibArtifact { finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, - func_data_registry: Arc, /// Length of the serialized metadata metadata_length: usize, symbol_registry: ModuleMetadataSymbolRegistry, @@ -292,7 +290,6 @@ impl StaticlibArtifact { finished_dynamic_function_trampolines: finished_dynamic_function_trampolines .into_boxed_slice(), signatures: signatures.into_boxed_slice(), - func_data_registry: engine_inner.func_data().clone(), metadata_length, symbol_registry, }) @@ -332,7 +329,6 @@ impl StaticlibArtifact { let engine_inner = engine.inner(); let signature_registry = engine_inner.signatures(); - let func_data_registry = engine_inner.func_data().clone(); let mut sig_map: BTreeMap = BTreeMap::new(); let num_imported_functions = metadata.compile_info.module.num_imported_functions; @@ -412,7 +408,6 @@ impl StaticlibArtifact { finished_dynamic_function_trampolines: finished_dynamic_function_trampolines .into_boxed_slice(), signatures: signatures.into_boxed_slice(), - func_data_registry, metadata_length: 0, symbol_registry, }) @@ -478,10 +473,6 @@ impl Artifact for StaticlibArtifact { &self.signatures } - fn func_data_registry(&self) -> &FuncDataRegistry { - &self.func_data_registry - } - fn preinstantiate(&self) -> Result<(), InstantiationError> { Ok(()) } diff --git a/lib/engine-staticlib/src/engine.rs b/lib/engine-staticlib/src/engine.rs index a0ee4c4d65a..4abd532ac65 100644 --- a/lib/engine-staticlib/src/engine.rs +++ b/lib/engine-staticlib/src/engine.rs @@ -10,9 +10,7 @@ use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables}; #[cfg(feature = "compiler")] use wasmer_types::Features; use wasmer_types::FunctionType; -use wasmer_vm::{ - FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex, -}; +use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex}; /// A WebAssembly `Staticlib` Engine. #[derive(Clone, MemoryUsage)] @@ -31,7 +29,6 @@ impl StaticlibEngine { inner: Arc::new(Mutex::new(StaticlibEngineInner { compiler: Some(compiler), signatures: SignatureRegistry::new(), - func_data: Arc::new(FuncDataRegistry::new()), prefixer: None, features, })), @@ -61,7 +58,6 @@ impl StaticlibEngine { #[cfg(feature = "compiler")] features: Features::default(), signatures: SignatureRegistry::new(), - func_data: Arc::new(FuncDataRegistry::new()), prefixer: None, })), target: Arc::new(Target::default()), @@ -109,11 +105,6 @@ impl Engine for StaticlibEngine { compiler.signatures().register(func_type) } - fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef { - let compiler = self.inner(); - compiler.func_data().register(func_data) - } - /// Lookup a signature fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option { let compiler = self.inner(); @@ -192,11 +183,6 @@ pub struct StaticlibEngineInner { /// performantly. signatures: SignatureRegistry, - /// The backing storage of `VMFuncRef`s. This centralized store ensures that 2 - /// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`. - /// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped. - func_data: Arc, - /// The prefixer returns the a String to prefix each of the /// functions in the static object generated by the /// `StaticlibEngine`, so we can assure no collisions. @@ -249,9 +235,4 @@ impl StaticlibEngineInner { pub fn signatures(&self) -> &SignatureRegistry { &self.signatures } - - /// Shared func metadata registry. - pub(crate) fn func_data(&self) -> &Arc { - &self.func_data - } } diff --git a/lib/engine-universal/src/artifact.rs b/lib/engine-universal/src/artifact.rs index d4784a958c2..cb776cbdde6 100644 --- a/lib/engine-universal/src/artifact.rs +++ b/lib/engine-universal/src/artifact.rs @@ -23,8 +23,7 @@ use wasmer_types::{ TableIndex, }; use wasmer_vm::{ - FuncDataRegistry, FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMSharedSignatureIndex, - VMTrampoline, + FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMSharedSignatureIndex, VMTrampoline, }; const SERIALIZED_METADATA_LENGTH_OFFSET: usize = 22; @@ -39,7 +38,6 @@ pub struct UniversalArtifact { finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, - func_data_registry: Arc, frame_info_registration: Mutex>, finished_function_lengths: BoxedSlice, } @@ -241,7 +239,6 @@ impl UniversalArtifact { let finished_dynamic_function_trampolines = finished_dynamic_function_trampolines.into_boxed_slice(); let signatures = signatures.into_boxed_slice(); - let func_data_registry = inner_engine.func_data().clone(); Ok(Self { serializable, @@ -251,7 +248,6 @@ impl UniversalArtifact { signatures, frame_info_registration: Mutex::new(None), finished_function_lengths, - func_data_registry, }) } @@ -332,9 +328,6 @@ impl Artifact for UniversalArtifact { &self.signatures } - fn func_data_registry(&self) -> &FuncDataRegistry { - &self.func_data_registry - } fn serialize(&self) -> Result, SerializeError> { // Prepend the header. let mut serialized = Self::MAGIC_HEADER.to_vec(); diff --git a/lib/engine-universal/src/engine.rs b/lib/engine-universal/src/engine.rs index 205f833ce1a..7ecd79c4e55 100644 --- a/lib/engine-universal/src/engine.rs +++ b/lib/engine-universal/src/engine.rs @@ -13,8 +13,8 @@ use wasmer_types::entity::PrimaryMap; use wasmer_types::Features; use wasmer_types::{FunctionIndex, FunctionType, LocalFunctionIndex, SignatureIndex}; use wasmer_vm::{ - FuncDataRegistry, FunctionBodyPtr, ModuleInfo, SectionBodyPtr, SignatureRegistry, - VMCallerCheckedAnyfunc, VMFuncRef, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline, + FunctionBodyPtr, ModuleInfo, SectionBodyPtr, SignatureRegistry, VMFunctionBody, + VMSharedSignatureIndex, VMTrampoline, }; /// A WebAssembly `Universal` Engine. @@ -35,7 +35,6 @@ impl UniversalEngine { compiler: Some(compiler), code_memory: vec![], signatures: SignatureRegistry::new(), - func_data: Arc::new(FuncDataRegistry::new()), features, })), target: Arc::new(target), @@ -63,7 +62,6 @@ impl UniversalEngine { compiler: None, code_memory: vec![], signatures: SignatureRegistry::new(), - func_data: Arc::new(FuncDataRegistry::new()), features: Features::default(), })), target: Arc::new(Target::default()), @@ -92,11 +90,6 @@ impl Engine for UniversalEngine { compiler.signatures().register(func_type) } - fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef { - let compiler = self.inner(); - compiler.func_data().register(func_data) - } - /// Lookup a signature fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option { let compiler = self.inner(); @@ -159,10 +152,6 @@ pub struct UniversalEngineInner { /// The signature registry is used mainly to operate with trampolines /// performantly. signatures: SignatureRegistry, - /// The backing storage of `VMFuncRef`s. This centralized store ensures that 2 - /// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`. - /// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped. - func_data: Arc, } impl UniversalEngineInner { @@ -310,9 +299,4 @@ impl UniversalEngineInner { pub fn signatures(&self) -> &SignatureRegistry { &self.signatures } - - /// Shared func metadata registry. - pub(crate) fn func_data(&self) -> &Arc { - &self.func_data - } } diff --git a/lib/engine/src/artifact.rs b/lib/engine/src/artifact.rs index 00146067c3d..591f7a2931a 100644 --- a/lib/engine/src/artifact.rs +++ b/lib/engine/src/artifact.rs @@ -13,8 +13,8 @@ use wasmer_types::{ SignatureIndex, TableIndex, }; use wasmer_vm::{ - FuncDataRegistry, FunctionBodyPtr, InstanceAllocator, InstanceHandle, MemoryStyle, ModuleInfo, - TableStyle, TrapHandler, VMSharedSignatureIndex, VMTrampoline, + FunctionBodyPtr, InstanceAllocator, InstanceHandle, MemoryStyle, ModuleInfo, TableStyle, + TrapHandler, VMSharedSignatureIndex, VMTrampoline, }; /// An `Artifact` is the product that the `Engine` @@ -67,9 +67,6 @@ pub trait Artifact: Send + Sync + Upcastable + MemoryUsage { /// Returns the associated VM signatures for this `Artifact`. fn signatures(&self) -> &BoxedSlice; - /// Get the func data registry - fn func_data_registry(&self) -> &FuncDataRegistry; - /// Serializes an artifact into bytes fn serialize(&self) -> Result, SerializeError>; @@ -146,7 +143,6 @@ pub trait Artifact: Send + Sync + Upcastable + MemoryUsage { finished_globals, imports, self.signatures().clone(), - self.func_data_registry(), host_state, import_function_envs, ) diff --git a/lib/engine/src/engine.rs b/lib/engine/src/engine.rs index fb79e235f57..1210395b2b4 100644 --- a/lib/engine/src/engine.rs +++ b/lib/engine/src/engine.rs @@ -9,7 +9,7 @@ use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::Arc; use wasmer_compiler::{CompileError, Target}; use wasmer_types::FunctionType; -use wasmer_vm::{VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex}; +use wasmer_vm::VMSharedSignatureIndex; /// A unimplemented Wasmer `Engine`. /// @@ -24,9 +24,6 @@ pub trait Engine: MemoryUsage { /// Register a signature fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex; - /// Register a function's data. - fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef; - /// Lookup a signature fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option; diff --git a/lib/vm/src/func_data_registry.rs b/lib/vm/src/func_data_registry.rs index 7fc9fc24d09..fa7d4fc269b 100644 --- a/lib/vm/src/func_data_registry.rs +++ b/lib/vm/src/func_data_registry.rs @@ -6,23 +6,6 @@ use crate::vmcontext::VMCallerCheckedAnyfunc; use loupe::MemoryUsage; -use std::collections::HashMap; -use std::sync::Mutex; - -/// The registry that holds the values that `VMFuncRef`s point to. -#[derive(Debug, MemoryUsage)] -pub struct FuncDataRegistry { - // This structure is stored in an `Engine` and is intended to be shared - // across many instances. Ideally instances can themselves be sent across - // threads, and ideally we can compile across many threads. As a result we - // use interior mutability here with a lock to avoid having callers to - // externally synchronize calls to compilation. - inner: Mutex, -} - -// We use raw pointers but the data never moves, so it's not a problem -unsafe impl Send for FuncDataRegistry {} -unsafe impl Sync for FuncDataRegistry {} /// A function reference. A single word that points to metadata about a function. #[repr(transparent)] @@ -86,36 +69,3 @@ impl std::ops::DerefMut for VMFuncRef { // TODO: update docs unsafe impl Send for VMFuncRef {} unsafe impl Sync for VMFuncRef {} - -#[derive(Debug, Default, MemoryUsage)] -struct Inner { - func_data: Vec>, - anyfunc_to_index: HashMap, -} - -impl FuncDataRegistry { - /// Create a new `FuncDataRegistry`. - pub fn new() -> Self { - Self { - inner: Default::default(), - } - } - - /// Register a signature and return its unique index. - pub fn register(&self, anyfunc: VMCallerCheckedAnyfunc) -> VMFuncRef { - let mut inner = self.inner.lock().unwrap(); - if let Some(&idx) = inner.anyfunc_to_index.get(&anyfunc) { - let data: &Box<_> = &inner.func_data[idx]; - let inner_ptr: &VMCallerCheckedAnyfunc = &*data; - VMFuncRef(inner_ptr) - } else { - let idx = inner.func_data.len(); - inner.func_data.push(Box::new(anyfunc.clone())); - inner.anyfunc_to_index.insert(anyfunc, idx); - - let data: &Box<_> = &inner.func_data[idx]; - let inner_ptr: &VMCallerCheckedAnyfunc = &*data; - VMFuncRef(inner_ptr) - } - } -} diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index 366339f9fdf..7272ff84829 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -14,7 +14,7 @@ pub use allocator::InstanceAllocator; pub use r#ref::{InstanceRef, WeakInstanceRef, WeakOrStrongInstanceRef}; use crate::export::VMExtern; -use crate::func_data_registry::{FuncDataRegistry, VMFuncRef}; +use crate::func_data_registry::VMFuncRef; use crate::global::Global; use crate::imports::Imports; use crate::memory::{Memory, MemoryError}; @@ -92,8 +92,8 @@ pub(crate) struct Instance { /// get removed. A missing entry is considered equivalent to an empty slice. passive_data: RefCell>>, - /// mapping of function indices to their func ref backing data. - funcrefs: BoxedSlice, + /// TODO: document this + funcref_backings: BoxedSlice>, /// Hosts can store arbitrary per-instance information here. host_state: Box, @@ -634,7 +634,8 @@ impl Instance { if index == FunctionIndex::reserved_value() { return VMFuncRef::null(); } - self.funcrefs[index] + let entry: &VMCallerCheckedAnyfunc = &*self.funcref_backings[index]; + VMFuncRef(entry as *const VMCallerCheckedAnyfunc) } /// The `table.init` operation: initializes a portion of a table with a @@ -903,7 +904,6 @@ impl InstanceHandle { finished_globals: BoxedSlice>, imports: Imports, vmshared_signatures: BoxedSlice, - func_data_registry: &FuncDataRegistry, host_state: Box, imported_function_envs: BoxedSlice, ) -> Result { @@ -917,7 +917,7 @@ impl InstanceHandle { let handle = { let offsets = allocator.offsets().clone(); // use dummy value to create an instance so we can get the vmctx pointer - let funcrefs = PrimaryMap::new().into_boxed_slice(); + let funcref_backings = PrimaryMap::new().into_boxed_slice(); // Create the `Instance`. The unique, the One. let instance = Instance { module, @@ -930,7 +930,7 @@ impl InstanceHandle { passive_elements: Default::default(), passive_data, host_state, - funcrefs, + funcref_backings, imported_function_envs, vmctx: VMContext {}, }; @@ -941,11 +941,10 @@ impl InstanceHandle { { let instance = instance_ref.as_mut().unwrap(); let vmctx_ptr = instance.vmctx_ptr(); - instance.funcrefs = build_funcrefs( + instance.funcref_backings = build_funcrefs( &*instance.module, &imports, &instance.functions, - func_data_registry, &vmshared_signatures, vmctx_ptr, ); @@ -1436,10 +1435,9 @@ fn build_funcrefs( module_info: &ModuleInfo, imports: &Imports, finished_functions: &BoxedSlice, - func_data_registry: &FuncDataRegistry, vmshared_signatures: &BoxedSlice, vmctx_ptr: *mut VMContext, -) -> BoxedSlice { +) -> BoxedSlice> { let mut func_refs = PrimaryMap::with_capacity(module_info.functions.len()); // do imported functions @@ -1451,8 +1449,7 @@ fn build_funcrefs( type_index, vmctx: import.environment, }; - let func_ref = func_data_registry.register(anyfunc); - func_refs.push(func_ref); + func_refs.push(Box::new(anyfunc)); } // do local functions @@ -1465,8 +1462,7 @@ fn build_funcrefs( type_index, vmctx: VMFunctionEnvironment { vmctx: vmctx_ptr }, }; - let func_ref = func_data_registry.register(anyfunc); - func_refs.push(func_ref); + func_refs.push(Box::new(anyfunc)); } func_refs.into_boxed_slice() diff --git a/lib/vm/src/lib.rs b/lib/vm/src/lib.rs index 87d51529a45..5f40b19ea29 100644 --- a/lib/vm/src/lib.rs +++ b/lib/vm/src/lib.rs @@ -39,7 +39,7 @@ mod vmoffsets; pub mod libcalls; pub use crate::export::*; -pub use crate::func_data_registry::{FuncDataRegistry, VMFuncRef}; +pub use crate::func_data_registry::VMFuncRef; pub use crate::global::*; pub use crate::imports::Imports; pub use crate::instance::{ diff --git a/tests/lib/engine-dummy/src/artifact.rs b/tests/lib/engine-dummy/src/artifact.rs index a5a993c401f..4467d22056c 100644 --- a/tests/lib/engine-dummy/src/artifact.rs +++ b/tests/lib/engine-dummy/src/artifact.rs @@ -16,8 +16,8 @@ use wasmer_types::{ TableIndex, }; use wasmer_vm::{ - FuncDataRegistry, FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMContext, - VMFunctionBody, VMSharedSignatureIndex, VMTrampoline, + FunctionBodyPtr, MemoryStyle, ModuleInfo, TableStyle, VMContext, VMFunctionBody, + VMSharedSignatureIndex, VMTrampoline, }; /// Serializable struct for the artifact @@ -44,7 +44,6 @@ pub struct DummyArtifact { finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, - func_data_registry: Arc, } extern "C" fn dummy_function(_context: *mut VMContext) { @@ -185,7 +184,6 @@ impl DummyArtifact { finished_function_call_trampolines, finished_dynamic_function_trampolines, signatures, - func_data_registry: engine.func_data().clone(), }) } } @@ -239,10 +237,6 @@ impl Artifact for DummyArtifact { &self.signatures } - fn func_data_registry(&self) -> &FuncDataRegistry { - &self.func_data_registry - } - #[cfg(feature = "serialize")] fn serialize(&self) -> Result, SerializeError> { let bytes = bincode::serialize(&self.metadata) diff --git a/tests/lib/engine-dummy/src/engine.rs b/tests/lib/engine-dummy/src/engine.rs index cdc80b81b1f..ca9b0c4a9c0 100644 --- a/tests/lib/engine-dummy/src/engine.rs +++ b/tests/lib/engine-dummy/src/engine.rs @@ -6,10 +6,7 @@ use std::sync::Arc; use wasmer_compiler::{CompileError, Features, Target}; use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables}; use wasmer_types::FunctionType; -use wasmer_vm::{ - FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMContext, VMFuncRef, - VMFunctionBody, VMSharedSignatureIndex, -}; +use wasmer_vm::{SignatureRegistry, VMContext, VMFunctionBody, VMSharedSignatureIndex}; #[allow(dead_code)] extern "C" fn dummy_trampoline( @@ -24,7 +21,6 @@ extern "C" fn dummy_trampoline( #[derive(Clone, MemoryUsage)] pub struct DummyEngine { signatures: Arc, - func_data: Arc, features: Arc, target: Arc, engine_id: EngineId, @@ -35,7 +31,6 @@ impl DummyEngine { pub fn new() -> Self { Self { signatures: Arc::new(SignatureRegistry::new()), - func_data: Arc::new(FuncDataRegistry::new()), features: Arc::new(Default::default()), target: Arc::new(Default::default()), engine_id: EngineId::default(), @@ -45,11 +40,6 @@ impl DummyEngine { pub fn features(&self) -> &Features { &self.features } - - /// Shared func metadata registry. - pub(crate) fn func_data(&self) -> &Arc { - &self.func_data - } } impl Engine for DummyEngine { @@ -63,10 +53,6 @@ impl Engine for DummyEngine { self.signatures.register(func_type) } - fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef { - self.func_data.register(func_data) - } - /// Lookup a signature fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option { self.signatures.lookup(sig) From b3ccf7789a83a69824d281c22de1881872267f9b Mon Sep 17 00:00:00 2001 From: Syrus Date: Fri, 29 Oct 2021 18:01:28 +0200 Subject: [PATCH 2/3] Ignore the Wasm spec tests linking for now More info: https://github.com/wasmerio/wasmer/issues/2638 --- tests/ignores.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/ignores.txt b/tests/ignores.txt index 6311b9a2279..b2ba08476e3 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -6,6 +6,11 @@ singlepass+dylib * # It needs to add support for PIC in Singlepass. Not implemen windows+dylib * # This might be trivial to fix? musl+dylib * # Dynamic loading not supported in Musl +# Linking tests are not fully passing because of an issue with how reference types was +# initially implemented, we will fix this. +# Related issue: #2438 +spec::linking * + # Traps ## Traps. Tracing doesn't work properly in Singlepass ## Unwinding is not properly implemented in Singlepass From 78f5b42bda4ee6f61ab4b63ebe50d6f2a9707b56 Mon Sep 17 00:00:00 2001 From: Syrus Date: Fri, 29 Oct 2021 18:12:36 +0200 Subject: [PATCH 3/3] Fixed ignores --- tests/ignores.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ignores.txt b/tests/ignores.txt index b2ba08476e3..ad5b1c73712 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -9,7 +9,7 @@ musl+dylib * # Dynamic loading not supported in Musl # Linking tests are not fully passing because of an issue with how reference types was # initially implemented, we will fix this. # Related issue: #2438 -spec::linking * +spec::linking # Traps ## Traps. Tracing doesn't work properly in Singlepass