diff --git a/CHANGELOG.md b/CHANGELOG.md index 4086e134e50..8b2fa3b4cf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - [#2135](https://github.com/wasmerio/wasmer/pull/2135) [Documentation](./PACKAGING.md) for linux distribution maintainers ### Changed +- [#2200](https://github.com/wasmerio/wasmer/pull/2200) Implement `loupe::MemoryUsage` for `wasmer::Module`. - [#2199](https://github.com/wasmerio/wasmer/pull/2199) Implement `loupe::MemoryUsage` for `wasmer::Store`. - [#2140](https://github.com/wasmerio/wasmer/pull/2140) Reduce the number of dependencies in the `wasmer.dll` shared library by statically compiling CRT. - [#2113](https://github.com/wasmerio/wasmer/pull/2113) Bump minimum supported Rust version to 1.49 diff --git a/Cargo.lock b/Cargo.lock index 052da5f44dd..3baa7f36750 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1156,19 +1156,20 @@ dependencies = [ [[package]] name = "loupe" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0700ebea6c2a63815aa6f376f1c6dac93223d7b11c4728a7f71ff951a6eca67" +checksum = "1acf065b51eb58abbc66a07c27ec63142205d339a9f5093dc3e1d7cda3d5c9a3" dependencies = [ + "indexmap", "loupe-derive", "rustversion", ] [[package]] name = "loupe-derive" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9a2f753a29753600fa1e3f5c2b311babaca3bb66929bdc37082996e9c46cfb" +checksum = "e40881c741681f26b0f4c0261f493c8df600998807184b524e34b7e208324834" dependencies = [ "quote", "syn", diff --git a/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs index 14368249127..8d2f92d3b92 100644 --- a/examples/tunables_limit_memory.rs +++ b/examples/tunables_limit_memory.rs @@ -1,8 +1,7 @@ -use std::mem; use std::ptr::NonNull; use std::sync::Arc; -use loupe::{MemoryUsage, MemoryUsageTracker}; +use loupe::MemoryUsage; use wasmer::{ imports, vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition}, @@ -16,6 +15,7 @@ use wasmer_engine_jit::JIT; /// /// After adjusting the memory limits, it delegates all other logic /// to the base tunables. +#[derive(MemoryUsage)] pub struct LimitingTunables { /// The maximum a linear memory is allowed to be (in Wasm pages, 64 KiB each). /// Since Wasmer ensures there is only none or one memory, this is practically @@ -133,12 +133,6 @@ impl Tunables for LimitingTunables { } } -impl MemoryUsage for LimitingTunables { - fn size_of_val(&self, _tracker: &mut dyn MemoryUsageTracker) -> usize { - mem::size_of_val(self) - } -} - fn main() -> Result<(), Box> { // A Wasm module with one exported memory (min: 7 pages, max: unset) let wat = br#"(module (memory 7) (export "memory" (memory 0)))"#; diff --git a/lib/api/src/module.rs b/lib/api/src/module.rs index 714991cba58..ea2b8b8d8a8 100644 --- a/lib/api/src/module.rs +++ b/lib/api/src/module.rs @@ -1,6 +1,7 @@ use crate::store::Store; use crate::types::{ExportType, ImportType}; use crate::InstantiationError; +use loupe::MemoryUsage; use std::fmt; use std::io; use std::path::Path; @@ -30,7 +31,7 @@ pub enum IoCompileError { /// /// Cloning a module is cheap: it does a shallow copy of the compiled /// contents rather than a deep copy. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct Module { store: Store, artifact: Arc, diff --git a/lib/compiler/src/address_map.rs b/lib/compiler/src/address_map.rs index 40d37a073f6..4fd8c1a2396 100644 --- a/lib/compiler/src/address_map.rs +++ b/lib/compiler/src/address_map.rs @@ -3,12 +3,13 @@ use crate::lib::std::vec::Vec; use crate::sourceloc::SourceLoc; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; /// Single source location to generated address mapping. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)] pub struct InstructionAddressMap { /// Original source location. pub srcloc: SourceLoc, @@ -22,7 +23,7 @@ pub struct InstructionAddressMap { /// Function and its instructions addresses mappings. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, MemoryUsage)] pub struct FunctionAddressMap { /// Instructions maps. /// The array is sorted by the InstructionAddressMap::code_offset field. diff --git a/lib/compiler/src/function.rs b/lib/compiler/src/function.rs index 6be0ae9ac52..e431f3bb7e0 100644 --- a/lib/compiler/src/function.rs +++ b/lib/compiler/src/function.rs @@ -12,6 +12,7 @@ use crate::lib::std::vec::Vec; use crate::section::{CustomSection, SectionIndex}; use crate::trap::TrapInformation; use crate::{CompiledFunctionUnwindInfo, FunctionAddressMap, JumpTableOffsets, Relocation}; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::PrimaryMap; @@ -22,7 +23,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, SignatureIndex}; /// This structure is only used for reconstructing /// the frame information after a `Trap`. #[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, MemoryUsage)] pub struct CompiledFunctionFrameInfo { /// The traps (in the function body). /// @@ -35,7 +36,7 @@ pub struct CompiledFunctionFrameInfo { /// The function body. #[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)] pub struct FunctionBody { /// The function body bytes. #[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))] @@ -79,7 +80,7 @@ pub type CustomSections = PrimaryMap; /// In the future this structure may also hold other information useful /// for debugging. #[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))] -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, MemoryUsage)] pub struct Dwarf { /// The section index in the [`Compilation`] that corresponds to the exception frames. /// [Learn diff --git a/lib/compiler/src/jump_table.rs b/lib/compiler/src/jump_table.rs index 19da678c77a..25fdbb60c08 100644 --- a/lib/compiler/src/jump_table.rs +++ b/lib/compiler/src/jump_table.rs @@ -5,6 +5,7 @@ //! [Learn more](https://en.wikipedia.org/wiki/Branch_table). use super::CodeOffset; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::{entity_impl, SecondaryMap}; @@ -14,7 +15,7 @@ use wasmer_types::entity::{entity_impl, SecondaryMap}; /// `JumpTable`s are used for indirect branching and are specialized for dense, /// 0-based jump offsets. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, MemoryUsage)] pub struct JumpTable(u32); entity_impl!(JumpTable, "jt"); diff --git a/lib/compiler/src/module.rs b/lib/compiler/src/module.rs index dacbdf3560a..b7882131295 100644 --- a/lib/compiler/src/module.rs +++ b/lib/compiler/src/module.rs @@ -1,4 +1,5 @@ use crate::lib::std::sync::Arc; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::PrimaryMap; @@ -10,7 +11,7 @@ use wasmer_vm::{MemoryStyle, ModuleInfo, TableStyle}; /// This differs from [`ModuleInfo`] because it have extra info only /// possible after translation (such as the features used for compiling, /// or the `MemoryStyle` and `TableStyle`). -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))] pub struct CompileModuleInfo { /// The features used for compiling the module diff --git a/lib/compiler/src/relocation.rs b/lib/compiler/src/relocation.rs index c0e6306ed6e..25cec340ad9 100644 --- a/lib/compiler/src/relocation.rs +++ b/lib/compiler/src/relocation.rs @@ -13,6 +13,7 @@ use crate::lib::std::fmt; use crate::lib::std::vec::Vec; use crate::section::SectionIndex; use crate::{Addend, CodeOffset, JumpTable}; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::PrimaryMap; @@ -21,7 +22,7 @@ use wasmer_vm::libcalls::LibCall; /// Relocation kinds for every ISA. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, MemoryUsage)] pub enum RelocationKind { /// absolute 4-byte Abs4, @@ -79,7 +80,7 @@ impl fmt::Display for RelocationKind { /// A record of a relocation to perform. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)] pub struct Relocation { /// The relocation kind. pub kind: RelocationKind, @@ -93,7 +94,7 @@ pub struct Relocation { /// Destination function. Can be either user function or some special one, like `memory.grow`. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, MemoryUsage)] pub enum RelocationTarget { /// A relocation to a function defined locally in the wasm (not an imported one). LocalFunc(LocalFunctionIndex), diff --git a/lib/compiler/src/section.rs b/lib/compiler/src/section.rs index 096cbcc8cf7..f6f3ee40484 100644 --- a/lib/compiler/src/section.rs +++ b/lib/compiler/src/section.rs @@ -7,13 +7,14 @@ use crate::lib::std::vec::Vec; use crate::Relocation; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::entity_impl; /// Index type of a Section defined inside a WebAssembly `Compilation`. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] pub struct SectionIndex(u32); entity_impl!(SectionIndex); @@ -22,7 +23,7 @@ entity_impl!(SectionIndex); /// /// Determines how a custom section may be used. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)] pub enum CustomSectionProtection { /// A custom section with read permission. Read, @@ -36,7 +37,7 @@ pub enum CustomSectionProtection { /// This is used so compilers can store arbitrary information /// in the emitted module. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)] pub struct CustomSection { /// Memory protection that applies to this section. pub protection: CustomSectionProtection, @@ -55,7 +56,7 @@ pub struct CustomSection { /// The bytes in the section. #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, MemoryUsage)] pub struct SectionBody(#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))] Vec); impl SectionBody { diff --git a/lib/compiler/src/sourceloc.rs b/lib/compiler/src/sourceloc.rs index 2964e144d47..fa61e4ab897 100644 --- a/lib/compiler/src/sourceloc.rs +++ b/lib/compiler/src/sourceloc.rs @@ -8,7 +8,7 @@ //! and tracing errors. use crate::lib::std::fmt; - +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -22,7 +22,7 @@ use serde::{Deserialize, Serialize}; serde(transparent) )] #[repr(transparent)] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, MemoryUsage)] pub struct SourceLoc(u32); impl SourceLoc { diff --git a/lib/compiler/src/trap.rs b/lib/compiler/src/trap.rs index 058f7e21c2e..80aecc73a3b 100644 --- a/lib/compiler/src/trap.rs +++ b/lib/compiler/src/trap.rs @@ -1,11 +1,12 @@ use crate::CodeOffset; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_vm::TrapCode; /// Information about trap. #[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))] -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, MemoryUsage)] pub struct TrapInformation { /// The offset of the trapping instruction in native code. It is relative to the beginning of the function. pub code_offset: CodeOffset, diff --git a/lib/compiler/src/unwind.rs b/lib/compiler/src/unwind.rs index 30949281477..128c300deab 100644 --- a/lib/compiler/src/unwind.rs +++ b/lib/compiler/src/unwind.rs @@ -6,6 +6,7 @@ //! //! [Learn more](https://en.wikipedia.org/wiki/Call_stack). use crate::lib::std::vec::Vec; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -17,7 +18,7 @@ use serde::{Deserialize, Serialize}; /// /// [unwind info]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019 #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)] pub enum CompiledFunctionUnwindInfo { /// Windows UNWIND_INFO. WindowsX64(Vec), diff --git a/lib/engine-jit/src/artifact.rs b/lib/engine-jit/src/artifact.rs index e9d91e10bdc..d0a548bb8b2 100644 --- a/lib/engine-jit/src/artifact.rs +++ b/lib/engine-jit/src/artifact.rs @@ -6,6 +6,7 @@ use crate::link::link_module; #[cfg(feature = "compiler")] use crate::serialize::SerializableCompilation; use crate::serialize::SerializableModule; +use loupe::MemoryUsage; use std::sync::{Arc, Mutex}; use wasmer_compiler::{CompileError, Features, Triple}; #[cfg(feature = "compiler")] @@ -26,9 +27,11 @@ use wasmer_vm::{ }; /// A compiled wasm module, ready to be instantiated. +#[derive(MemoryUsage)] pub struct JITArtifact { serializable: SerializableModule, finished_functions: BoxedSlice, + #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, diff --git a/lib/engine-jit/src/serialize.rs b/lib/engine-jit/src/serialize.rs index 92596ff3362..c924381b9a0 100644 --- a/lib/engine-jit/src/serialize.rs +++ b/lib/engine-jit/src/serialize.rs @@ -1,3 +1,4 @@ +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use wasmer_compiler::{ CompileModuleInfo, CustomSection, Dwarf, FunctionBody, JumpTableOffsets, Relocation, @@ -18,7 +19,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, Sign // } /// The compilation related data for a serialized modules -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, MemoryUsage)] pub struct SerializableCompilation { pub function_bodies: PrimaryMap, pub function_relocations: PrimaryMap>, @@ -37,7 +38,7 @@ pub struct SerializableCompilation { /// Serializable struct that is able to serialize from and to /// a `JITArtifactInfo`. -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, MemoryUsage)] pub struct SerializableModule { pub compilation: SerializableCompilation, pub compile_info: CompileModuleInfo, diff --git a/lib/engine-native/src/artifact.rs b/lib/engine-native/src/artifact.rs index 8c77216cf20..7f93b3f97e4 100644 --- a/lib/engine-native/src/artifact.rs +++ b/lib/engine-native/src/artifact.rs @@ -4,6 +4,7 @@ use crate::engine::{NativeEngine, NativeEngineInner}; use crate::serialize::ModuleMetadata; use libloading::{Library, Symbol as LibrarySymbol}; +use loupe::MemoryUsage; use std::error::Error; use std::fs::File; use std::io::{Read, Write}; @@ -37,10 +38,12 @@ use wasmer_vm::{ }; /// A compiled wasm module, ready to be instantiated. +#[derive(MemoryUsage)] pub struct NativeArtifact { sharedobject_path: PathBuf, metadata: ModuleMetadata, finished_functions: BoxedSlice, + #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, diff --git a/lib/engine-native/src/serialize.rs b/lib/engine-native/src/serialize.rs index 88fa9965d27..47c012d77fa 100644 --- a/lib/engine-native/src/serialize.rs +++ b/lib/engine-native/src/serialize.rs @@ -1,10 +1,11 @@ +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use wasmer_compiler::{CompileModuleInfo, SectionIndex, Symbol, SymbolRegistry}; use wasmer_types::entity::{EntityRef, PrimaryMap}; use wasmer_types::{FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, SignatureIndex}; /// Serializable struct that represents the compiled metadata. -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, MemoryUsage)] pub struct ModuleMetadata { pub compile_info: CompileModuleInfo, pub prefix: String, diff --git a/lib/engine-object-file/src/artifact.rs b/lib/engine-object-file/src/artifact.rs index fcba7872224..276f53cc060 100644 --- a/lib/engine-object-file/src/artifact.rs +++ b/lib/engine-object-file/src/artifact.rs @@ -3,6 +3,7 @@ use crate::engine::{ObjectFileEngine, ObjectFileEngineInner}; use crate::serialize::{ModuleMetadata, ModuleMetadataSymbolRegistry}; +use loupe::MemoryUsage; use std::collections::BTreeMap; use std::error::Error; use std::mem; @@ -30,10 +31,12 @@ use wasmer_vm::{ }; /// A compiled wasm module, ready to be instantiated. +#[derive(MemoryUsage)] pub struct ObjectFileArtifact { metadata: ModuleMetadata, module_bytes: Vec, finished_functions: BoxedSlice, + #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, diff --git a/lib/engine-object-file/src/serialize.rs b/lib/engine-object-file/src/serialize.rs index 8ec7da0302d..4077b68e667 100644 --- a/lib/engine-object-file/src/serialize.rs +++ b/lib/engine-object-file/src/serialize.rs @@ -1,10 +1,11 @@ +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use wasmer_compiler::{CompileModuleInfo, SectionIndex, Symbol, SymbolRegistry}; use wasmer_types::entity::{EntityRef, PrimaryMap}; use wasmer_types::{FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, SignatureIndex}; /// Serializable struct that represents the compiled metadata. -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, MemoryUsage)] pub struct ModuleMetadata { pub compile_info: CompileModuleInfo, pub prefix: String, @@ -13,6 +14,7 @@ pub struct ModuleMetadata { pub function_body_lengths: PrimaryMap, } +#[derive(MemoryUsage)] pub struct ModuleMetadataSymbolRegistry { pub prefix: String, } diff --git a/lib/engine/src/artifact.rs b/lib/engine/src/artifact.rs index 3a93fe4ce1f..db420f4f9a1 100644 --- a/lib/engine/src/artifact.rs +++ b/lib/engine/src/artifact.rs @@ -1,6 +1,7 @@ use crate::{ resolve_imports, InstantiationError, Resolver, RuntimeError, SerializeError, Tunables, }; +use loupe::MemoryUsage; use std::any::Any; use std::fs; use std::path::Path; @@ -22,7 +23,7 @@ use wasmer_vm::{ /// The `Artifact` contains the compiled data for a given /// module as well as extra information needed to run the /// module at runtime, such as [`ModuleInfo`] and [`Features`]. -pub trait Artifact: Send + Sync + Upcastable { +pub trait Artifact: Send + Sync + Upcastable + MemoryUsage { /// Return a reference-counted pointer to the module fn module(&self) -> Arc; diff --git a/lib/engine/src/serialize.rs b/lib/engine/src/serialize.rs index d501332c931..a36b47da320 100644 --- a/lib/engine/src/serialize.rs +++ b/lib/engine/src/serialize.rs @@ -1,3 +1,4 @@ +use loupe::MemoryUsage; use serde::de::{Deserializer, Visitor}; use serde::ser::Serializer; use serde::{Deserialize, Serialize}; @@ -5,7 +6,7 @@ use std::fmt; use wasmer_compiler::CompiledFunctionFrameInfo; /// This is the unserialized verison of `CompiledFunctionFrameInfo`. -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize, MemoryUsage)] #[serde(transparent)] #[repr(transparent)] pub struct UnprocessedFunctionFrameInfo { @@ -44,7 +45,7 @@ impl UnprocessedFunctionFrameInfo { /// of compiling at the same time that emiting the JIT. /// In that case, we don't need to deserialize/process anything /// as the data is already in memory. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub enum SerializableFunctionFrameInfo { /// The unprocessed frame info (binary) Unprocessed(UnprocessedFunctionFrameInfo), diff --git a/lib/engine/src/trap/frame_info.rs b/lib/engine/src/trap/frame_info.rs index 8906a4478c7..3407ab742db 100644 --- a/lib/engine/src/trap/frame_info.rs +++ b/lib/engine/src/trap/frame_info.rs @@ -11,6 +11,7 @@ //! FRAME_INFO.register(module, compiled_functions); //! ``` use crate::serialize::SerializableFunctionFrameInfo; +use loupe::MemoryUsage; use std::cmp; use std::collections::BTreeMap; use std::sync::{Arc, RwLock}; @@ -44,6 +45,7 @@ pub struct GlobalFrameInfo { /// An RAII structure used to unregister a module's frame information when the /// module is destroyed. +#[derive(MemoryUsage)] pub struct GlobalFrameInfoRegistration { /// The key that will be removed from the global `ranges` map when this is /// dropped. diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index a721dc1157b..4e95f79f0a2 100644 --- a/lib/vm/Cargo.toml +++ b/lib/vm/Cargo.toml @@ -21,7 +21,7 @@ more-asserts = "0.2" cfg-if = "0.1" backtrace = "0.3" serde = { version = "1.0", features = ["derive", "rc"] } -loupe = "0.1" +loupe = { version = "0.1", features = ["enable-indexmap"] } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] } diff --git a/lib/vm/src/global.rs b/lib/vm/src/global.rs index bdf65af6382..35f41fdfdf8 100644 --- a/lib/vm/src/global.rs +++ b/lib/vm/src/global.rs @@ -1,11 +1,12 @@ use crate::vmcontext::VMGlobalDefinition; +use loupe::MemoryUsage; use std::cell::UnsafeCell; use std::ptr::NonNull; use std::sync::Mutex; use thiserror::Error; use wasmer_types::{GlobalType, Mutability, Type, Value}; -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] /// A Global instance pub struct Global { ty: GlobalType, diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index 77849e3b2a0..986ee9d5156 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -27,6 +27,7 @@ use crate::vmcontext::{ }; use crate::{FunctionBodyPtr, ModuleInfo, VMOffsets}; use crate::{VMExportFunction, VMExportGlobal, VMExportMemory, VMExportTable}; +use loupe::{MemoryUsage, MemoryUsageTracker}; use memoffset::offset_of; use more_asserts::assert_lt; use std::any::Any; @@ -34,9 +35,10 @@ use std::cell::{Cell, RefCell}; use std::convert::{TryFrom, TryInto}; use std::ffi; use std::fmt; -use std::ptr::NonNull; +use std::mem; +use std::ptr::{self, NonNull}; +use std::slice; use std::sync::Arc; -use std::{mem, ptr, slice}; use wasmer_types::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, PrimaryMap}; use wasmer_types::{ DataIndex, DataInitializer, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, GlobalInit, @@ -122,6 +124,7 @@ pub enum ImportFunctionEnv { /// The function environment. This is not always the user-supplied /// env. env: *mut ffi::c_void, + /// A clone function for duplicating the env. clone: fn(*mut ffi::c_void) -> *mut ffi::c_void, /// This field is not always present. When it is present, it @@ -187,6 +190,12 @@ impl Drop for ImportFunctionEnv { } } +impl MemoryUsage for ImportFunctionEnv { + fn size_of_val(&self, _: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + } +} + impl fmt::Debug for Instance { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.debug_struct("Instance").finish() diff --git a/lib/vm/src/lib.rs b/lib/vm/src/lib.rs index c46eab9fe68..8d63c303951 100644 --- a/lib/vm/src/lib.rs +++ b/lib/vm/src/lib.rs @@ -56,12 +56,13 @@ pub use crate::vmcontext::{ VMTableImport, VMTrampoline, }; pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMOffsets}; +use loupe::MemoryUsage; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); /// A safe wrapper around `VMFunctionBody`. -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, MemoryUsage)] #[repr(transparent)] pub struct FunctionBodyPtr(pub *const VMFunctionBody); diff --git a/lib/vm/src/libcalls.rs b/lib/vm/src/libcalls.rs index 5267d35a6e5..a602af1ac9e 100644 --- a/lib/vm/src/libcalls.rs +++ b/lib/vm/src/libcalls.rs @@ -38,6 +38,7 @@ use crate::probestack::PROBESTACK; use crate::trap::{raise_lib_trap, Trap, TrapCode}; use crate::vmcontext::VMContext; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use std::fmt; use wasmer_types::{DataIndex, ElemIndex, LocalMemoryIndex, MemoryIndex, TableIndex}; @@ -405,7 +406,7 @@ pub static wasmer_probestack: unsafe extern "C" fn() = PROBESTACK; /// The name of a runtime library routine. /// /// This list is likely to grow over time. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, MemoryUsage)] pub enum LibCall { /// ceil.f32 CeilF32, diff --git a/lib/vm/src/memory.rs b/lib/vm/src/memory.rs index 8ab78560584..e64cfd132bf 100644 --- a/lib/vm/src/memory.rs +++ b/lib/vm/src/memory.rs @@ -7,6 +7,7 @@ use crate::mmap::Mmap; use crate::vmcontext::VMMemoryDefinition; +use loupe::MemoryUsage; use more_asserts::assert_ge; use serde::{Deserialize, Serialize}; use std::borrow::BorrowMut; @@ -61,7 +62,7 @@ pub enum MemoryError { } /// Implementation styles for WebAssembly linear memory. -#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, MemoryUsage)] pub enum MemoryStyle { /// The actual memory can be resized and moved. Dynamic { @@ -96,7 +97,7 @@ impl MemoryStyle { } /// Trait for implementing Wasm Memory used by Wasmer. -pub trait Memory: fmt::Debug + Send + Sync { +pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage { /// Returns the memory type for this memory. fn ty(&self) -> &MemoryType; @@ -116,7 +117,7 @@ pub trait Memory: fmt::Debug + Send + Sync { } /// A linear memory instance. -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] pub struct LinearMemory { // The underlying allocation. mmap: Mutex, @@ -144,7 +145,7 @@ pub struct LinearMemory { /// A type to help manage who is responsible for the backing memory of them /// `VMMemoryDefinition`. -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] enum VMMemoryDefinitionOwnership { /// The `VMMemoryDefinition` is owned by the `Instance` and we should use /// its memory. This is how a local memory that's exported should be stored. @@ -167,7 +168,7 @@ unsafe impl Send for LinearMemory {} /// This is correct because all internal mutability is protected by a mutex. unsafe impl Sync for LinearMemory {} -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] struct WasmMmap { // Our OS allocation of mmap'd memory. alloc: Mmap, diff --git a/lib/vm/src/module.rs b/lib/vm/src/module.rs index 82d951f46c2..d43aa5dceae 100644 --- a/lib/vm/src/module.rs +++ b/lib/vm/src/module.rs @@ -5,6 +5,7 @@ //! `wasmer::Module`. use indexmap::IndexMap; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fmt; @@ -19,7 +20,7 @@ use wasmer_types::{ TableIndex, TableInitializer, TableType, }; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct ModuleId { id: usize, } @@ -41,7 +42,7 @@ impl Default for ModuleId { /// A translated WebAssembly module, excluding the function bodies and /// memory initializers. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, MemoryUsage)] pub struct ModuleInfo { /// A unique identifier (within this process) for this module. /// diff --git a/lib/vm/src/table.rs b/lib/vm/src/table.rs index 66fb0e8a128..90f2069a165 100644 --- a/lib/vm/src/table.rs +++ b/lib/vm/src/table.rs @@ -7,6 +7,7 @@ use crate::trap::{Trap, TrapCode}; use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition}; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use std::borrow::{Borrow, BorrowMut}; use std::cell::UnsafeCell; @@ -17,14 +18,14 @@ use std::sync::Mutex; use wasmer_types::{TableType, Type as ValType}; /// Implementation styles for WebAssembly tables. -#[derive(Debug, Clone, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, Hash, Serialize, Deserialize, MemoryUsage)] pub enum TableStyle { /// Signatures are stored in the table and checked in the caller. CallerChecksSignature, } /// Trait for implementing the interface of a Wasm table. -pub trait Table: fmt::Debug + Send + Sync { +pub trait Table: fmt::Debug + Send + Sync + MemoryUsage { /// Returns the style for this Table. fn style(&self) -> &TableStyle; @@ -103,7 +104,7 @@ pub trait Table: fmt::Debug + Send + Sync { } /// A table instance. -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] pub struct LinearTable { // TODO: we can remove the mutex by using atomic swaps and preallocating the max table size vec: Mutex>, @@ -117,7 +118,7 @@ pub struct LinearTable { /// A type to help manage who is responsible for the backing table of the /// `VMTableDefinition`. -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] enum VMTableDefinitionOwnership { /// The `VMTableDefinition` is owned by the `Instance` and we should use /// its table. This is how a local table that's exported should be stored. diff --git a/lib/vm/src/trap/trapcode.rs b/lib/vm/src/trap/trapcode.rs index 32121fbd08e..31a25765f4f 100644 --- a/lib/vm/src/trap/trapcode.rs +++ b/lib/vm/src/trap/trapcode.rs @@ -5,13 +5,14 @@ use core::fmt::{self, Display, Formatter}; use core::str::FromStr; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use thiserror::Error; /// A trap code describing the reason for a trap. /// /// All trap instructions have an explicit trap code. -#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize, Deserialize, Error)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize, Deserialize, Error, MemoryUsage)] #[repr(u32)] pub enum TrapCode { /// The current stack space was exhausted. diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index 929c1126f2d..9479f8121bd 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -9,10 +9,11 @@ use crate::instance::Instance; use crate::memory::Memory; use crate::table::Table; use crate::trap::{Trap, TrapCode}; -use loupe::MemoryUsage; +use loupe::{MemoryUsage, MemoryUsageTracker, POINTER_BYTE_SIZE}; use std::any::Any; use std::convert::TryFrom; use std::fmt; +use std::mem; use std::ptr::{self, NonNull}; use std::sync::Arc; use std::u32; @@ -50,8 +51,14 @@ impl std::cmp::PartialEq for VMFunctionEnvironment { } } +impl MemoryUsage for VMFunctionEnvironment { + fn size_of_val(&self, _: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + } +} + /// An imported function. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, MemoryUsage)] #[repr(C)] pub struct VMFunctionImport { /// A pointer to the imported function body. @@ -189,7 +196,7 @@ pub enum VMFunctionKind { /// The fields compiled code needs to access to utilize a WebAssembly table /// imported from another instance. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] #[repr(C)] pub struct VMTableImport { /// A pointer to the imported table description. @@ -227,7 +234,7 @@ mod test_vmtable_import { /// The fields compiled code needs to access to utilize a WebAssembly linear /// memory imported from another instance. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] #[repr(C)] pub struct VMMemoryImport { /// A pointer to the imported memory description. @@ -265,7 +272,7 @@ mod test_vmmemory_import { /// The fields compiled code needs to access to utilize a WebAssembly global /// variable imported from another instance. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] #[repr(C)] pub struct VMGlobalImport { /// A pointer to the imported global variable description. @@ -337,6 +344,16 @@ unsafe impl Send for VMMemoryDefinition {} /// correctness in a multi-threaded context is concerned. unsafe impl Sync for VMMemoryDefinition {} +impl MemoryUsage for VMMemoryDefinition { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + if tracker.track(self.base as *const _ as *const ()) { + POINTER_BYTE_SIZE * (self.current_length as usize) + } else { + 0 + } + } +} + impl VMMemoryDefinition { /// Do an unsynchronized, non-atomic `memory.copy` for the memory. /// @@ -446,6 +463,16 @@ pub struct VMTableDefinition { pub current_elements: u32, } +impl MemoryUsage for VMTableDefinition { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + if tracker.track(self.base as *const _ as *const ()) { + POINTER_BYTE_SIZE * (self.current_elements as usize) + } else { + 0 + } + } +} + #[cfg(test)] mod test_vmtable_definition { use super::VMTableDefinition; @@ -500,11 +527,17 @@ impl fmt::Debug for VMGlobalDefinitionStorage { } } +impl MemoryUsage for VMGlobalDefinitionStorage { + fn size_of_val(&self, _: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + } +} + /// The storage for a WebAssembly global defined within the instance. /// /// TODO: Pack the globals more densely, rather than using the same size /// for every type. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] #[repr(C, align(16))] pub struct VMGlobalDefinition { storage: VMGlobalDefinitionStorage, @@ -751,7 +784,7 @@ impl Default for VMSharedSignatureIndex { /// The VM caller-checked "anyfunc" record, for caller-side signature checking. /// It consists of the actual function pointer and a signature id to be checked /// by the caller. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] #[repr(C)] pub struct VMCallerCheckedAnyfunc { /// Function body. diff --git a/lib/wasmer-types/src/entity/boxed_slice.rs b/lib/wasmer-types/src/entity/boxed_slice.rs index 4f9aa95eaf8..19fdd4b45ec 100644 --- a/lib/wasmer-types/src/entity/boxed_slice.rs +++ b/lib/wasmer-types/src/entity/boxed_slice.rs @@ -10,6 +10,8 @@ use crate::lib::std::boxed::Box; use crate::lib::std::marker::PhantomData; use crate::lib::std::ops::{Index, IndexMut}; use crate::lib::std::slice; +use loupe::{MemoryUsage, MemoryUsageTracker}; +use std::mem; /// A slice mapping `K -> V` allocating dense entity references. /// @@ -144,6 +146,21 @@ where } } +impl MemoryUsage for BoxedSlice +where + K: EntityRef, + V: MemoryUsage, +{ + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + + self + .elems + .iter() + .map(|value| value.size_of_val(tracker) - mem::size_of_val(value)) + .sum::() + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/lib/wasmer-types/src/entity/primary_map.rs b/lib/wasmer-types/src/entity/primary_map.rs index c82bf4d5ad4..a3a07eec81d 100644 --- a/lib/wasmer-types/src/entity/primary_map.rs +++ b/lib/wasmer-types/src/entity/primary_map.rs @@ -12,8 +12,10 @@ use crate::lib::std::marker::PhantomData; use crate::lib::std::ops::{Index, IndexMut}; use crate::lib::std::slice; use crate::lib::std::vec::Vec; +use loupe::{MemoryUsage, MemoryUsageTracker}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; +use std::mem; /// A primary mapping `K -> V` allocating dense entity references. /// @@ -236,6 +238,21 @@ where } } +impl MemoryUsage for PrimaryMap +where + K: EntityRef, + V: MemoryUsage, +{ + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + + self + .elems + .iter() + .map(|value| value.size_of_val(tracker) - mem::size_of_val(value)) + .sum::() + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/lib/wasmer-types/src/entity/secondary_map.rs b/lib/wasmer-types/src/entity/secondary_map.rs index 9fd474d4d1f..ac19c432fb7 100644 --- a/lib/wasmer-types/src/entity/secondary_map.rs +++ b/lib/wasmer-types/src/entity/secondary_map.rs @@ -11,12 +11,14 @@ use crate::lib::std::marker::PhantomData; use crate::lib::std::ops::{Index, IndexMut}; use crate::lib::std::slice; use crate::lib::std::vec::Vec; +use loupe::{MemoryUsage, MemoryUsageTracker}; #[cfg(feature = "enable-serde")] use serde::{ de::{Deserializer, SeqAccess, Visitor}, ser::{SerializeSeq, Serializer}, Deserialize, Serialize, }; +use std::mem; /// A mapping `K -> V` for densely indexed entity references. /// @@ -279,6 +281,21 @@ where } } +impl MemoryUsage for SecondaryMap +where + K: EntityRef, + V: Clone + MemoryUsage, +{ + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + + self + .elems + .iter() + .map(|value| value.size_of_val(tracker) - mem::size_of_val(value)) + .sum::() + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/lib/wasmer-types/src/initializers.rs b/lib/wasmer-types/src/initializers.rs index 0d47554c502..3683ecf04a8 100644 --- a/lib/wasmer-types/src/initializers.rs +++ b/lib/wasmer-types/src/initializers.rs @@ -1,11 +1,12 @@ use crate::indexes::{FunctionIndex, GlobalIndex, MemoryIndex, TableIndex}; use crate::lib::std::boxed::Box; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; /// A WebAssembly table initializer. -#[derive(Clone, Debug, Hash, Serialize, Deserialize)] +#[derive(Clone, Debug, Hash, Serialize, Deserialize, MemoryUsage)] pub struct TableInitializer { /// The index of a table to initialize. pub table_index: TableIndex, @@ -19,7 +20,7 @@ pub struct TableInitializer { /// A memory index and offset within that memory where a data initialization /// should be performed. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct DataInitializerLocation { /// The index of the memory to initialize. @@ -45,7 +46,7 @@ pub struct DataInitializer<'data> { /// As `DataInitializer` but owning the data rather than /// holding a reference to it -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct OwnedDataInitializer { /// The location where the initialization is to be performed. diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs index 168f947616f..3f5d8f5d816 100644 --- a/lib/wasmer-types/src/types.rs +++ b/lib/wasmer-types/src/types.rs @@ -57,7 +57,7 @@ impl fmt::Display for Type { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] /// The WebAssembly V128 type pub struct V128(pub(crate) [u8; 16]); @@ -311,7 +311,7 @@ impl From<&FunctionType> for FunctionType { } /// Indicator of whether a global is mutable or not -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum Mutability { /// The global is constant and its value does not change @@ -347,7 +347,7 @@ impl From for bool { } /// WebAssembly global. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct GlobalType { /// The type of the value stored in the global. @@ -390,7 +390,7 @@ impl fmt::Display for GlobalType { } /// Globals are initialized via the `const` operators or by referring to another import. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum GlobalInit { /// An `i32.const`. @@ -441,7 +441,7 @@ impl GlobalInit { /// Tables are contiguous chunks of a specific element, typically a `funcref` or /// an `externref`. The most common use for tables is a function table through /// which `call_indirect` can invoke other functions. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct TableType { /// The type of data stored in elements of the table. @@ -480,7 +480,7 @@ impl fmt::Display for TableType { /// /// Memories are described in units of pages (64KB) and represent contiguous /// chunks of addressable memory. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct MemoryType { /// The minimum number of pages in the memory. diff --git a/tests/lib/engine-dummy/src/artifact.rs b/tests/lib/engine-dummy/src/artifact.rs index ea542256d06..4467d22056c 100644 --- a/tests/lib/engine-dummy/src/artifact.rs +++ b/tests/lib/engine-dummy/src/artifact.rs @@ -2,6 +2,7 @@ //! done as separate steps. use crate::engine::DummyEngine; +use loupe::MemoryUsage; #[cfg(feature = "serialize")] use serde::{Deserialize, Serialize}; use std::sync::Arc; @@ -21,6 +22,7 @@ use wasmer_vm::{ /// Serializable struct for the artifact #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] +#[derive(MemoryUsage)] pub struct DummyArtifactMetadata { pub module: Arc, pub features: Features, @@ -34,10 +36,11 @@ pub struct DummyArtifactMetadata { /// /// This artifact will point to fake finished functions and trampolines /// as no functions are really compiled. +#[derive(MemoryUsage)] pub struct DummyArtifact { metadata: DummyArtifactMetadata, - finished_functions: BoxedSlice, + #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice,