From 026520998c4042d14b486217acdacb1b3919e758 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 15 Mar 2021 20:28:07 +0100 Subject: [PATCH 01/26] feat: Start implementing `loupe::MemoryUsage` on `wasmer::Store`. --- Cargo.lock | 97 +++++++++++++++-------- lib/api/Cargo.toml | 2 + lib/api/src/store.rs | 3 +- lib/api/src/tunables.rs | 3 +- lib/compiler-cranelift/Cargo.toml | 2 + lib/compiler-cranelift/src/compiler.rs | 2 + lib/compiler-cranelift/src/config.rs | 5 +- lib/compiler-llvm/Cargo.toml | 2 + lib/compiler-llvm/src/compiler.rs | 2 + lib/compiler-llvm/src/config.rs | 5 +- lib/compiler-singlepass/Cargo.toml | 2 + lib/compiler-singlepass/src/compiler.rs | 2 + lib/compiler-singlepass/src/config.rs | 3 +- lib/compiler/Cargo.toml | 2 + lib/compiler/src/compiler.rs | 3 +- lib/compiler/src/target.rs | 5 +- lib/compiler/src/translator/middleware.rs | 3 +- lib/engine-jit/Cargo.toml | 2 + lib/engine-jit/src/code_memory.rs | 2 + lib/engine-jit/src/engine.rs | 4 +- lib/engine-jit/src/unwind/dummy.rs | 2 + lib/engine-jit/src/unwind/systemv.rs | 9 ++- lib/engine-jit/src/unwind/windows_x64.rs | 20 +++++ lib/engine-native/Cargo.toml | 2 + lib/engine-native/src/engine.rs | 14 +++- lib/engine-object-file/Cargo.toml | 2 + lib/engine-object-file/src/engine.rs | 8 +- lib/engine/Cargo.toml | 2 + lib/engine/src/engine.rs | 6 +- lib/engine/src/tunables.rs | 3 +- lib/middlewares/Cargo.toml | 2 + lib/middlewares/src/metering.rs | 12 ++- lib/vm/Cargo.toml | 2 + lib/vm/src/mmap.rs | 9 +++ lib/vm/src/sig_registry.rs | 5 +- lib/vm/src/vmcontext.rs | 3 +- lib/wasmer-types/Cargo.toml | 2 + lib/wasmer-types/src/features.rs | 3 +- lib/wasmer-types/src/indexes.rs | 29 +++---- lib/wasmer-types/src/types.rs | 5 +- lib/wasmer-types/src/units.rs | 3 +- tests/lib/engine-dummy/Cargo.toml | 2 + tests/lib/engine-dummy/src/engine.rs | 3 +- 43 files changed, 225 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb7362058..02001a8e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -545,9 +545,9 @@ dependencies = [ [[package]] name = "csv" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d58633299b24b515ac72a3f869f8b91306a3cec616a602843a383acd6f9e97" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" dependencies = [ "bstr", "csv-core", @@ -941,9 +941,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", @@ -1088,9 +1088,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "libffi" @@ -1154,6 +1154,19 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "loupe" +version = "0.1.0" + +[[package]] +name = "loupe-derive" +version = "0.1.0" +dependencies = [ + "loupe", + "quote", + "syn", +] + [[package]] name = "mach" version = "0.3.2" @@ -1372,9 +1385,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d65c4d95931acda4498f675e332fcbdc9a06705cd07086c510e9b6009cd1c1" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" [[package]] name = "peeking_take_while" @@ -1393,9 +1406,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cf491442e4b033ed1c722cb9f0df5fcfcf4de682466c46469c36bc47dc5548a" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pkg-config" @@ -1627,14 +1640,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.3" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] @@ -1648,9 +1660,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "region" @@ -1825,9 +1837,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] @@ -1853,9 +1865,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2", "quote", @@ -1922,9 +1934,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.60" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" dependencies = [ "proc-macro2", "quote", @@ -2041,15 +2053,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thread_local" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" -dependencies = [ - "once_cell", -] - [[package]] name = "time" version = "0.1.43" @@ -2094,9 +2097,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a9bd1db7706f2373a190b0d067146caa39350c486f3d455b0e33b431f94c07" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" dependencies = [ "proc-macro2", "quote", @@ -2120,9 +2123,9 @@ checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] name = "typenum" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" [[package]] name = "typetag" @@ -2295,6 +2298,8 @@ dependencies = [ "cfg-if 0.1.10", "indexmap", "libc", + "loupe", + "loupe-derive", "more-asserts", "target-lexicon", "tempfile", @@ -2390,6 +2395,8 @@ version = "1.0.2" dependencies = [ "enumset", "hashbrown", + "loupe", + "loupe-derive", "serde", "serde_bytes", "smallvec", @@ -2409,6 +2416,8 @@ dependencies = [ "gimli", "hashbrown", "lazy_static", + "loupe", + "loupe-derive", "more-asserts", "rayon", "serde", @@ -2431,6 +2440,8 @@ dependencies = [ "itertools 0.10.0", "lazy_static", "libc", + "loupe", + "loupe-derive", "rayon", "regex", "rustc_version 0.2.3", @@ -2451,6 +2462,8 @@ dependencies = [ "dynasmrt", "hashbrown", "lazy_static", + "loupe", + "loupe-derive", "more-asserts", "rayon", "serde", @@ -2493,6 +2506,8 @@ dependencies = [ "backtrace", "bincode", "lazy_static", + "loupe", + "loupe-derive", "memmap2", "more-asserts", "rustc-demangle", @@ -2510,6 +2525,8 @@ name = "wasmer-engine-dummy" version = "1.0.2" dependencies = [ "bincode", + "loupe", + "loupe-derive", "serde", "serde_bytes", "wasmer-compiler", @@ -2524,6 +2541,8 @@ version = "1.0.2" dependencies = [ "bincode", "cfg-if 0.1.10", + "loupe", + "loupe-derive", "region", "serde", "serde_bytes", @@ -2542,6 +2561,8 @@ dependencies = [ "cfg-if 0.1.10", "leb128", "libloading", + "loupe", + "loupe-derive", "serde", "tempfile", "tracing", @@ -2561,6 +2582,8 @@ dependencies = [ "cfg-if 0.1.10", "leb128", "libloading", + "loupe", + "loupe-derive", "serde", "tempfile", "tracing", @@ -2583,6 +2606,8 @@ dependencies = [ name = "wasmer-middlewares" version = "1.0.2" dependencies = [ + "loupe", + "loupe-derive", "wasmer", "wasmer-types", "wasmer-vm", @@ -2603,6 +2628,8 @@ name = "wasmer-types" version = "1.0.2" dependencies = [ "cranelift-entity", + "loupe", + "loupe-derive", "serde", "thiserror", ] @@ -2616,6 +2643,8 @@ dependencies = [ "cfg-if 0.1.10", "indexmap", "libc", + "loupe", + "loupe-derive", "memoffset", "more-asserts", "region", diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index f9286c04c..a7b7a9945 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -27,6 +27,8 @@ wat = { version = "1.0", optional = true } thiserror = "1.0" more-asserts = "0.2" target-lexicon = { version = "0.11", default-features = false } +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [target.'cfg(target_os = "windows")'.dependencies] winapi = "0.3" diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index 661375082..0e21f9048 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -1,4 +1,5 @@ use crate::tunables::BaseTunables; +use loupe_derive::MemoryUsage; use std::fmt; use std::sync::Arc; #[cfg(all(feature = "compiler", feature = "engine"))] @@ -15,7 +16,7 @@ use wasmer_engine::{Engine, Tunables}; /// [`Tunables`] (that are used to create the memories, tables and globals). /// /// Spec: -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct Store { engine: Arc, tunables: Arc, diff --git a/lib/api/src/tunables.rs b/lib/api/src/tunables.rs index 242540001..30d09521f 100644 --- a/lib/api/src/tunables.rs +++ b/lib/api/src/tunables.rs @@ -1,4 +1,5 @@ use crate::{MemoryType, Pages, TableType}; +use loupe_derive::MemoryUsage; use std::cmp::min; use std::ptr::NonNull; use std::sync::Arc; @@ -19,7 +20,7 @@ use wasmer_vm::{ /// implementation or use composition to wrap your Tunables around /// this one. The later approach is demonstrated in the /// tunables-limit-memory example. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct BaseTunables { /// For static heaps, the size in wasm pages of the heap protected by bounds checking. pub static_memory_bound: Pages, diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index 9a2c809f5..54cb0fba1 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -24,6 +24,8 @@ serde = { version = "1.0", features = ["derive"] } more-asserts = "0.2" gimli = { version = "0.23", optional = true } smallvec = "1.6" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index 9b28a0a3a..180735775 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -18,6 +18,7 @@ use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::{binemit, Context}; #[cfg(feature = "unwind")] use gimli::write::{Address, EhFrame, FrameTable}; +use loupe_derive::MemoryUsage; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; use wasmer_compiler::CompileError; @@ -32,6 +33,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, SignatureIndex}; /// A compiler that compiles a WebAssembly module with Cranelift, translating the Wasm to Cranelift IR, /// optimizing it and then translating to assembly. +#[derive(MemoryUsage)] pub struct CraneliftCompiler { config: Cranelift, } diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index 5a7b671b3..ac639e94e 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -1,6 +1,7 @@ use crate::compiler::CraneliftCompiler; use cranelift_codegen::isa::{lookup, TargetIsa}; use cranelift_codegen::settings::{self, Configurable}; +use loupe_derive::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{ Architecture, Compiler, CompilerConfig, CpuFeature, ModuleMiddleware, Target, @@ -10,7 +11,7 @@ use wasmer_compiler::{ /// Possible optimization levels for the Cranelift codegen backend. #[non_exhaustive] -#[derive(Clone, Debug)] +#[derive(Clone, Debug, MemoryUsage)] pub enum CraneliftOptLevel { /// No optimizations performed, minimizes compilation time by disabling most /// optimizations. @@ -27,7 +28,7 @@ pub enum CraneliftOptLevel { /// /// This structure exposes a builder-like interface and is primarily /// consumed by `wasmer_engine::Engine::new`. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct Cranelift { enable_nan_canonicalization: bool, enable_verifier: bool, diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index ce5159448..ae97a0f4c 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -22,6 +22,8 @@ libc = { version = "^0.2", default-features = false } byteorder = "1" itertools = "0.10" rayon = "1.5" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [dependencies.inkwell] version = "=0.1.0-beta.2" diff --git a/lib/compiler-llvm/src/compiler.rs b/lib/compiler-llvm/src/compiler.rs index d08f34bad..5ea1c9f8f 100644 --- a/lib/compiler-llvm/src/compiler.rs +++ b/lib/compiler-llvm/src/compiler.rs @@ -7,6 +7,7 @@ use inkwell::memory_buffer::MemoryBuffer; use inkwell::module::{Linkage, Module}; use inkwell::targets::FileType; use inkwell::DLLStorageClass; +use loupe_derive::MemoryUsage; use rayon::iter::ParallelBridge; use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; @@ -22,6 +23,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, SignatureIndex}; /// A compiler that compiles a WebAssembly module with LLVM, translating the Wasm to LLVM IR, /// optimizing it and then translating to assembly. +#[derive(MemoryUsage)] pub struct LLVMCompiler { config: LLVM, } diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 6ae8085aa..66af408fe 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -5,6 +5,7 @@ use inkwell::targets::{ }; pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; +use loupe_derive::MemoryUsage; use std::fmt::Debug; use std::sync::Arc; use target_lexicon::Architecture; @@ -37,12 +38,14 @@ pub trait LLVMCallbacks: Debug + Send + Sync { fn obj_memory_buffer(&self, function: &CompiledKind, memory_buffer: &InkwellMemoryBuffer); } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct LLVM { pub(crate) enable_nan_canonicalization: bool, pub(crate) enable_verifier: bool, + #[memoryusage(ignore)] pub(crate) opt_level: LLVMOptLevel, is_pic: bool, + #[memoryusage(ignore)] pub(crate) callbacks: Option>, /// The middleware chain. pub(crate) middlewares: Vec>, diff --git a/lib/compiler-singlepass/Cargo.toml b/lib/compiler-singlepass/Cargo.toml index 2c771c8c5..38e2f178f 100644 --- a/lib/compiler-singlepass/Cargo.toml +++ b/lib/compiler-singlepass/Cargo.toml @@ -24,6 +24,8 @@ dynasmrt = "1.0" lazy_static = "1.4" byteorder = "1.3" smallvec = "1.6" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler-singlepass/src/compiler.rs b/lib/compiler-singlepass/src/compiler.rs index 0f2f6520b..51a520f61 100644 --- a/lib/compiler-singlepass/src/compiler.rs +++ b/lib/compiler-singlepass/src/compiler.rs @@ -7,6 +7,7 @@ use crate::codegen_x64::{ CodegenError, FuncGen, }; use crate::config::Singlepass; +use loupe_derive::MemoryUsage; use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; use wasmer_compiler::TrapInformation; @@ -22,6 +23,7 @@ use wasmer_vm::{ModuleInfo, TrapCode, VMOffsets}; /// A compiler that compiles a WebAssembly module with Singlepass. /// It does the compilation in one pass +#[derive(MemoryUsage)] pub struct SinglepassCompiler { config: Singlepass, } diff --git a/lib/compiler-singlepass/src/config.rs b/lib/compiler-singlepass/src/config.rs index 669b8be07..2426db66d 100644 --- a/lib/compiler-singlepass/src/config.rs +++ b/lib/compiler-singlepass/src/config.rs @@ -2,11 +2,12 @@ #![allow(unused_imports, dead_code)] use crate::compiler::SinglepassCompiler; +use loupe_derive::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{Compiler, CompilerConfig, CpuFeature, ModuleMiddleware, Target}; use wasmer_types::Features; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct Singlepass { pub(crate) enable_nan_canonicalization: bool, pub(crate) enable_stack_check: bool, diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index 92625b684..91a83a26a 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -21,6 +21,8 @@ serde = { version = "1.0", features = ["derive"], optional = true } thiserror = "1.0" serde_bytes = { version = "0.11", optional = true } smallvec = "1.6" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [features] default = ["std", "enable-serde"] diff --git a/lib/compiler/src/compiler.rs b/lib/compiler/src/compiler.rs index db2313b4a..eff21365c 100644 --- a/lib/compiler/src/compiler.rs +++ b/lib/compiler/src/compiler.rs @@ -11,6 +11,7 @@ use crate::translator::ModuleMiddleware; use crate::FunctionBodyData; use crate::ModuleTranslationState; use crate::SectionIndex; +use loupe::MemoryUsage; use wasmer_types::entity::PrimaryMap; use wasmer_types::{Features, FunctionIndex, LocalFunctionIndex, SignatureIndex}; use wasmparser::{Validator, WasmFeatures}; @@ -58,7 +59,7 @@ where } /// An implementation of a Compiler from parsed WebAssembly module to Compiled native code. -pub trait Compiler: Send { +pub trait Compiler: Send + MemoryUsage { /// Validates a module. /// /// It returns the a succesful Result in case is valid, `CompileError` in case is not. diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 9d18d79e8..bc5da48df 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,6 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; +use loupe_derive::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, @@ -160,9 +161,11 @@ impl ToString for CpuFeature { /// This is the target that we will use for compiling /// the WebAssembly ModuleInfo, and then run it. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, MemoryUsage)] pub struct Target { + #[memoryusage(ignore)] triple: Triple, + #[memoryusage(ignore)] cpu_features: EnumSet, } diff --git a/lib/compiler/src/translator/middleware.rs b/lib/compiler/src/translator/middleware.rs index 5efcc562f..3dd8c6aed 100644 --- a/lib/compiler/src/translator/middleware.rs +++ b/lib/compiler/src/translator/middleware.rs @@ -1,6 +1,7 @@ //! The middleware parses the function binary bytecodes and transform them //! with the chosen functions. +use loupe::MemoryUsage; use smallvec::SmallVec; use std::collections::VecDeque; use std::fmt::Debug; @@ -12,7 +13,7 @@ use wasmparser::{BinaryReader, Operator, Type}; use crate::error::{MiddlewareError, WasmResult}; /// A shared builder for function middlewares. -pub trait ModuleMiddleware: Debug + Send + Sync { +pub trait ModuleMiddleware: Debug + Send + Sync + MemoryUsage { /// Generates a `FunctionMiddleware` for a given function. /// /// Here we generate a separate object for each function instead of executing directly on per-function operators, diff --git a/lib/engine-jit/Cargo.toml b/lib/engine-jit/Cargo.toml index a4d1c6f90..bbe11a705 100644 --- a/lib/engine-jit/Cargo.toml +++ b/lib/engine-jit/Cargo.toml @@ -21,6 +21,8 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" cfg-if = "0.1" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winnt", "impl-default"] } diff --git a/lib/engine-jit/src/code_memory.rs b/lib/engine-jit/src/code_memory.rs index 3d23e1eda..e6a6a4fab 100644 --- a/lib/engine-jit/src/code_memory.rs +++ b/lib/engine-jit/src/code_memory.rs @@ -3,6 +3,7 @@ //! Memory management for executable code. use crate::unwind::UnwindRegistry; +use loupe_derive::MemoryUsage; use wasmer_compiler::{CompiledFunctionUnwindInfo, CustomSection, FunctionBody}; use wasmer_vm::{Mmap, VMFunctionBody}; @@ -18,6 +19,7 @@ const ARCH_FUNCTION_ALIGNMENT: usize = 16; const DATA_SECTION_ALIGNMENT: usize = 64; /// Memory manager for executable code. +#[derive(MemoryUsage)] pub struct CodeMemory { unwind_registry: UnwindRegistry, mmap: Mmap, diff --git a/lib/engine-jit/src/engine.rs b/lib/engine-jit/src/engine.rs index c3ff020ff..bac823659 100644 --- a/lib/engine-jit/src/engine.rs +++ b/lib/engine-jit/src/engine.rs @@ -1,6 +1,7 @@ //! JIT compilation. use crate::{CodeMemory, JITArtifact}; +use loupe_derive::MemoryUsage; use std::sync::{Arc, Mutex}; #[cfg(feature = "compiler")] use wasmer_compiler::Compiler; @@ -17,7 +18,7 @@ use wasmer_vm::{ }; /// A WebAssembly `JIT` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct JITEngine { inner: Arc>, /// The target for the compiler @@ -138,6 +139,7 @@ impl Engine for JITEngine { } /// The inner contents of `JITEngine` +#[derive(MemoryUsage)] pub struct JITEngineInner { /// The compiler #[cfg(feature = "compiler")] diff --git a/lib/engine-jit/src/unwind/dummy.rs b/lib/engine-jit/src/unwind/dummy.rs index 3d029ecd9..4cd69926c 100644 --- a/lib/engine-jit/src/unwind/dummy.rs +++ b/lib/engine-jit/src/unwind/dummy.rs @@ -1,9 +1,11 @@ //! Module for Dummy unwind registry. +use loupe_derive::MemoryUsage; use wasmer_compiler::CompiledFunctionUnwindInfo; /// Represents a registry of function unwind information when the host system /// support any one in specific. +#[derive(MemoryUsage)] pub struct DummyUnwindRegistry {} impl DummyUnwindRegistry { diff --git a/lib/engine-jit/src/unwind/systemv.rs b/lib/engine-jit/src/unwind/systemv.rs index d08ea7780..573ac08b1 100644 --- a/lib/engine-jit/src/unwind/systemv.rs +++ b/lib/engine-jit/src/unwind/systemv.rs @@ -2,9 +2,12 @@ // Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md //! Module for System V ABI unwind registry. + +use loupe_derive::MemoryUsage; use wasmer_compiler::CompiledFunctionUnwindInfo; /// Represents a registry of function unwind information for System V ABI. +#[derive(MemoryUsage)] pub struct UnwindRegistry { registrations: Vec, published: bool, @@ -65,7 +68,11 @@ impl UnwindRegistry { // deregistering it. We must avoid this // scenario. Usually, this is handled upstream by the // compilers. - debug_assert_ne!(eh_frame, &[0, 0, 0, 0], "`eh_frame` seems to contain empty FDEs"); + debug_assert_ne!( + eh_frame, + &[0, 0, 0, 0], + "`eh_frame` seems to contain empty FDEs" + ); // On gnu (libgcc), `__register_frame` will walk the FDEs until an entry of length 0 let ptr = eh_frame.as_ptr(); diff --git a/lib/engine-jit/src/unwind/windows_x64.rs b/lib/engine-jit/src/unwind/windows_x64.rs index 96cac3923..1db1658ac 100644 --- a/lib/engine-jit/src/unwind/windows_x64.rs +++ b/lib/engine-jit/src/unwind/windows_x64.rs @@ -2,6 +2,7 @@ // Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md //! Module for Windows x64 ABI unwind registry. +use loupe::{MemoryUsage, MemoryUsageTracker}; use std::collections::HashMap; use wasmer_compiler::CompiledFunctionUnwindInfo; use winapi::um::winnt; @@ -103,3 +104,22 @@ impl Drop for UnwindRegistry { } } } + +impl MemoryUsage for UnwindRegistry { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + // To count `RUNTIME_FUNCTION`, we first check the + // [documentation][doc1]. We see that it's a type alias to + // `_IMAGE_RUNTIME_FUNCTION_ENTRY`, let's check the + // [documentation][doc2]. It's composed of two `DWORD`, so two + // `u64`, and one `IMAGE_RUNTIME_FUNCTION_ENTRY_u`, which we + // approximate to size of `u64`. + // + // [doc1]: https://docs.rs/winapi/0.3.9/winapi/um/winnt/type.RUNTIME_FUNCTION.html + // [doc2]: https://docs.rs/winapi/0.3.9/winapi/um/winnt/struct._IMAGE_RUNTIME_FUNCTION_ENTRY.html + self.functions + .iter() + .map(|(key, _)| (key, std::mem::size_of::() * 3)) + .sum::() + + self.published.size_of_val(tracker) + } +} diff --git a/lib/engine-native/Cargo.toml b/lib/engine-native/Cargo.toml index c8f5c125d..c875b0f50 100644 --- a/lib/engine-native/Cargo.toml +++ b/lib/engine-native/Cargo.toml @@ -24,6 +24,8 @@ leb128 = "0.2" libloading = "0.7" tempfile = "3.1" which = "4.0" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 03d49d642..bcfb28d40 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,6 +2,7 @@ use crate::NativeArtifact; use libloading::Library; +use loupe_derive::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; @@ -15,7 +16,7 @@ use wasmer_types::FunctionType; use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex}; /// A WebAssembly `Native` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct NativeEngine { inner: Arc>, /// The target for the compiler @@ -174,7 +175,7 @@ impl Engine for NativeEngine { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, MemoryUsage)] pub(crate) enum Linker { None, Clang11, @@ -219,25 +220,34 @@ impl Linker { } /// The inner contents of `NativeEngine` +#[derive(MemoryUsage)] pub struct NativeEngineInner { /// The compiler #[cfg(feature = "compiler")] compiler: Option>, + /// The WebAssembly features to use #[cfg(feature = "compiler")] features: Features, + /// The signature registry is used mainly to operate with trampolines /// performantly. signatures: SignatureRegistry, + /// The prefixer returns the a String to prefix each of /// the functions in the shared object generated by the `NativeEngine`, /// so we can assure no collisions. + #[memoryusage(ignore)] prefixer: Option String + Send>>, + /// Whether the native engine will cross-compile. is_cross_compiling: bool, + /// The linker to use. linker: Linker, + /// List of libraries loaded by this engine. + #[memoryusage(ignore)] libraries: Vec, } diff --git a/lib/engine-object-file/Cargo.toml b/lib/engine-object-file/Cargo.toml index 36a0ee634..f78e1d699 100644 --- a/lib/engine-object-file/Cargo.toml +++ b/lib/engine-object-file/Cargo.toml @@ -23,6 +23,8 @@ bincode = "1.3" leb128 = "0.2" libloading = "0.7" tempfile = "3.1" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine-object-file/src/engine.rs b/lib/engine-object-file/src/engine.rs index 3f00db119..a3f051f82 100644 --- a/lib/engine-object-file/src/engine.rs +++ b/lib/engine-object-file/src/engine.rs @@ -1,4 +1,5 @@ use crate::ObjectFileArtifact; +use loupe_derive::MemoryUsage; use std::io::Read; use std::path::Path; use std::sync::{Arc, Mutex}; @@ -12,7 +13,7 @@ use wasmer_types::FunctionType; use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex}; /// A WebAssembly `ObjectFile` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct ObjectFileEngine { inner: Arc>, /// The target for the compiler @@ -165,19 +166,24 @@ impl Engine for ObjectFileEngine { } /// The inner contents of `ObjectFileEngine` +#[derive(MemoryUsage)] pub struct ObjectFileEngineInner { /// The compiler #[cfg(feature = "compiler")] compiler: Option>, + /// The WebAssembly features to use #[cfg(feature = "compiler")] features: Features, + /// The signature registry is used mainly to operate with trampolines /// performantly. signatures: SignatureRegistry, + /// The prefixer returns the a String to prefix each of /// the functions in the shared object generated by the `ObjectFileEngine`, /// so we can assure no collisions. + #[memoryusage(ignore)] prefixer: Option String + Send>>, } diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml index eab531b0f..55c4a4ed8 100644 --- a/lib/engine/Cargo.toml +++ b/lib/engine/Cargo.toml @@ -25,6 +25,8 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" lazy_static = "1.4" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [badges] maintenance = { status = "actively-developed" } diff --git a/lib/engine/src/engine.rs b/lib/engine/src/engine.rs index 8cfceb3a8..9eed69ac6 100644 --- a/lib/engine/src/engine.rs +++ b/lib/engine/src/engine.rs @@ -2,6 +2,8 @@ use crate::tunables::Tunables; use crate::{Artifact, DeserializeError}; +use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use memmap2::Mmap; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; @@ -16,7 +18,7 @@ use wasmer_vm::VMSharedSignatureIndex; /// such as: JIT or Native. /// /// The product that an `Engine` produces and consumes is the [`Artifact`]. -pub trait Engine { +pub trait Engine: MemoryUsage { /// Gets the target fn target(&self) -> &Target; @@ -68,7 +70,7 @@ pub trait Engine { fn cloned(&self) -> Arc; } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[repr(transparent)] /// A unique identifier for an Engine. pub struct EngineId { diff --git a/lib/engine/src/tunables.rs b/lib/engine/src/tunables.rs index 7d3de7291..adad964c6 100644 --- a/lib/engine/src/tunables.rs +++ b/lib/engine/src/tunables.rs @@ -1,4 +1,5 @@ use crate::error::LinkError; +use loupe::MemoryUsage; use std::ptr::NonNull; use std::sync::Arc; use wasmer_types::entity::{EntityRef, PrimaryMap}; @@ -13,7 +14,7 @@ use wasmer_vm::{VMMemoryDefinition, VMTableDefinition}; /// An engine delegates the creation of memories, tables, and globals /// to a foreign implementor of this trait. -pub trait Tunables { +pub trait Tunables: MemoryUsage { /// Construct a `MemoryStyle` for the provided `MemoryType` fn memory_style(&self, memory: &MemoryType) -> MemoryStyle; diff --git a/lib/middlewares/Cargo.toml b/lib/middlewares/Cargo.toml index 6ffde00e3..ebbd3e755 100644 --- a/lib/middlewares/Cargo.toml +++ b/lib/middlewares/Cargo.toml @@ -14,6 +14,8 @@ edition = "2018" wasmer = { path = "../api", version = "1.0.2" } wasmer-types = { path = "../wasmer-types", version = "1.0.2" } wasmer-vm = { path = "../vm", version = "1.0.2" } +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [badges] maintenance = { status = "actively-developed" } diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index 94a07df28..b3ddc029a 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -1,8 +1,11 @@ //! `metering` is a middleware for tracking how many operators are executed in total //! and putting a limit on the total number of operators executed. +use loupe::{MemoryUsage, MemoryUsageTracker}; +use loupe_derive::MemoryUsage; use std::convert::TryInto; use std::fmt; +use std::mem; use std::sync::{Arc, Mutex}; use wasmer::wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}; use wasmer::{ @@ -12,7 +15,7 @@ use wasmer::{ use wasmer_types::GlobalIndex; use wasmer_vm::ModuleInfo; -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] struct MeteringGlobalIndexes(GlobalIndex, GlobalIndex); impl MeteringGlobalIndexes { @@ -154,6 +157,13 @@ impl u64 + Send + Sync + 'static> ModuleMiddleware for Meter } } +impl u64 + Send + Sync + 'static> MemoryUsage for Metering { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + self.global_indexes.size_of_val(tracker) + - mem::size_of_val(&self.global_indexes) + } +} + impl u64 + Send + Sync> fmt::Debug for FunctionMetering { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("FunctionMetering") diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index 5f1c88d10..4d55a8625 100644 --- a/lib/vm/Cargo.toml +++ b/lib/vm/Cargo.toml @@ -21,6 +21,8 @@ more-asserts = "0.2" cfg-if = "0.1" backtrace = "0.3" serde = { version = "1.0", features = ["derive", "rc"] } +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] } diff --git a/lib/vm/src/mmap.rs b/lib/vm/src/mmap.rs index 6b3dcdd19..7f33e8862 100644 --- a/lib/vm/src/mmap.rs +++ b/lib/vm/src/mmap.rs @@ -4,6 +4,7 @@ //! Low-level abstraction for allocating and managing zero-filled pages //! of memory. +use loupe::{MemoryUsage, MemoryUsageTracker}; use more_asserts::assert_le; use more_asserts::assert_lt; use std::io; @@ -279,6 +280,14 @@ impl Drop for Mmap { } } +impl MemoryUsage for Mmap { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + tracker.track(self.as_ptr() as *const ()); + + self.len() + } +} + fn _assert() { fn _assert_send_sync() {} _assert_send_sync::(); diff --git a/lib/vm/src/sig_registry.rs b/lib/vm/src/sig_registry.rs index 58b690fc6..b0da474eb 100644 --- a/lib/vm/src/sig_registry.rs +++ b/lib/vm/src/sig_registry.rs @@ -5,6 +5,7 @@ //! signature checking. use crate::vmcontext::VMSharedSignatureIndex; +use loupe_derive::MemoryUsage; use more_asserts::{assert_lt, debug_assert_lt}; use std::collections::{hash_map, HashMap}; use std::convert::TryFrom; @@ -15,7 +16,7 @@ use wasmer_types::FunctionType; /// call must match. To implement this efficiently, keep a registry of all /// signatures, shared by all instances, so that call sites can just do an /// index comparison. -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] pub struct SignatureRegistry { // This structure is stored in an `Engine` and is intended to be shared // across many instances. Ideally instances can themselves be sent across @@ -25,7 +26,7 @@ pub struct SignatureRegistry { inner: RwLock, } -#[derive(Debug, Default)] +#[derive(Debug, Default, MemoryUsage)] struct Inner { signature2index: HashMap, index2signature: HashMap, diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index 4e50eb459..7262be3cb 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -9,6 +9,7 @@ use crate::instance::Instance; use crate::memory::Memory; use crate::table::Table; use crate::trap::{Trap, TrapCode}; +use loupe_derive::MemoryUsage; use std::any::Any; use std::convert::TryFrom; use std::fmt; @@ -705,7 +706,7 @@ impl VMGlobalDefinition { /// An index into the shared signature registry, usable for checking signatures /// at indirect calls. #[repr(C)] -#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] +#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash, MemoryUsage)] pub struct VMSharedSignatureIndex(u32); #[cfg(test)] diff --git a/lib/wasmer-types/Cargo.toml b/lib/wasmer-types/Cargo.toml index 9f56e3361..fbfebc320 100644 --- a/lib/wasmer-types/Cargo.toml +++ b/lib/wasmer-types/Cargo.toml @@ -16,6 +16,8 @@ edition = "2018" cranelift-entity = "0.70" serde = { version = "1.0", features = ["derive"], optional = true, default-features = false } thiserror = "1.0" +loupe = { path = "../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../loupe/crates/loupe-derive" } [features] default = ["std", "enable-serde"] diff --git a/lib/wasmer-types/src/features.rs b/lib/wasmer-types/src/features.rs index 557c4e632..a051bcfbd 100644 --- a/lib/wasmer-types/src/features.rs +++ b/lib/wasmer-types/src/features.rs @@ -1,3 +1,4 @@ +use loupe_derive::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -5,7 +6,7 @@ use serde::{Deserialize, Serialize}; /// Features usually have a corresponding [WebAssembly proposal]. /// /// [WebAssembly proposal]: https://github.com/WebAssembly/proposals -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct Features { /// Threads proposal should be enabled diff --git a/lib/wasmer-types/src/indexes.rs b/lib/wasmer-types/src/indexes.rs index 7c2247f8e..06ba01caa 100644 --- a/lib/wasmer-types/src/indexes.rs +++ b/lib/wasmer-types/src/indexes.rs @@ -1,83 +1,84 @@ //! Helper functions and structures for the translation. use crate::entity::entity_impl; use core::u32; +use loupe_derive::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; /// Index type of a function defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalFunctionIndex(u32); entity_impl!(LocalFunctionIndex); /// Index type of a table defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalTableIndex(u32); entity_impl!(LocalTableIndex); /// Index type of a memory defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalMemoryIndex(u32); entity_impl!(LocalMemoryIndex); /// Index type of a global defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalGlobalIndex(u32); entity_impl!(LocalGlobalIndex); /// Index type of a function (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct FunctionIndex(u32); entity_impl!(FunctionIndex); /// Index type of a table (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct TableIndex(u32); entity_impl!(TableIndex); /// Index type of a global variable (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct GlobalIndex(u32); entity_impl!(GlobalIndex); /// Index type of a linear memory (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct MemoryIndex(u32); entity_impl!(MemoryIndex); /// Index type of a signature (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct SignatureIndex(u32); entity_impl!(SignatureIndex); /// Index type of a passive data segment inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct DataIndex(u32); entity_impl!(DataIndex); /// Index type of a passive element segment inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct ElemIndex(u32); entity_impl!(ElemIndex); /// Index type of a custom section inside a WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct CustomSectionIndex(u32); entity_impl!(CustomSectionIndex); /// An entity to export. -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum ExportIndex { /// Function export. @@ -91,7 +92,7 @@ pub enum ExportIndex { } /// An entity to import. -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum ImportIndex { /// Function import. diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs index 6a9b9b9ab..3482d42a8 100644 --- a/lib/wasmer-types/src/types.rs +++ b/lib/wasmer-types/src/types.rs @@ -6,6 +6,7 @@ use crate::lib::std::string::{String, ToString}; use crate::lib::std::vec::Vec; use crate::units::Pages; use crate::values::Value; +use loupe_derive::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize}; // Value Types /// A list of all possible value types in WebAssembly. -#[derive(Copy, Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Copy, Debug, Clone, Eq, PartialEq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum Type { /// Signed 32 bit integer. @@ -225,7 +226,7 @@ impl ExternType { /// in a Wasm module or exposed to Wasm by the host. /// /// WebAssembly functions can have 0 or more parameters and results. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct FunctionType { /// The parameters of the function diff --git a/lib/wasmer-types/src/units.rs b/lib/wasmer-types/src/units.rs index 93e9f04d4..703006167 100644 --- a/lib/wasmer-types/src/units.rs +++ b/lib/wasmer-types/src/units.rs @@ -1,6 +1,7 @@ use crate::lib::std::convert::TryFrom; use crate::lib::std::fmt; use crate::lib::std::ops::{Add, Sub}; +use loupe_derive::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use std::convert::TryInto; @@ -19,7 +20,7 @@ pub const WASM_MAX_PAGES: u32 = 0x10000; pub const WASM_MIN_PAGES: u32 = 0x100; /// Units of WebAssembly pages (as specified to be 65,536 bytes). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct Pages(pub u32); diff --git a/tests/lib/engine-dummy/Cargo.toml b/tests/lib/engine-dummy/Cargo.toml index 22c659d64..3a81e5ef5 100644 --- a/tests/lib/engine-dummy/Cargo.toml +++ b/tests/lib/engine-dummy/Cargo.toml @@ -15,6 +15,8 @@ wasmer-engine = { path = "../../../lib/engine", version = "1.0.2" } serde = { version = "1.0", features = ["derive", "rc"], optional = true } serde_bytes = { version = "0.11", optional = true } bincode = { version = "1.2", optional = true } +loupe = { path = "../../../../loupe/crates/loupe" } +loupe-derive = { path = "../../../../loupe/crates/loupe-derive" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/tests/lib/engine-dummy/src/engine.rs b/tests/lib/engine-dummy/src/engine.rs index bdfab9885..0135bd391 100644 --- a/tests/lib/engine-dummy/src/engine.rs +++ b/tests/lib/engine-dummy/src/engine.rs @@ -1,6 +1,7 @@ //! Dummy Engine. use crate::DummyArtifact; +use loupe_derive::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{CompileError, Features, Target}; use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables}; @@ -17,7 +18,7 @@ extern "C" fn dummy_trampoline( } /// A WebAssembly `Dummy` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct DummyEngine { signatures: Arc, features: Arc, From 2afed4d813265e31ec7693fa489201b2c14a91eb Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 22 Mar 2021 11:38:25 +0100 Subject: [PATCH 02/26] feat: Use latest version of `loupe`. --- Cargo.lock | 20 ++++++-------------- lib/api/Cargo.toml | 3 +-- lib/api/src/store.rs | 2 +- lib/api/src/tunables.rs | 2 +- lib/compiler-cranelift/Cargo.toml | 3 +-- lib/compiler-cranelift/src/compiler.rs | 2 +- lib/compiler-cranelift/src/config.rs | 2 +- lib/compiler-llvm/Cargo.toml | 3 +-- lib/compiler-llvm/src/compiler.rs | 2 +- lib/compiler-llvm/src/config.rs | 6 +++--- lib/compiler-singlepass/Cargo.toml | 3 +-- lib/compiler-singlepass/src/compiler.rs | 2 +- lib/compiler-singlepass/src/config.rs | 2 +- lib/compiler/Cargo.toml | 3 +-- lib/compiler/src/target.rs | 6 +++--- lib/engine-jit/Cargo.toml | 3 +-- lib/engine-jit/src/code_memory.rs | 2 +- lib/engine-jit/src/engine.rs | 2 +- lib/engine-jit/src/unwind/dummy.rs | 2 +- lib/engine-jit/src/unwind/systemv.rs | 2 +- lib/engine-native/Cargo.toml | 3 +-- lib/engine-native/src/engine.rs | 6 +++--- lib/engine-object-file/Cargo.toml | 3 +-- lib/engine-object-file/src/engine.rs | 4 ++-- lib/engine/Cargo.toml | 3 +-- lib/engine/src/engine.rs | 1 - lib/middlewares/Cargo.toml | 3 +-- lib/middlewares/src/metering.rs | 1 - lib/vm/Cargo.toml | 3 +-- lib/vm/src/sig_registry.rs | 2 +- lib/vm/src/vmcontext.rs | 2 +- lib/wasmer-types/Cargo.toml | 3 +-- lib/wasmer-types/src/features.rs | 2 +- lib/wasmer-types/src/indexes.rs | 2 +- lib/wasmer-types/src/types.rs | 2 +- lib/wasmer-types/src/units.rs | 2 +- tests/lib/engine-dummy/Cargo.toml | 3 +-- tests/lib/engine-dummy/src/engine.rs | 2 +- 38 files changed, 48 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e27efa31d..3ebaca6ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1157,12 +1157,17 @@ dependencies = [ [[package]] name = "loupe" version = "0.1.0" +source = "git+https://github.com/wasmerio/loupe?branch=master#63c2f4a5acf1f3a8ed3568119cad96a731c71d21" +dependencies = [ + "loupe-derive", + "rustversion", +] [[package]] name = "loupe-derive" version = "0.1.0" +source = "git+https://github.com/wasmerio/loupe?branch=master#63c2f4a5acf1f3a8ed3568119cad96a731c71d21" dependencies = [ - "loupe", "quote", "syn", ] @@ -2299,7 +2304,6 @@ dependencies = [ "indexmap", "libc", "loupe", - "loupe-derive", "more-asserts", "target-lexicon", "tempfile", @@ -2396,7 +2400,6 @@ dependencies = [ "enumset", "hashbrown", "loupe", - "loupe-derive", "serde", "serde_bytes", "smallvec", @@ -2418,7 +2421,6 @@ dependencies = [ "hashbrown", "lazy_static", "loupe", - "loupe-derive", "more-asserts", "rayon", "serde", @@ -2442,7 +2444,6 @@ dependencies = [ "lazy_static", "libc", "loupe", - "loupe-derive", "rayon", "regex", "rustc_version 0.2.3", @@ -2464,7 +2465,6 @@ dependencies = [ "hashbrown", "lazy_static", "loupe", - "loupe-derive", "more-asserts", "rayon", "serde", @@ -2508,7 +2508,6 @@ dependencies = [ "bincode", "lazy_static", "loupe", - "loupe-derive", "memmap2", "more-asserts", "rustc-demangle", @@ -2527,7 +2526,6 @@ version = "1.0.2" dependencies = [ "bincode", "loupe", - "loupe-derive", "serde", "serde_bytes", "wasmer-compiler", @@ -2543,7 +2541,6 @@ dependencies = [ "bincode", "cfg-if 0.1.10", "loupe", - "loupe-derive", "region", "serde", "serde_bytes", @@ -2563,7 +2560,6 @@ dependencies = [ "leb128", "libloading", "loupe", - "loupe-derive", "serde", "tempfile", "tracing", @@ -2584,7 +2580,6 @@ dependencies = [ "leb128", "libloading", "loupe", - "loupe-derive", "serde", "tempfile", "tracing", @@ -2608,7 +2603,6 @@ name = "wasmer-middlewares" version = "1.0.2" dependencies = [ "loupe", - "loupe-derive", "wasmer", "wasmer-types", "wasmer-vm", @@ -2629,7 +2623,6 @@ name = "wasmer-types" version = "1.0.2" dependencies = [ "loupe", - "loupe-derive", "serde", "thiserror", ] @@ -2644,7 +2637,6 @@ dependencies = [ "indexmap", "libc", "loupe", - "loupe-derive", "memoffset", "more-asserts", "region", diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index a7b7a9945..f69280e6d 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -27,8 +27,7 @@ wat = { version = "1.0", optional = true } thiserror = "1.0" more-asserts = "0.2" target-lexicon = { version = "0.11", default-features = false } -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [target.'cfg(target_os = "windows")'.dependencies] winapi = "0.3" diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index 0e21f9048..2371fd18b 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -1,5 +1,5 @@ use crate::tunables::BaseTunables; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt; use std::sync::Arc; #[cfg(all(feature = "compiler", feature = "engine"))] diff --git a/lib/api/src/tunables.rs b/lib/api/src/tunables.rs index 30d09521f..d714ffd60 100644 --- a/lib/api/src/tunables.rs +++ b/lib/api/src/tunables.rs @@ -1,5 +1,5 @@ use crate::{MemoryType, Pages, TableType}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::cmp::min; use std::ptr::NonNull; use std::sync::Arc; diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index 32bedd59e..cb0d3630d 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -25,8 +25,7 @@ serde = { version = "1.0", features = ["derive"] } more-asserts = "0.2" gimli = { version = "0.23", optional = true } smallvec = "1.6" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index 180735775..dd2970330 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -18,7 +18,7 @@ use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::{binemit, Context}; #[cfg(feature = "unwind")] use gimli::write::{Address, EhFrame, FrameTable}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; use wasmer_compiler::CompileError; diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index ac639e94e..ed8419c2f 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -1,7 +1,7 @@ use crate::compiler::CraneliftCompiler; use cranelift_codegen::isa::{lookup, TargetIsa}; use cranelift_codegen::settings::{self, Configurable}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{ Architecture, Compiler, CompilerConfig, CpuFeature, ModuleMiddleware, Target, diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index ae97a0f4c..d6aac52fa 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -22,8 +22,7 @@ libc = { version = "^0.2", default-features = false } byteorder = "1" itertools = "0.10" rayon = "1.5" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [dependencies.inkwell] version = "=0.1.0-beta.2" diff --git a/lib/compiler-llvm/src/compiler.rs b/lib/compiler-llvm/src/compiler.rs index 5ea1c9f8f..d3d1b8428 100644 --- a/lib/compiler-llvm/src/compiler.rs +++ b/lib/compiler-llvm/src/compiler.rs @@ -7,7 +7,7 @@ use inkwell::memory_buffer::MemoryBuffer; use inkwell::module::{Linkage, Module}; use inkwell::targets::FileType; use inkwell::DLLStorageClass; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use rayon::iter::ParallelBridge; use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 66af408fe..245a27e92 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -5,7 +5,7 @@ use inkwell::targets::{ }; pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt::Debug; use std::sync::Arc; use target_lexicon::Architecture; @@ -42,10 +42,10 @@ pub trait LLVMCallbacks: Debug + Send + Sync { pub struct LLVM { pub(crate) enable_nan_canonicalization: bool, pub(crate) enable_verifier: bool, - #[memoryusage(ignore)] + #[loupe(skip)] pub(crate) opt_level: LLVMOptLevel, is_pic: bool, - #[memoryusage(ignore)] + #[loupe(skip)] pub(crate) callbacks: Option>, /// The middleware chain. pub(crate) middlewares: Vec>, diff --git a/lib/compiler-singlepass/Cargo.toml b/lib/compiler-singlepass/Cargo.toml index 38e2f178f..ede05f8bb 100644 --- a/lib/compiler-singlepass/Cargo.toml +++ b/lib/compiler-singlepass/Cargo.toml @@ -24,8 +24,7 @@ dynasmrt = "1.0" lazy_static = "1.4" byteorder = "1.3" smallvec = "1.6" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler-singlepass/src/compiler.rs b/lib/compiler-singlepass/src/compiler.rs index 51a520f61..edc1d93a4 100644 --- a/lib/compiler-singlepass/src/compiler.rs +++ b/lib/compiler-singlepass/src/compiler.rs @@ -7,7 +7,7 @@ use crate::codegen_x64::{ CodegenError, FuncGen, }; use crate::config::Singlepass; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; use wasmer_compiler::TrapInformation; diff --git a/lib/compiler-singlepass/src/config.rs b/lib/compiler-singlepass/src/config.rs index 2426db66d..d788478a9 100644 --- a/lib/compiler-singlepass/src/config.rs +++ b/lib/compiler-singlepass/src/config.rs @@ -2,7 +2,7 @@ #![allow(unused_imports, dead_code)] use crate::compiler::SinglepassCompiler; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{Compiler, CompilerConfig, CpuFeature, ModuleMiddleware, Target}; use wasmer_types::Features; diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index 91a83a26a..579f7814e 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -21,8 +21,7 @@ serde = { version = "1.0", features = ["derive"], optional = true } thiserror = "1.0" serde_bytes = { version = "0.11", optional = true } smallvec = "1.6" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] default = ["std", "enable-serde"] diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index bc5da48df..12b2b06f1 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,7 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, @@ -163,9 +163,9 @@ impl ToString for CpuFeature { /// the WebAssembly ModuleInfo, and then run it. #[derive(Clone, Debug, PartialEq, Eq, Hash, MemoryUsage)] pub struct Target { - #[memoryusage(ignore)] + #[loupe(skip)] triple: Triple, - #[memoryusage(ignore)] + #[loupe(skip)] cpu_features: EnumSet, } diff --git a/lib/engine-jit/Cargo.toml b/lib/engine-jit/Cargo.toml index bbe11a705..38b70474e 100644 --- a/lib/engine-jit/Cargo.toml +++ b/lib/engine-jit/Cargo.toml @@ -21,8 +21,7 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" cfg-if = "0.1" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winnt", "impl-default"] } diff --git a/lib/engine-jit/src/code_memory.rs b/lib/engine-jit/src/code_memory.rs index e6a6a4fab..1498a23ea 100644 --- a/lib/engine-jit/src/code_memory.rs +++ b/lib/engine-jit/src/code_memory.rs @@ -3,7 +3,7 @@ //! Memory management for executable code. use crate::unwind::UnwindRegistry; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use wasmer_compiler::{CompiledFunctionUnwindInfo, CustomSection, FunctionBody}; use wasmer_vm::{Mmap, VMFunctionBody}; diff --git a/lib/engine-jit/src/engine.rs b/lib/engine-jit/src/engine.rs index bac823659..9009d937b 100644 --- a/lib/engine-jit/src/engine.rs +++ b/lib/engine-jit/src/engine.rs @@ -1,7 +1,7 @@ //! JIT compilation. use crate::{CodeMemory, JITArtifact}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::{Arc, Mutex}; #[cfg(feature = "compiler")] use wasmer_compiler::Compiler; diff --git a/lib/engine-jit/src/unwind/dummy.rs b/lib/engine-jit/src/unwind/dummy.rs index 4cd69926c..cfb636bd2 100644 --- a/lib/engine-jit/src/unwind/dummy.rs +++ b/lib/engine-jit/src/unwind/dummy.rs @@ -1,6 +1,6 @@ //! Module for Dummy unwind registry. -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use wasmer_compiler::CompiledFunctionUnwindInfo; /// Represents a registry of function unwind information when the host system diff --git a/lib/engine-jit/src/unwind/systemv.rs b/lib/engine-jit/src/unwind/systemv.rs index 573ac08b1..8362fec49 100644 --- a/lib/engine-jit/src/unwind/systemv.rs +++ b/lib/engine-jit/src/unwind/systemv.rs @@ -3,7 +3,7 @@ //! Module for System V ABI unwind registry. -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use wasmer_compiler::CompiledFunctionUnwindInfo; /// Represents a registry of function unwind information for System V ABI. diff --git a/lib/engine-native/Cargo.toml b/lib/engine-native/Cargo.toml index c875b0f50..be045b7a4 100644 --- a/lib/engine-native/Cargo.toml +++ b/lib/engine-native/Cargo.toml @@ -24,8 +24,7 @@ leb128 = "0.2" libloading = "0.7" tempfile = "3.1" which = "4.0" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index bcfb28d40..84f857fd6 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,7 +2,7 @@ use crate::NativeArtifact; use libloading::Library; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; @@ -237,7 +237,7 @@ pub struct NativeEngineInner { /// The prefixer returns the a String to prefix each of /// the functions in the shared object generated by the `NativeEngine`, /// so we can assure no collisions. - #[memoryusage(ignore)] + #[loupe(skip)] prefixer: Option String + Send>>, /// Whether the native engine will cross-compile. @@ -247,7 +247,7 @@ pub struct NativeEngineInner { linker: Linker, /// List of libraries loaded by this engine. - #[memoryusage(ignore)] + #[loupe(skip)] libraries: Vec, } diff --git a/lib/engine-object-file/Cargo.toml b/lib/engine-object-file/Cargo.toml index f78e1d699..17ee1e016 100644 --- a/lib/engine-object-file/Cargo.toml +++ b/lib/engine-object-file/Cargo.toml @@ -23,8 +23,7 @@ bincode = "1.3" leb128 = "0.2" libloading = "0.7" tempfile = "3.1" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine-object-file/src/engine.rs b/lib/engine-object-file/src/engine.rs index a3f051f82..8bd589361 100644 --- a/lib/engine-object-file/src/engine.rs +++ b/lib/engine-object-file/src/engine.rs @@ -1,5 +1,5 @@ use crate::ObjectFileArtifact; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::io::Read; use std::path::Path; use std::sync::{Arc, Mutex}; @@ -183,7 +183,7 @@ pub struct ObjectFileEngineInner { /// The prefixer returns the a String to prefix each of /// the functions in the shared object generated by the `ObjectFileEngine`, /// so we can assure no collisions. - #[memoryusage(ignore)] + #[loupe(skip)] prefixer: Option String + Send>>, } diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml index 55c4a4ed8..a8ae21bec 100644 --- a/lib/engine/Cargo.toml +++ b/lib/engine/Cargo.toml @@ -25,8 +25,7 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" lazy_static = "1.4" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [badges] maintenance = { status = "actively-developed" } diff --git a/lib/engine/src/engine.rs b/lib/engine/src/engine.rs index 9eed69ac6..8d5f6c360 100644 --- a/lib/engine/src/engine.rs +++ b/lib/engine/src/engine.rs @@ -3,7 +3,6 @@ use crate::tunables::Tunables; use crate::{Artifact, DeserializeError}; use loupe::MemoryUsage; -use loupe_derive::MemoryUsage; use memmap2::Mmap; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; diff --git a/lib/middlewares/Cargo.toml b/lib/middlewares/Cargo.toml index ebbd3e755..5fd6837df 100644 --- a/lib/middlewares/Cargo.toml +++ b/lib/middlewares/Cargo.toml @@ -14,8 +14,7 @@ edition = "2018" wasmer = { path = "../api", version = "1.0.2" } wasmer-types = { path = "../wasmer-types", version = "1.0.2" } wasmer-vm = { path = "../vm", version = "1.0.2" } -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [badges] maintenance = { status = "actively-developed" } diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index b3ddc029a..faea363e0 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -2,7 +2,6 @@ //! and putting a limit on the total number of operators executed. use loupe::{MemoryUsage, MemoryUsageTracker}; -use loupe_derive::MemoryUsage; use std::convert::TryInto; use std::fmt; use std::mem; diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index 4d55a8625..cc12923e6 100644 --- a/lib/vm/Cargo.toml +++ b/lib/vm/Cargo.toml @@ -21,8 +21,7 @@ more-asserts = "0.2" cfg-if = "0.1" backtrace = "0.3" serde = { version = "1.0", features = ["derive", "rc"] } -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] } diff --git a/lib/vm/src/sig_registry.rs b/lib/vm/src/sig_registry.rs index b0da474eb..051006bc9 100644 --- a/lib/vm/src/sig_registry.rs +++ b/lib/vm/src/sig_registry.rs @@ -5,7 +5,7 @@ //! signature checking. use crate::vmcontext::VMSharedSignatureIndex; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use more_asserts::{assert_lt, debug_assert_lt}; use std::collections::{hash_map, HashMap}; use std::convert::TryFrom; diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index 7262be3cb..929c1126f 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -9,7 +9,7 @@ use crate::instance::Instance; use crate::memory::Memory; use crate::table::Table; use crate::trap::{Trap, TrapCode}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::any::Any; use std::convert::TryFrom; use std::fmt; diff --git a/lib/wasmer-types/Cargo.toml b/lib/wasmer-types/Cargo.toml index 4a9ad93ab..8bff64a3d 100644 --- a/lib/wasmer-types/Cargo.toml +++ b/lib/wasmer-types/Cargo.toml @@ -13,8 +13,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"], optional = true, default-features = false } thiserror = "1.0" -loupe = { path = "../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] default = ["std", "enable-serde"] diff --git a/lib/wasmer-types/src/features.rs b/lib/wasmer-types/src/features.rs index a051bcfbd..4fc19564d 100644 --- a/lib/wasmer-types/src/features.rs +++ b/lib/wasmer-types/src/features.rs @@ -1,4 +1,4 @@ -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/wasmer-types/src/indexes.rs b/lib/wasmer-types/src/indexes.rs index 06ba01caa..ed5f32015 100644 --- a/lib/wasmer-types/src/indexes.rs +++ b/lib/wasmer-types/src/indexes.rs @@ -1,7 +1,7 @@ //! Helper functions and structures for the translation. use crate::entity::entity_impl; use core::u32; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs index 3482d42a8..168f94761 100644 --- a/lib/wasmer-types/src/types.rs +++ b/lib/wasmer-types/src/types.rs @@ -6,7 +6,7 @@ use crate::lib::std::string::{String, ToString}; use crate::lib::std::vec::Vec; use crate::units::Pages; use crate::values::Value; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/wasmer-types/src/units.rs b/lib/wasmer-types/src/units.rs index 703006167..1d1360b60 100644 --- a/lib/wasmer-types/src/units.rs +++ b/lib/wasmer-types/src/units.rs @@ -1,7 +1,7 @@ use crate::lib::std::convert::TryFrom; use crate::lib::std::fmt; use crate::lib::std::ops::{Add, Sub}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use std::convert::TryInto; diff --git a/tests/lib/engine-dummy/Cargo.toml b/tests/lib/engine-dummy/Cargo.toml index 3a81e5ef5..2a12de6d8 100644 --- a/tests/lib/engine-dummy/Cargo.toml +++ b/tests/lib/engine-dummy/Cargo.toml @@ -15,8 +15,7 @@ wasmer-engine = { path = "../../../lib/engine", version = "1.0.2" } serde = { version = "1.0", features = ["derive", "rc"], optional = true } serde_bytes = { version = "0.11", optional = true } bincode = { version = "1.2", optional = true } -loupe = { path = "../../../../loupe/crates/loupe" } -loupe-derive = { path = "../../../../loupe/crates/loupe-derive" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/tests/lib/engine-dummy/src/engine.rs b/tests/lib/engine-dummy/src/engine.rs index 0135bd391..ca9b0c4a9 100644 --- a/tests/lib/engine-dummy/src/engine.rs +++ b/tests/lib/engine-dummy/src/engine.rs @@ -1,7 +1,7 @@ //! Dummy Engine. use crate::DummyArtifact; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{CompileError, Features, Target}; use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables}; From a6adbcbcd12329ceab73c2987afb23129832738d Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 22 Mar 2021 13:05:11 +0100 Subject: [PATCH 03/26] Added multilanguage README --- README.md | 2 + docs/cn/README.md | 192 ++++++++++++++++++++++++++++++++++++++++++++++ docs/es/README.md | 191 +++++++++++++++++++++++++++++++++++++++++++++ docs/fr/README.md | 191 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 576 insertions(+) create mode 100644 docs/cn/README.md create mode 100644 docs/es/README.md create mode 100644 docs/fr/README.md diff --git a/README.md b/README.md index d1326658b..a4e321100 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ [Wasmer](https://wasmer.io/) enables super lightweight containers based on [WebAssembly](https://webassembly.org/) that can run anywhere: from Desktop to the Cloud and IoT devices, and also embedded in [*any programming language*](https://github.com/wasmerio/wasmer#language-integrations). +> This readme is also available in: [🇨🇳 中文 / Chinese](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md) • [🇪🇸 Español / Spanish](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇫🇷 Français / French](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md). + ## Features * **Fast & Safe**. Wasmer runs WebAssembly at *near-native* speed in a fully sandboxed environment. diff --git a/docs/cn/README.md b/docs/cn/README.md new file mode 100644 index 000000000..4e8d0d1ca --- /dev/null +++ b/docs/cn/README.md @@ -0,0 +1,192 @@ +
+ + Wasmer logo + + +

+ + Build Status + + + License + + + Slack channel + +

+ +

+ 网站 + + 文件资料 + + 聊天 +

+ +
+ +
+ +[Wasmer]https://wasmer.io/)使得能够基于 [WebAssembly](https://webassembly.org/),其可以在任何地方运行超轻型容器:从桌面到云和的IoT装置,并且也嵌入在 [*任何编程语言*](https://github.com/wasmerio/wasmer#language-integrations). + +> This readme is also available in: [🇬🇧 English / 英文](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español / 西班牙语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇫🇷 Français / 法语/法语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md). + +## 特征 + +* **快速又安全**. Wasmer 在完全沙盒化的环境中以“接近本机”的速度运行 WebAssembly。 + +* **可插拔**. Wasmer支持不同的编译框架以最适合您的需求(LLVM,Cranelift ...). + +* **普遍的**. 您可以在任何*平台*(macOS,Linux和Windows)和*芯片组*中运行Wasmer. + +* **符合标准**. 运行时通过了[官方WebAssembly测试 + 套件](https://github.com/WebAssembly/testsuite) 支持[WASI](https://github.com/WebAssembly/WASI) 和[Emscripten](https://emscripten.org/). + +## 快速开始 + +Wasmer出厂时没有任何依赖关系. 您可以使用以下安装程序进行安装: + +```sh +curl https://get.wasmer.io -sSfL | sh +``` + +
+ 使用Powershell (Windows) +

+ +```powershell +iwr https://win.wasmer.io -useb | iex +``` + +

+
+ +> 有关更多安装选项,请参见 [wasmer-install](https://github.com/wasmerio/wasmer-install): Homebrew, Scoop, Cargo... + + +#### 执行WebAssembly文件 + +安装Wasmer之后,您应该已经准备好执行第一个WebAssemby文件! 🎉 + +您可以通过运行QuickJS开始: [qjs.wasm](https://registry-cdn.wapm.io/contents/_/quickjs/0.0.3/build/qjs.wasm) + +```bash +$ wasmer qjs.wasm +QuickJS - Type "\h" for help +qjs > +``` + +#### 接下来是您可以做的: + +- [在您的Rust应用程序中使用Wasmer](https://docs.wasmer.io/integrations/rust) +- [在WAPM上发布Wasm程序包](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) +- [阅读有关Wasmer的更多信息](https://medium.com/wasmer/) + +## 语言整合 + +📦 Wasmer运行时可以用作**以不同语言嵌入的库**,因此您可以在任何位置使用WebAssembly. + +|   | 语言 | 箱 | 文件资料 | +|-|-|-|-| +| ![Rust logo] | [**Rust**][Rust integration] | [`wasmer` Rust crate] | [文件资料][rust docs] +| ![C logo] | [**C/C++**][C integration] | [`wasmer.h` headers] | [文件资料][c docs] | +| ![C# logo] | [**C#**][C# integration] | [`WasmerSharp` NuGet package] | [文件资料][c# docs] | +| ![D logo] | [**D**][D integration] | [`wasmer` Dub package] | [文件资料][d docs] | +| ![Python logo] | [**Python**][Python integration] | [`wasmer` PyPI package] | [文件资料][python docs] | +| ![JS logo] | [**Javascript**][JS integration] | [`@wasmerio` NPM packages] | [文件资料][js docs] | +| ![Go logo] | [**Go**][Go integration] | [`wasmer` Go package] | [文件资料][go docs] | +| ![PHP logo] | [**PHP**][PHP integration] | [`wasm` PECL package] | [文件资料][php docs] | +| ![Ruby logo] | [**Ruby**][Ruby integration] | [`wasmer` Ruby Gem] | [文件资料][ruby docs] | +| ![Java logo] | [**Java**][Java integration] | [`wasmer/wasmer-jni` Bintray package] | [文件资料][java docs] | +| ![Elixir logo] | [**Elixir**][Elixir integration] | [`wasmex` hex package] | [文件资料][elixir docs] | +| ![R logo] | [**R**][R integration] | *没有已发布的软件包* | [文件资料][r docs] | +| ![Postgres logo] | [**Postgres**][Postgres integration] | *没有已发布的软件包* | [文件资料][postgres docs] | +| | [**Swift**][Swift integration] | *没有已发布的软件包* | | + +[👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) + +[rust logo]: ./assets/languages/rust.svg +[rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api +[`wasmer` rust crate]: https://crates.io/crates/wasmer/ +[rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime + +[c logo]: ./assets/languages/c.svg +[c integration]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api +[`wasmer.h` headers]: https://wasmerio.github.io/wasmer/c/ +[c docs]: https://wasmerio.github.io/wasmer/c/ + +[c# logo]: ./assets/languages/csharp.svg +[c# integration]: https://github.com/migueldeicaza/WasmerSharp +[`wasmersharp` nuget package]: https://www.nuget.org/packages/WasmerSharp/ +[c# docs]: https://migueldeicaza.github.io/WasmerSharp/ + +[d logo]: ./assets/languages/d.svg +[d integration]: https://github.com/chances/wasmer-d +[`wasmer` Dub package]: https://code.dlang.org/packages/wasmer +[d docs]: https://chances.github.io/wasmer-d + +[python logo]: ./assets/languages/python.svg +[python integration]: https://github.com/wasmerio/wasmer-python +[`wasmer` pypi package]: https://pypi.org/project/wasmer/ +[python docs]: https://github.com/wasmerio/wasmer-python#api-of-the-wasmer-extensionmodule + +[go logo]: ./assets/languages/go.svg +[go integration]: https://github.com/wasmerio/wasmer-go +[`wasmer` go package]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer +[go docs]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc + +[php logo]: ./assets/languages/php.svg +[php integration]: https://github.com/wasmerio/wasmer-php +[`wasm` pecl package]: https://pecl.php.net/package/wasm +[php docs]: https://wasmerio.github.io/wasmer-php/wasm/ + +[js logo]: ./assets/languages/js.svg +[js integration]: https://github.com/wasmerio/wasmer-js +[`@wasmerio` npm packages]: https://www.npmjs.com/org/wasmer +[js docs]: https://docs.wasmer.io/integrations/js/reference-api + +[ruby logo]: ./assets/languages/ruby.svg +[ruby integration]: https://github.com/wasmerio/wasmer-ruby +[`wasmer` ruby gem]: https://rubygems.org/gems/wasmer +[ruby docs]: https://www.rubydoc.info/gems/wasmer/ + +[java logo]: ./assets/languages/java.svg +[java integration]: https://github.com/wasmerio/wasmer-java +[`wasmer/wasmer-jni` bintray package]: https://bintray.com/wasmer/wasmer-jni/wasmer-jni +[java docs]: https://github.com/wasmerio/wasmer-java/#api-of-the-wasmer-library + +[elixir logo]: ./assets/languages/elixir.svg +[elixir integration]: https://github.com/tessi/wasmex +[elixir docs]: https://hexdocs.pm/wasmex/api-reference.html +[`wasmex` hex package]: https://hex.pm/packages/wasmex + +[r logo]: ./assets/languages/r.svg +[r integration]: https://github.com/dirkschumacher/wasmr +[r docs]: https://github.com/dirkschumacher/wasmr#example + +[postgres logo]: ./assets/languages/postgres.svg +[postgres integration]: https://github.com/wasmerio/wasmer-postgres +[postgres docs]: https://github.com/wasmerio/wasmer-postgres#usage--documentation + +[swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer + +## 贡献 + +**我们欢迎任何形式的贡献,尤其是来自社区新成员的贡献** 💜 + +您可以在[我们的出色文档](https://docs.wasmer.io/ecosystem/wasmer/building-from-source) 中检查如何构建Wasmer运行时! + +### 测试 + +要测试吗? The [Wasmer文档将向您展示如何](https://docs.wasmer.io/ecosystem/wasmer/building-from-source/testing). + +## 社区 + +Wasmer拥有一个了不起的开发人员和贡献者社区。 欢迎您,请加入我们! 👋 + +### 频道 + +- [Slack](https://slack.wasmer.io/) +- [Twitter](https://twitter.com/wasmerio) +- [Facebook](https://www.facebook.com/wasmerio) +- [Email](mailto:hello@wasmer.io) diff --git a/docs/es/README.md b/docs/es/README.md new file mode 100644 index 000000000..53222920a --- /dev/null +++ b/docs/es/README.md @@ -0,0 +1,191 @@ +
+ + Wasmer logo + + +

+ + Build Status + + + License + + + Slack channel + +

+ +

+ Web + + Documentación + + Chat +

+ +
+ +
+ +[Wasmer](https://wasmer.io/) hace posible tener contenedores ultraligeros basados en [WebAssembly](https://webassembly.org/) que pueden ser ejecutados en cualquier sitio: desde tu ordenador hasta la nube y dispositivos de IoT, además de ser [*any programming language*](https://github.com/wasmerio/wasmer#language-integrations). + +> This README is also available in: [🇬🇧 English / Inglés](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇫🇷 Français / Francés](https://github.com/wasmerio/wasmer/blob/master/docs/fr/README.md) • [🇨🇳 中文 / Chino](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md). + +## Funcionalidades + +* **Rápido y Seguro**. Wasmer ejecuta WebAssembly a velocidades *nativas* en un entorno completamente protegido. + +* **Extendible**. Wasmer soporta diferentes métodos de compilación dependiendo de tus necesidades (LLVM, Cranelift...). + +* **Universal**. Puedes ejecutar Wasmer en cualquier *platforma* (macOS, Linux y Windows) y *chip*. + +* **Respeta los estándares**. Wasmer pasa los [tests oficiales de WebAssembly](https://github.com/WebAssembly/testsuite) siendo compatible con [WASI](https://github.com/WebAssembly/WASI) y [Emscripten](https://emscripten.org/). + +## Empezamos? + +Wasmer no requiere ninguna dependencia. Puedes instalarlo con uno de éstos instaladores: + +```sh +curl https://get.wasmer.io -sSfL | sh +``` + +
+ Con PowerShell (Windows) +

+ +```powershell +iwr https://win.wasmer.io -useb | iex +``` + +

+
+ +> Visita [wasmer-install](https://github.com/wasmerio/wasmer-install) para más opciones de instalación: Homebrew, Scoop, Cargo... + + +#### Ejecuta un archivo WebAssembly + +¡Después de instalar Wasmer deberías estar listo para ejecutar tu primer módulo de WebAssembly! 🎉 + +Puedes empezar corriendo QuickJS: [qjs.wasm](https://registry-cdn.wapm.io/contents/_/quickjs/0.0.3/build/qjs.wasm) + +```bash +$ wasmer qjs.wasm +QuickJS - Type "\h" for help +qjs > +``` + +#### Here is what you can do next: + +- [Use Wasmer from your Rust application](https://docs.wasmer.io/integrations/rust) +- [Publish a Wasm package on WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) +- [Read more about Wasmer](https://medium.com/wasmer/) + +## Integraciones en diferentes Lenguajes + +📦 Wasmer puede ser usado como una librería **integrado en diferentes lenguajes de programación**, para que puedas ejecutar WebAssembly _en cualquier sitio_. + +|   | Lenguaje | Librería | Documentación | +|-|-|-|-| +| ![Rust logo] | [**Rust**][Rust integration] | [`wasmer` en crates.io] | [Documentación][rust docs] +| ![C logo] | [**C/C++**][C integration] | [cabecera `wasmer.h`] | [Documentación][c docs] | +| ![C# logo] | [**C#**][C# integration] | [`WasmerSharp` en NuGet] | [Documentación][c# docs] | +| ![D logo] | [**D**][D integration] | [`wasmer` en Dug] | [Documentación][d docs] | +| ![Python logo] | [**Python**][Python integration] | [`wasmer` en PyPI] | [Documentación][python docs] | +| ![JS logo] | [**Javascript**][JS integration] | [`@wasmerio` en NPM] | [Documentación][js docs] | +| ![Go logo] | [**Go**][Go integration] | [`wasmer` en Go] | [Documentación][go docs] | +| ![PHP logo] | [**PHP**][PHP integration] | [`wasm` en PECL] | [Documentación][php docs] | +| ![Ruby logo] | [**Ruby**][Ruby integration] | [`wasmer` en Ruby Gems] | [Documentación][ruby docs] | +| ![Java logo] | [**Java**][Java integration] | [`wasmer/wasmer-jni` en Bintray] | [Documentación][java docs] | +| ![Elixir logo] | [**Elixir**][Elixir integration] | [`wasmex` en hex] | [Documentación][elixir docs] | +| ![R logo] | [**R**][R integration] | *sin paquete publicado* | [Documentación][r docs] | +| ![Postgres logo] | [**Postgres**][Postgres integration] | *sin paquete publicado* | [Documentación][postgres docs] | +| | [**Swift**][Swift integration] | *sin paquete publicado* | | + +[👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) + +[rust logo]: ./assets/languages/rust.svg +[rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api +[`wasmer` en crates.io]: https://crates.io/crates/wasmer/ +[rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime + +[c logo]: ./assets/languages/c.svg +[c integration]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api +[cabecera `wasmer.h`]: https://wasmerio.github.io/wasmer/c/ +[c docs]: https://wasmerio.github.io/wasmer/c/ + +[c# logo]: ./assets/languages/csharp.svg +[c# integration]: https://github.com/migueldeicaza/WasmerSharp +[`wasmersharp` en NuGet]: https://www.nuget.org/packages/WasmerSharp/ +[c# docs]: https://migueldeicaza.github.io/WasmerSharp/ + +[d logo]: ./assets/languages/d.svg +[d integration]: https://github.com/chances/wasmer-d +[`wasmer` en Dub]: https://code.dlang.org/packages/wasmer +[d docs]: https://chances.github.io/wasmer-d + +[python logo]: ./assets/languages/python.svg +[python integration]: https://github.com/wasmerio/wasmer-python +[`wasmer` en pypi]: https://pypi.org/project/wasmer/ +[python docs]: https://github.com/wasmerio/wasmer-python#api-of-the-wasmer-extensionmodule + +[go logo]: ./assets/languages/go.svg +[go integration]: https://github.com/wasmerio/wasmer-go +[`wasmer` en go]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer +[go docs]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc + +[php logo]: ./assets/languages/php.svg +[php integration]: https://github.com/wasmerio/wasmer-php +[php docs]: https://wasmerio.github.io/wasmer-php/wasm/ +[`wasm` en pecl]: https://pecl.php.net/package/wasm + +[js logo]: ./assets/languages/js.svg +[js integration]: https://github.com/wasmerio/wasmer-js +[`@wasmerio` en npm]: https://www.npmjs.com/org/wasmer +[js docs]: https://docs.wasmer.io/integrations/js/reference-api + +[ruby logo]: ./assets/languages/ruby.svg +[ruby integration]: https://github.com/wasmerio/wasmer-ruby +[`wasmer` en ruby gems]: https://rubygems.org/gems/wasmer +[ruby docs]: https://www.rubydoc.info/gems/wasmer/ + +[java logo]: ./assets/languages/java.svg +[java integration]: https://github.com/wasmerio/wasmer-java +[`wasmer/wasmer-jni` en bintray]: https://bintray.com/wasmer/wasmer-jni/wasmer-jni +[java docs]: https://github.com/wasmerio/wasmer-java/#api-of-the-wasmer-library + +[elixir logo]: ./assets/languages/elixir.svg +[elixir integration]: https://github.com/tessi/wasmex +[elixir docs]: https://hexdocs.pm/wasmex/api-reference.html +[`wasmex` en hex]: https://hex.pm/packages/wasmex + +[r logo]: ./assets/languages/r.svg +[r integration]: https://github.com/dirkschumacher/wasmr +[r docs]: https://github.com/dirkschumacher/wasmr#example + +[postgres logo]: ./assets/languages/postgres.svg +[postgres integration]: https://github.com/wasmerio/wasmer-postgres +[postgres docs]: https://github.com/wasmerio/wasmer-postgres#usage--documentation + +[swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer + +## Contribuye + +**Damos la bienvenida a cualquier forma de contribución, especialmente a los nuevos miembros de la comunidad** 💜 + +¡Puedes ver cómo crear el binario de Wasmer con [nuestros increíbles documentos](https://docs.wasmer.io/ecosystem/wasmer/building-from-source)! + +### Tests + +Testear quieres? Los [documentos de Wasmer te enseñarán cómo](https://docs.wasmer.io/ecosystem/wasmer/building-from-source/testing). + +## Comunidad + +Wasmer tiene una comunidad increíble de desarrolladores y colaboradores ¡Bienvenido, únete a nosotros! 👋 + +### Medios + +- [Slack](https://slack.wasmer.io/) +- [Twitter](https://twitter.com/wasmerio) +- [Facebook](https://www.facebook.com/wasmerio) +- [Email](mailto:hello@wasmer.io) diff --git a/docs/fr/README.md b/docs/fr/README.md new file mode 100644 index 000000000..afce98b40 --- /dev/null +++ b/docs/fr/README.md @@ -0,0 +1,191 @@ +
+ + Wasmer logo + + +

+ + Build Status + + + License + + + Slack channel + +

+ +

+ Web + + Documentation + + Chat +

+ +
+ +
+ +[Wasmer](https://wasmer.io/) active des conteneurs super légers basés sur [WebAssembly](https://webassembly.org/) qui peuvent fonctionner n'importe où: du bureau au cloud et aux appareils IoT, et également intégrés dans [*tout langage de programmation*](https://github.com/wasmerio/wasmer#language-integrations). + +> This readme is also available in: [🇬🇧 English / Anglaise](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español / Espagnol](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇨🇳 中文 / Chinoise](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md) + +## Fonctionnalités + +* **Rapide et sûr**. Wasmer exécute WebAssembly à une vitesse *quasi native* dans un environnement entièrement bac à sable. + +* **Enfichable**. Wasmer prend en charge différents frameworks de compilation pour répondre au mieux à vos besoins (LLVM, Cranelift ...). + +* **Universal**. Vous pouvez exécuter Wasmer sur n'importe quelle *plate-forme* (macOS, Linux et Windows) et *chipset*. + +* **Conforme aux normes**. Le runtime réussit [test officiel de WebAssembly suite](https://github.com/WebAssembly/testsuite) prenant en charge [WASI](https://github.com/WebAssembly/WASI) et [Emscripten](https://emscripten.org/) + +## Quickstart + +Wasmer est livré sans dépendances. Vous pouvez l'installer à l'aide des programmes d'installation ci-dessous: + +```sh +curl https://get.wasmer.io -sSfL | sh +``` + +
+ Avec PowerShell (Windows) +

+ +```powershell +iwr https://win.wasmer.io -useb | iex +``` + +

+
+ +> Voir [wasmer-install](https://github.com/wasmerio/wasmer-install) pour plus d'options d'installation: Homebrew, Scoop, Cargo... + + +#### Exécution d'un fichier WebAssembly + +Après avoir installé Wasmer, vous devriez être prêt à exécuter votre premier fichier WebAssemby! 🎉 + +Vous pouvez commencer par exécuter QuickJS: [qjs.wasm](https://registry-cdn.wapm.io/contents/_/quickjs/0.0.3/build/qjs.wasm) + +```bash +$ wasmer qjs.wasm +QuickJS - Type "\h" for help +qjs > +``` + +#### Voici ce que vous pouvez faire ensuite: + +- [Utilisez Wasmer depuis votre application Rust](https://docs.wasmer.io/integrations/rust) +- [Publier un package Wasm sur WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) +- [En savoir plus sur Wasmer](https://medium.com/wasmer/) + +## Intégrations + +📦 Le runtime Wasmer peut être utilisé comme une bibliothèque **intégrée dans différentes langues**, vous pouvez donc utiliser WebAssembly _anywhere_. + +|   | Langage de programmation | Package | Docs | +|-|-|-|-| +| ![Rust logo] | [**Rust**][Rust integration] | [`wasmer` Rust crate] | [Docs][rust docs] +| ![C logo] | [**C/C++**][C integration] | [`wasmer.h` headers] | [Docs][c docs] | +| ![C# logo] | [**C#**][C# integration] | [`WasmerSharp` NuGet package] | [Docs][c# docs] | +| ![D logo] | [**D**][D integration] | [`wasmer` Dub package] | [Docs][d docs] | +| ![Python logo] | [**Python**][Python integration] | [`wasmer` PyPI package] | [Docs][python docs] | +| ![JS logo] | [**Javascript**][JS integration] | [`@wasmerio` NPM packages] | [Docs][js docs] | +| ![Go logo] | [**Go**][Go integration] | [`wasmer` Go package] | [Docs][go docs] | +| ![PHP logo] | [**PHP**][PHP integration] | [`wasm` PECL package] | [Docs][php docs] | +| ![Ruby logo] | [**Ruby**][Ruby integration] | [`wasmer` Ruby Gem] | [Docs][ruby docs] | +| ![Java logo] | [**Java**][Java integration] | [`wasmer/wasmer-jni` Bintray package] | [Docs][java docs] | +| ![Elixir logo] | [**Elixir**][Elixir integration] | [`wasmex` hex package] | [Docs][elixir docs] | +| ![R logo] | [**R**][R integration] | *no published package* | [Docs][r docs] | +| ![Postgres logo] | [**Postgres**][Postgres integration] | *no published package* | [Docs][postgres docs] | +| | [**Swift**][Swift integration] | *no published package* | | + +[👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) + +[rust logo]: ./assets/languages/rust.svg +[rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api +[`wasmer` rust crate]: https://crates.io/crates/wasmer/ +[rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime + +[c logo]: ./assets/languages/c.svg +[c integration]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api +[`wasmer.h` headers]: https://wasmerio.github.io/wasmer/c/ +[c docs]: https://wasmerio.github.io/wasmer/c/ + +[c# logo]: ./assets/languages/csharp.svg +[c# integration]: https://github.com/migueldeicaza/WasmerSharp +[`wasmersharp` nuget package]: https://www.nuget.org/packages/WasmerSharp/ +[c# docs]: https://migueldeicaza.github.io/WasmerSharp/ + +[d logo]: ./assets/languages/d.svg +[d integration]: https://github.com/chances/wasmer-d +[`wasmer` Dub package]: https://code.dlang.org/packages/wasmer +[d docs]: https://chances.github.io/wasmer-d + +[python logo]: ./assets/languages/python.svg +[python integration]: https://github.com/wasmerio/wasmer-python +[`wasmer` pypi package]: https://pypi.org/project/wasmer/ +[python docs]: https://github.com/wasmerio/wasmer-python#api-of-the-wasmer-extensionmodule + +[go logo]: ./assets/languages/go.svg +[go integration]: https://github.com/wasmerio/wasmer-go +[`wasmer` go package]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer +[go docs]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc + +[php logo]: ./assets/languages/php.svg +[php integration]: https://github.com/wasmerio/wasmer-php +[`wasm` pecl package]: https://pecl.php.net/package/wasm +[php docs]: https://wasmerio.github.io/wasmer-php/wasm/ + +[js logo]: ./assets/languages/js.svg +[js integration]: https://github.com/wasmerio/wasmer-js +[`@wasmerio` npm packages]: https://www.npmjs.com/org/wasmer +[js docs]: https://docs.wasmer.io/integrations/js/reference-api + +[ruby logo]: ./assets/languages/ruby.svg +[ruby integration]: https://github.com/wasmerio/wasmer-ruby +[`wasmer` ruby gem]: https://rubygems.org/gems/wasmer +[ruby docs]: https://www.rubydoc.info/gems/wasmer/ + +[java logo]: ./assets/languages/java.svg +[java integration]: https://github.com/wasmerio/wasmer-java +[`wasmer/wasmer-jni` bintray package]: https://bintray.com/wasmer/wasmer-jni/wasmer-jni +[java docs]: https://github.com/wasmerio/wasmer-java/#api-of-the-wasmer-library + +[elixir logo]: ./assets/languages/elixir.svg +[elixir integration]: https://github.com/tessi/wasmex +[elixir docs]: https://hexdocs.pm/wasmex/api-reference.html +[`wasmex` hex package]: https://hex.pm/packages/wasmex + +[r logo]: ./assets/languages/r.svg +[r integration]: https://github.com/dirkschumacher/wasmr +[r docs]: https://github.com/dirkschumacher/wasmr#example + +[postgres logo]: ./assets/languages/postgres.svg +[postgres integration]: https://github.com/wasmerio/wasmer-postgres +[postgres docs]: https://github.com/wasmerio/wasmer-postgres#usage--documentation + +[swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer + +## Contribuer + +**Nous accueillons toute forme de contribution, en particulier de la part des nouveaux membres de notre communauté** 💜 + +Vous pouvez vérifier comment construire le runtime Wasmer dans [nos super documents](https://docs.wasmer.io/ecosystem/wasmer/building-from-source)! + +### Test + +Test que vous voulez? La [documentation Wasmer vous montrera comment](https://docs.wasmer.io/ecosystem/wasmer/building-from-source/testing). + +## Communauté + +Wasmer a une incroyable communauté de développeurs et de contributeurs. Bienvenue, rejoignez-nous! 👋 + +### Canaux + +- [Slack](https://slack.wasmer.io/) +- [Twitter](https://twitter.com/wasmerio) +- [Facebook](https://www.facebook.com/wasmerio) +- [Email](mailto:hello@wasmer.io) From fa2d3f6f18ecd4c639709f75cb9dee463842b192 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 22 Mar 2021 13:11:56 +0100 Subject: [PATCH 04/26] Minor fixes --- README.md | 28 ++++++++++++++-------------- docs/cn/README.md | 30 +++++++++++++++--------------- docs/es/README.md | 28 ++++++++++++++-------------- docs/fr/README.md | 28 ++++++++++++++-------------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index a4e321100..dd952cc15 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ [Wasmer](https://wasmer.io/) enables super lightweight containers based on [WebAssembly](https://webassembly.org/) that can run anywhere: from Desktop to the Cloud and IoT devices, and also embedded in [*any programming language*](https://github.com/wasmerio/wasmer#language-integrations). -> This readme is also available in: [🇨🇳 中文 / Chinese](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md) • [🇪🇸 Español / Spanish](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇫🇷 Français / French](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md). +> This readme is also available in: [🇨🇳 中文-Chinese](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md) • [🇪🇸 Español-Spanish](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇫🇷 Français-French](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md). ## Features @@ -105,66 +105,66 @@ qjs > [👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) -[rust logo]: ./assets/languages/rust.svg +[rust logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/rust.svg [rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api [`wasmer` rust crate]: https://crates.io/crates/wasmer/ [rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime -[c logo]: ./assets/languages/c.svg +[c logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/c.svg [c integration]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api [`wasmer.h` headers]: https://wasmerio.github.io/wasmer/c/ [c docs]: https://wasmerio.github.io/wasmer/c/ -[c# logo]: ./assets/languages/csharp.svg +[c# logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/csharp.svg [c# integration]: https://github.com/migueldeicaza/WasmerSharp [`wasmersharp` nuget package]: https://www.nuget.org/packages/WasmerSharp/ [c# docs]: https://migueldeicaza.github.io/WasmerSharp/ -[d logo]: ./assets/languages/d.svg +[d logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/d.svg [d integration]: https://github.com/chances/wasmer-d [`wasmer` Dub package]: https://code.dlang.org/packages/wasmer [d docs]: https://chances.github.io/wasmer-d -[python logo]: ./assets/languages/python.svg +[python logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/python.svg [python integration]: https://github.com/wasmerio/wasmer-python [`wasmer` pypi package]: https://pypi.org/project/wasmer/ [python docs]: https://github.com/wasmerio/wasmer-python#api-of-the-wasmer-extensionmodule -[go logo]: ./assets/languages/go.svg +[go logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/go.svg [go integration]: https://github.com/wasmerio/wasmer-go [`wasmer` go package]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer [go docs]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc -[php logo]: ./assets/languages/php.svg +[php logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/php.svg [php integration]: https://github.com/wasmerio/wasmer-php [`wasm` pecl package]: https://pecl.php.net/package/wasm [php docs]: https://wasmerio.github.io/wasmer-php/wasm/ -[js logo]: ./assets/languages/js.svg +[js logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/js.svg [js integration]: https://github.com/wasmerio/wasmer-js [`@wasmerio` npm packages]: https://www.npmjs.com/org/wasmer [js docs]: https://docs.wasmer.io/integrations/js/reference-api -[ruby logo]: ./assets/languages/ruby.svg +[ruby logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/ruby.svg [ruby integration]: https://github.com/wasmerio/wasmer-ruby [`wasmer` ruby gem]: https://rubygems.org/gems/wasmer [ruby docs]: https://www.rubydoc.info/gems/wasmer/ -[java logo]: ./assets/languages/java.svg +[java logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/java.svg [java integration]: https://github.com/wasmerio/wasmer-java [`wasmer/wasmer-jni` bintray package]: https://bintray.com/wasmer/wasmer-jni/wasmer-jni [java docs]: https://github.com/wasmerio/wasmer-java/#api-of-the-wasmer-library -[elixir logo]: ./assets/languages/elixir.svg +[elixir logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/elixir.svg [elixir integration]: https://github.com/tessi/wasmex [elixir docs]: https://hexdocs.pm/wasmex/api-reference.html [`wasmex` hex package]: https://hex.pm/packages/wasmex -[r logo]: ./assets/languages/r.svg +[r logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/r.svg [r integration]: https://github.com/dirkschumacher/wasmr [r docs]: https://github.com/dirkschumacher/wasmr#example -[postgres logo]: ./assets/languages/postgres.svg +[postgres logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/postgres.svg [postgres integration]: https://github.com/wasmerio/wasmer-postgres [postgres docs]: https://github.com/wasmerio/wasmer-postgres#usage--documentation diff --git a/docs/cn/README.md b/docs/cn/README.md index 4e8d0d1ca..af18d24ce 100644 --- a/docs/cn/README.md +++ b/docs/cn/README.md @@ -27,9 +27,9 @@
-[Wasmer]https://wasmer.io/)使得能够基于 [WebAssembly](https://webassembly.org/),其可以在任何地方运行超轻型容器:从桌面到云和的IoT装置,并且也嵌入在 [*任何编程语言*](https://github.com/wasmerio/wasmer#language-integrations). +[Wasmer](https://wasmer.io/)使得能够基于 [WebAssembly](https://webassembly.org/),其可以在任何地方运行超轻型容器:从桌面到云和的IoT装置,并且也嵌入在 [*任何编程语言*](https://github.com/wasmerio/wasmer#language-integrations). -> This readme is also available in: [🇬🇧 English / 英文](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español / 西班牙语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇫🇷 Français / 法语/法语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md). +> This readme is also available in: [🇬🇧 English-英文](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español-西班牙语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇫🇷 Français-法语/法语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md). ## 特征 @@ -105,66 +105,66 @@ qjs > [👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) -[rust logo]: ./assets/languages/rust.svg +[rust logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/rust.svg [rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api [`wasmer` rust crate]: https://crates.io/crates/wasmer/ [rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime -[c logo]: ./assets/languages/c.svg +[c logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/c.svg [c integration]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api [`wasmer.h` headers]: https://wasmerio.github.io/wasmer/c/ [c docs]: https://wasmerio.github.io/wasmer/c/ -[c# logo]: ./assets/languages/csharp.svg +[c# logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/csharp.svg [c# integration]: https://github.com/migueldeicaza/WasmerSharp [`wasmersharp` nuget package]: https://www.nuget.org/packages/WasmerSharp/ [c# docs]: https://migueldeicaza.github.io/WasmerSharp/ -[d logo]: ./assets/languages/d.svg +[d logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/d.svg [d integration]: https://github.com/chances/wasmer-d [`wasmer` Dub package]: https://code.dlang.org/packages/wasmer [d docs]: https://chances.github.io/wasmer-d -[python logo]: ./assets/languages/python.svg +[python logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/python.svg [python integration]: https://github.com/wasmerio/wasmer-python [`wasmer` pypi package]: https://pypi.org/project/wasmer/ [python docs]: https://github.com/wasmerio/wasmer-python#api-of-the-wasmer-extensionmodule -[go logo]: ./assets/languages/go.svg +[go logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/go.svg [go integration]: https://github.com/wasmerio/wasmer-go [`wasmer` go package]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer [go docs]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc -[php logo]: ./assets/languages/php.svg +[php logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/php.svg [php integration]: https://github.com/wasmerio/wasmer-php [`wasm` pecl package]: https://pecl.php.net/package/wasm [php docs]: https://wasmerio.github.io/wasmer-php/wasm/ -[js logo]: ./assets/languages/js.svg +[js logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/js.svg [js integration]: https://github.com/wasmerio/wasmer-js [`@wasmerio` npm packages]: https://www.npmjs.com/org/wasmer [js docs]: https://docs.wasmer.io/integrations/js/reference-api -[ruby logo]: ./assets/languages/ruby.svg +[ruby logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/ruby.svg [ruby integration]: https://github.com/wasmerio/wasmer-ruby [`wasmer` ruby gem]: https://rubygems.org/gems/wasmer [ruby docs]: https://www.rubydoc.info/gems/wasmer/ -[java logo]: ./assets/languages/java.svg +[java logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/java.svg [java integration]: https://github.com/wasmerio/wasmer-java [`wasmer/wasmer-jni` bintray package]: https://bintray.com/wasmer/wasmer-jni/wasmer-jni [java docs]: https://github.com/wasmerio/wasmer-java/#api-of-the-wasmer-library -[elixir logo]: ./assets/languages/elixir.svg +[elixir logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/elixir.svg [elixir integration]: https://github.com/tessi/wasmex [elixir docs]: https://hexdocs.pm/wasmex/api-reference.html [`wasmex` hex package]: https://hex.pm/packages/wasmex -[r logo]: ./assets/languages/r.svg +[r logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/r.svg [r integration]: https://github.com/dirkschumacher/wasmr [r docs]: https://github.com/dirkschumacher/wasmr#example -[postgres logo]: ./assets/languages/postgres.svg +[postgres logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/postgres.svg [postgres integration]: https://github.com/wasmerio/wasmer-postgres [postgres docs]: https://github.com/wasmerio/wasmer-postgres#usage--documentation diff --git a/docs/es/README.md b/docs/es/README.md index 53222920a..113fc5749 100644 --- a/docs/es/README.md +++ b/docs/es/README.md @@ -29,7 +29,7 @@ [Wasmer](https://wasmer.io/) hace posible tener contenedores ultraligeros basados en [WebAssembly](https://webassembly.org/) que pueden ser ejecutados en cualquier sitio: desde tu ordenador hasta la nube y dispositivos de IoT, además de ser [*any programming language*](https://github.com/wasmerio/wasmer#language-integrations). -> This README is also available in: [🇬🇧 English / Inglés](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇫🇷 Français / Francés](https://github.com/wasmerio/wasmer/blob/master/docs/fr/README.md) • [🇨🇳 中文 / Chino](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md). +> This README is also available in: [🇬🇧 English-Inglés](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇫🇷 Français-Francés](https://github.com/wasmerio/wasmer/blob/master/docs/fr/README.md) • [🇨🇳 中文-Chino](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md). ## Funcionalidades @@ -104,66 +104,66 @@ qjs > [👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) -[rust logo]: ./assets/languages/rust.svg +[rust logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/rust.svg [rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api [`wasmer` en crates.io]: https://crates.io/crates/wasmer/ [rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime -[c logo]: ./assets/languages/c.svg +[c logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/c.svg [c integration]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api [cabecera `wasmer.h`]: https://wasmerio.github.io/wasmer/c/ [c docs]: https://wasmerio.github.io/wasmer/c/ -[c# logo]: ./assets/languages/csharp.svg +[c# logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/csharp.svg [c# integration]: https://github.com/migueldeicaza/WasmerSharp [`wasmersharp` en NuGet]: https://www.nuget.org/packages/WasmerSharp/ [c# docs]: https://migueldeicaza.github.io/WasmerSharp/ -[d logo]: ./assets/languages/d.svg +[d logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/d.svg [d integration]: https://github.com/chances/wasmer-d [`wasmer` en Dub]: https://code.dlang.org/packages/wasmer [d docs]: https://chances.github.io/wasmer-d -[python logo]: ./assets/languages/python.svg +[python logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/python.svg [python integration]: https://github.com/wasmerio/wasmer-python [`wasmer` en pypi]: https://pypi.org/project/wasmer/ [python docs]: https://github.com/wasmerio/wasmer-python#api-of-the-wasmer-extensionmodule -[go logo]: ./assets/languages/go.svg +[go logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/go.svg [go integration]: https://github.com/wasmerio/wasmer-go [`wasmer` en go]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer [go docs]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc -[php logo]: ./assets/languages/php.svg +[php logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/php.svg [php integration]: https://github.com/wasmerio/wasmer-php [php docs]: https://wasmerio.github.io/wasmer-php/wasm/ [`wasm` en pecl]: https://pecl.php.net/package/wasm -[js logo]: ./assets/languages/js.svg +[js logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/js.svg [js integration]: https://github.com/wasmerio/wasmer-js [`@wasmerio` en npm]: https://www.npmjs.com/org/wasmer [js docs]: https://docs.wasmer.io/integrations/js/reference-api -[ruby logo]: ./assets/languages/ruby.svg +[ruby logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/ruby.svg [ruby integration]: https://github.com/wasmerio/wasmer-ruby [`wasmer` en ruby gems]: https://rubygems.org/gems/wasmer [ruby docs]: https://www.rubydoc.info/gems/wasmer/ -[java logo]: ./assets/languages/java.svg +[java logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/java.svg [java integration]: https://github.com/wasmerio/wasmer-java [`wasmer/wasmer-jni` en bintray]: https://bintray.com/wasmer/wasmer-jni/wasmer-jni [java docs]: https://github.com/wasmerio/wasmer-java/#api-of-the-wasmer-library -[elixir logo]: ./assets/languages/elixir.svg +[elixir logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/elixir.svg [elixir integration]: https://github.com/tessi/wasmex [elixir docs]: https://hexdocs.pm/wasmex/api-reference.html [`wasmex` en hex]: https://hex.pm/packages/wasmex -[r logo]: ./assets/languages/r.svg +[r logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/r.svg [r integration]: https://github.com/dirkschumacher/wasmr [r docs]: https://github.com/dirkschumacher/wasmr#example -[postgres logo]: ./assets/languages/postgres.svg +[postgres logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/postgres.svg [postgres integration]: https://github.com/wasmerio/wasmer-postgres [postgres docs]: https://github.com/wasmerio/wasmer-postgres#usage--documentation diff --git a/docs/fr/README.md b/docs/fr/README.md index afce98b40..747415651 100644 --- a/docs/fr/README.md +++ b/docs/fr/README.md @@ -29,7 +29,7 @@ [Wasmer](https://wasmer.io/) active des conteneurs super légers basés sur [WebAssembly](https://webassembly.org/) qui peuvent fonctionner n'importe où: du bureau au cloud et aux appareils IoT, et également intégrés dans [*tout langage de programmation*](https://github.com/wasmerio/wasmer#language-integrations). -> This readme is also available in: [🇬🇧 English / Anglaise](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español / Espagnol](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇨🇳 中文 / Chinoise](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md) +> This readme is also available in: [🇬🇧 English-Anglaise](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español-Espagnol](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇨🇳 中文-Chinoise](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md) ## Fonctionnalités @@ -104,66 +104,66 @@ qjs > [👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) -[rust logo]: ./assets/languages/rust.svg +[rust logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/rust.svg [rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api [`wasmer` rust crate]: https://crates.io/crates/wasmer/ [rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime -[c logo]: ./assets/languages/c.svg +[c logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/c.svg [c integration]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api [`wasmer.h` headers]: https://wasmerio.github.io/wasmer/c/ [c docs]: https://wasmerio.github.io/wasmer/c/ -[c# logo]: ./assets/languages/csharp.svg +[c# logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/csharp.svg [c# integration]: https://github.com/migueldeicaza/WasmerSharp [`wasmersharp` nuget package]: https://www.nuget.org/packages/WasmerSharp/ [c# docs]: https://migueldeicaza.github.io/WasmerSharp/ -[d logo]: ./assets/languages/d.svg +[d logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/d.svg [d integration]: https://github.com/chances/wasmer-d [`wasmer` Dub package]: https://code.dlang.org/packages/wasmer [d docs]: https://chances.github.io/wasmer-d -[python logo]: ./assets/languages/python.svg +[python logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/python.svg [python integration]: https://github.com/wasmerio/wasmer-python [`wasmer` pypi package]: https://pypi.org/project/wasmer/ [python docs]: https://github.com/wasmerio/wasmer-python#api-of-the-wasmer-extensionmodule -[go logo]: ./assets/languages/go.svg +[go logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/go.svg [go integration]: https://github.com/wasmerio/wasmer-go [`wasmer` go package]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer [go docs]: https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc -[php logo]: ./assets/languages/php.svg +[php logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/php.svg [php integration]: https://github.com/wasmerio/wasmer-php [`wasm` pecl package]: https://pecl.php.net/package/wasm [php docs]: https://wasmerio.github.io/wasmer-php/wasm/ -[js logo]: ./assets/languages/js.svg +[js logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/js.svg [js integration]: https://github.com/wasmerio/wasmer-js [`@wasmerio` npm packages]: https://www.npmjs.com/org/wasmer [js docs]: https://docs.wasmer.io/integrations/js/reference-api -[ruby logo]: ./assets/languages/ruby.svg +[ruby logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/ruby.svg [ruby integration]: https://github.com/wasmerio/wasmer-ruby [`wasmer` ruby gem]: https://rubygems.org/gems/wasmer [ruby docs]: https://www.rubydoc.info/gems/wasmer/ -[java logo]: ./assets/languages/java.svg +[java logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/java.svg [java integration]: https://github.com/wasmerio/wasmer-java [`wasmer/wasmer-jni` bintray package]: https://bintray.com/wasmer/wasmer-jni/wasmer-jni [java docs]: https://github.com/wasmerio/wasmer-java/#api-of-the-wasmer-library -[elixir logo]: ./assets/languages/elixir.svg +[elixir logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/elixir.svg [elixir integration]: https://github.com/tessi/wasmex [elixir docs]: https://hexdocs.pm/wasmex/api-reference.html [`wasmex` hex package]: https://hex.pm/packages/wasmex -[r logo]: ./assets/languages/r.svg +[r logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/r.svg [r integration]: https://github.com/dirkschumacher/wasmr [r docs]: https://github.com/dirkschumacher/wasmr#example -[postgres logo]: ./assets/languages/postgres.svg +[postgres logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/postgres.svg [postgres integration]: https://github.com/wasmerio/wasmer-postgres [postgres docs]: https://github.com/wasmerio/wasmer-postgres#usage--documentation From 5bcdbd958373fb9e7a31c08b25e5eb18bd1fa0cc Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 22 Mar 2021 13:24:58 +0100 Subject: [PATCH 05/26] Add more minor fixes --- docs/cn/README.md | 2 +- docs/es/README.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/cn/README.md b/docs/cn/README.md index af18d24ce..5fb952b30 100644 --- a/docs/cn/README.md +++ b/docs/cn/README.md @@ -27,7 +27,7 @@
-[Wasmer](https://wasmer.io/)使得能够基于 [WebAssembly](https://webassembly.org/),其可以在任何地方运行超轻型容器:从桌面到云和的IoT装置,并且也嵌入在 [*任何编程语言*](https://github.com/wasmerio/wasmer#language-integrations). +[Wasmer](https://wasmer.io/) 使得能够基于 [WebAssembly](https://webassembly.org/),其可以在任何地方运行超轻型容器:从桌面到云和的IoT装置,并且也嵌入在 [*任何编程语言*](https://github.com/wasmerio/wasmer#language-integrations). > This readme is also available in: [🇬🇧 English-英文](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español-西班牙语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇫🇷 Français-法语/法语](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md). diff --git a/docs/es/README.md b/docs/es/README.md index 113fc5749..13ee9dc8c 100644 --- a/docs/es/README.md +++ b/docs/es/README.md @@ -27,7 +27,7 @@
-[Wasmer](https://wasmer.io/) hace posible tener contenedores ultraligeros basados en [WebAssembly](https://webassembly.org/) que pueden ser ejecutados en cualquier sitio: desde tu ordenador hasta la nube y dispositivos de IoT, además de ser [*any programming language*](https://github.com/wasmerio/wasmer#language-integrations). +[Wasmer](https://wasmer.io/) hace posible tener contenedores ultraligeros basados en [WebAssembly](https://webassembly.org/) que pueden ser ejecutados en cualquier sitio: desde tu ordenador hasta la nube y dispositivos de IoT, además de poder ser ejecutados [*en cualquier lenguaje de programación*](https://github.com/wasmerio/wasmer#language-integrations). > This README is also available in: [🇬🇧 English-Inglés](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇫🇷 Français-Francés](https://github.com/wasmerio/wasmer/blob/master/docs/fr/README.md) • [🇨🇳 中文-Chino](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md). @@ -75,11 +75,11 @@ QuickJS - Type "\h" for help qjs > ``` -#### Here is what you can do next: +#### Esto es lo que puedes hacer: -- [Use Wasmer from your Rust application](https://docs.wasmer.io/integrations/rust) -- [Publish a Wasm package on WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) -- [Read more about Wasmer](https://medium.com/wasmer/) +- [Usa Wasmer desde tu aplicación de Rust](https://docs.wasmer.io/integrations/rust) +- [Publica un paquete de Wasm en WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) +- [Lee más sobre Wasmer](https://medium.com/wasmer/) ## Integraciones en diferentes Lenguajes From c212f74e1972566ebc62b9b79b2ca9c2fbf17740 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 22 Mar 2021 15:35:22 +0100 Subject: [PATCH 06/26] test: Implement `MemoryUsage` on test middlewares. --- Cargo.lock | 1 + Cargo.toml | 1 + tests/compilers/middlewares.rs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ebaca6ac..9ba2e51eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2701,6 +2701,7 @@ dependencies = [ "criterion", "glob", "lazy_static", + "loupe", "rustc_version 0.3.3", "tempfile", "test-generator", diff --git a/Cargo.toml b/Cargo.toml index 40fda1950..7bd6fe842 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,7 @@ criterion = "0.3" lazy_static = "1.4" wasmer-engine-dummy = { path = "tests/lib/engine-dummy" } tempfile = "3.1" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] # Don't add the compiler features in default, please add them on the Makefile diff --git a/tests/compilers/middlewares.rs b/tests/compilers/middlewares.rs index 3a9e55166..02eabc373 100644 --- a/tests/compilers/middlewares.rs +++ b/tests/compilers/middlewares.rs @@ -1,11 +1,12 @@ use crate::utils::get_store_with_middlewares; use anyhow::Result; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer::wasmparser::Operator; use wasmer::*; -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] struct Add2MulGen { value_off: i32, } @@ -47,7 +48,7 @@ impl FunctionMiddleware for Add2Mul { } } -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] struct FusionGen; #[derive(Debug)] From 10c6f26770f8d185fd6acfe93809ecf5b0e6872e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 22 Mar 2021 15:38:59 +0100 Subject: [PATCH 07/26] doc: Update the tunable exemple to include `MemoryUsage`. --- examples/tunables_limit_memory.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs index ccd1ac773..143682491 100644 --- a/examples/tunables_limit_memory.rs +++ b/examples/tunables_limit_memory.rs @@ -1,6 +1,8 @@ +use std::mem; use std::ptr::NonNull; use std::sync::Arc; +use loupe::{MemoryUsage, MemoryUsageTracker}; use wasmer::{ imports, vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition}, @@ -131,6 +133,12 @@ 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)))"#; From 5f5ec8e2b95afc1ff4dc48c5fd7069850e217259 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 23 Mar 2021 08:41:59 +0100 Subject: [PATCH 08/26] Apply suggestions from code review Co-authored-by: Julien BIANCHI --- docs/fr/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/fr/README.md b/docs/fr/README.md index 747415651..fcb30c92b 100644 --- a/docs/fr/README.md +++ b/docs/fr/README.md @@ -1,6 +1,6 @@
- Wasmer logo + Logo Wasmer

@@ -8,10 +8,10 @@ Build Status - License + Licence - Slack channel + Salon Slack

@@ -27,23 +27,23 @@
-[Wasmer](https://wasmer.io/) active des conteneurs super légers basés sur [WebAssembly](https://webassembly.org/) qui peuvent fonctionner n'importe où: du bureau au cloud et aux appareils IoT, et également intégrés dans [*tout langage de programmation*](https://github.com/wasmerio/wasmer#language-integrations). +[Wasmer](https://wasmer.io/) permet l'utilisation de conteneurs super légers basés sur [WebAssembly](https://webassembly.org/) qui peuvent fonctionner n'importe où : du bureau au cloud en passant par les appareils IoT, et également intégrés dans [*une multitude de langages de programmation*](https://github.com/wasmerio/wasmer#language-integrations). > This readme is also available in: [🇬🇧 English-Anglaise](https://github.com/wasmerio/wasmer/blob/master/README.md) • [🇪🇸 Español-Espagnol](https://github.com/wasmerio/wasmer/blob/master/docs/es/README.md) • [🇨🇳 中文-Chinoise](https://github.com/wasmerio/wasmer/blob/master/docs/cn/README.md) ## Fonctionnalités -* **Rapide et sûr**. Wasmer exécute WebAssembly à une vitesse *quasi native* dans un environnement entièrement bac à sable. +* **Rapide et sûr**. Wasmer exécute WebAssembly à une vitesse *quasi native* dans un environnement entièrement contrôlé (bac à sable, _sandbox_). * **Enfichable**. Wasmer prend en charge différents frameworks de compilation pour répondre au mieux à vos besoins (LLVM, Cranelift ...). * **Universal**. Vous pouvez exécuter Wasmer sur n'importe quelle *plate-forme* (macOS, Linux et Windows) et *chipset*. -* **Conforme aux normes**. Le runtime réussit [test officiel de WebAssembly suite](https://github.com/WebAssembly/testsuite) prenant en charge [WASI](https://github.com/WebAssembly/WASI) et [Emscripten](https://emscripten.org/) +* **Conforme aux normes**. Wasmer passe [la suite de tests officielle de WebAssembly](https://github.com/WebAssembly/testsuite) prenant en charge [WASI](https://github.com/WebAssembly/WASI) et [Emscripten](https://emscripten.org/) ## Quickstart -Wasmer est livré sans dépendances. Vous pouvez l'installer à l'aide des programmes d'installation ci-dessous: +Wasmer est livré sans aucune dépendance. Vous pouvez l'installer à l'aide des programmes d'installation ci-dessous: ```sh curl https://get.wasmer.io -sSfL | sh @@ -78,12 +78,12 @@ qjs > #### Voici ce que vous pouvez faire ensuite: - [Utilisez Wasmer depuis votre application Rust](https://docs.wasmer.io/integrations/rust) -- [Publier un package Wasm sur WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) +- [Publier un paquet Wasm sur WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) - [En savoir plus sur Wasmer](https://medium.com/wasmer/) ## Intégrations -📦 Le runtime Wasmer peut être utilisé comme une bibliothèque **intégrée dans différentes langues**, vous pouvez donc utiliser WebAssembly _anywhere_. +📦 Wasmer peut être utilisé comme une bibliothèque **intégrée dans différents langages**, vous pouvez donc utiliser WebAssembly _n'import où_. |   | Langage de programmation | Package | Docs | |-|-|-|-| @@ -102,7 +102,7 @@ qjs > | ![Postgres logo] | [**Postgres**][Postgres integration] | *no published package* | [Docs][postgres docs] | | | [**Swift**][Swift integration] | *no published package* | | -[👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) +[👋 Il manque un langage ?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) [rust logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/rust.svg [rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api @@ -173,11 +173,11 @@ qjs > **Nous accueillons toute forme de contribution, en particulier de la part des nouveaux membres de notre communauté** 💜 -Vous pouvez vérifier comment construire le runtime Wasmer dans [nos super documents](https://docs.wasmer.io/ecosystem/wasmer/building-from-source)! +Vous pouvez vérifier comment compiler Wasmer dans [nos super documents](https://docs.wasmer.io/ecosystem/wasmer/building-from-source)! ### Test -Test que vous voulez? La [documentation Wasmer vous montrera comment](https://docs.wasmer.io/ecosystem/wasmer/building-from-source/testing). +Vous voulez des tests ? La [documentation de Wasmer](https://docs.wasmer.io/ecosystem/wasmer/building-from-source/testing) vous montrera comment les exécuter. ## Communauté From 9b95945c70ee8cbac59f78da7b0d8b26b761345a Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 23 Mar 2021 09:05:45 +0100 Subject: [PATCH 09/26] Apply suggestions from code review Co-authored-by: Ivan Enderlin --- docs/cn/README.md | 2 +- docs/es/README.md | 2 +- docs/fr/README.md | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/cn/README.md b/docs/cn/README.md index 5fb952b30..8ccbe74e1 100644 --- a/docs/cn/README.md +++ b/docs/cn/README.md @@ -103,7 +103,7 @@ qjs > | ![Postgres logo] | [**Postgres**][Postgres integration] | *没有已发布的软件包* | [文件资料][postgres docs] | | | [**Swift**][Swift integration] | *没有已发布的软件包* | | -[👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) +[👋 缺少语言?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) [rust logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/rust.svg [rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api diff --git a/docs/es/README.md b/docs/es/README.md index 13ee9dc8c..8a6924a9f 100644 --- a/docs/es/README.md +++ b/docs/es/README.md @@ -102,7 +102,7 @@ qjs > | ![Postgres logo] | [**Postgres**][Postgres integration] | *sin paquete publicado* | [Documentación][postgres docs] | | | [**Swift**][Swift integration] | *sin paquete publicado* | | -[👋 Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) +[👋 Falta algún lenguaje?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=) [rust logo]: https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/languages/rust.svg [rust integration]: https://github.com/wasmerio/wasmer/tree/master/lib/api diff --git a/docs/fr/README.md b/docs/fr/README.md index fcb30c92b..e6f87a90e 100644 --- a/docs/fr/README.md +++ b/docs/fr/README.md @@ -5,7 +5,7 @@

- Build Status + État des tests Licence @@ -35,15 +35,15 @@ * **Rapide et sûr**. Wasmer exécute WebAssembly à une vitesse *quasi native* dans un environnement entièrement contrôlé (bac à sable, _sandbox_). -* **Enfichable**. Wasmer prend en charge différents frameworks de compilation pour répondre au mieux à vos besoins (LLVM, Cranelift ...). +* **Modulaire**. Wasmer prend en charge différents frameworks de compilation pour répondre au mieux à vos besoins (LLVM, Cranelift ...). -* **Universal**. Vous pouvez exécuter Wasmer sur n'importe quelle *plate-forme* (macOS, Linux et Windows) et *chipset*. +* **Universel**. Vous pouvez exécuter Wasmer sur n'importe quelle *plate-forme* (macOS, Linux et Windows) et *processeur*. * **Conforme aux normes**. Wasmer passe [la suite de tests officielle de WebAssembly](https://github.com/WebAssembly/testsuite) prenant en charge [WASI](https://github.com/WebAssembly/WASI) et [Emscripten](https://emscripten.org/) ## Quickstart -Wasmer est livré sans aucune dépendance. Vous pouvez l'installer à l'aide des programmes d'installation ci-dessous: +Wasmer est livré sans aucune dépendance. Vous pouvez l'installer à l'aide des programmes d'installation ci-dessous : ```sh curl https://get.wasmer.io -sSfL | sh @@ -65,9 +65,9 @@ iwr https://win.wasmer.io -useb | iex #### Exécution d'un fichier WebAssembly -Après avoir installé Wasmer, vous devriez être prêt à exécuter votre premier fichier WebAssemby! 🎉 +Après avoir installé Wasmer, vous devriez être prêt à exécuter votre premier fichier WebAssemby ! 🎉 -Vous pouvez commencer par exécuter QuickJS: [qjs.wasm](https://registry-cdn.wapm.io/contents/_/quickjs/0.0.3/build/qjs.wasm) +Vous pouvez commencer par exécuter QuickJS : [qjs.wasm](https://registry-cdn.wapm.io/contents/_/quickjs/0.0.3/build/qjs.wasm) ```bash $ wasmer qjs.wasm @@ -75,7 +75,7 @@ QuickJS - Type "\h" for help qjs > ``` -#### Voici ce que vous pouvez faire ensuite: +#### Voici ce que vous pouvez faire ensuite - [Utilisez Wasmer depuis votre application Rust](https://docs.wasmer.io/integrations/rust) - [Publier un paquet Wasm sur WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package) @@ -171,9 +171,9 @@ qjs > ## Contribuer -**Nous accueillons toute forme de contribution, en particulier de la part des nouveaux membres de notre communauté** 💜 +**Nous accueillons toutes formes de contributions, en particulier de la part des nouveaux membres de notre communauté**. 💜 -Vous pouvez vérifier comment compiler Wasmer dans [nos super documents](https://docs.wasmer.io/ecosystem/wasmer/building-from-source)! +Vous pouvez vérifier comment compiler Wasmer dans [notre documentation](https://docs.wasmer.io/ecosystem/wasmer/building-from-source)! ### Test @@ -181,9 +181,9 @@ Vous voulez des tests ? La [documentation de Wasmer](https://docs.wasmer.io/ecos ## Communauté -Wasmer a une incroyable communauté de développeurs et de contributeurs. Bienvenue, rejoignez-nous! 👋 +Wasmer a une incroyable communauté de développeurs et de contributeurs. Bienvenue et rejoignez-nous ! 👋 -### Canaux +### Canaux de communications - [Slack](https://slack.wasmer.io/) - [Twitter](https://twitter.com/wasmerio) From 1a2dbdaef6a438c72840a1af2c002c4e16f2968c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 09:23:58 +0100 Subject: [PATCH 10/26] fix(engine-jit) Fix `MemoryUsage` on Windows. --- lib/engine-jit/src/unwind/windows_x64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/engine-jit/src/unwind/windows_x64.rs b/lib/engine-jit/src/unwind/windows_x64.rs index 1db1658ac..7d9e017c8 100644 --- a/lib/engine-jit/src/unwind/windows_x64.rs +++ b/lib/engine-jit/src/unwind/windows_x64.rs @@ -118,7 +118,7 @@ impl MemoryUsage for UnwindRegistry { // [doc2]: https://docs.rs/winapi/0.3.9/winapi/um/winnt/struct._IMAGE_RUNTIME_FUNCTION_ENTRY.html self.functions .iter() - .map(|(key, _)| (key, std::mem::size_of::() * 3)) + .map(|(_, _)| std::mem::size_of::() * 3) .sum::() + self.published.size_of_val(tracker) } From 4b752ed498ecbdf6c3d196f7bdc097693dce41e0 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 11:18:31 +0100 Subject: [PATCH 11/26] chore: Use `loupe` 0.1.0. --- Cargo.lock | 6 ++- Cargo.toml | 2 +- fuzz/Cargo.lock | 59 ++++++++++++++++++++++++------ lib/api/Cargo.toml | 2 +- lib/compiler-cranelift/Cargo.toml | 2 +- lib/compiler-llvm/Cargo.toml | 2 +- lib/compiler-singlepass/Cargo.toml | 2 +- lib/compiler/Cargo.toml | 2 +- lib/engine-jit/Cargo.toml | 2 +- lib/engine-native/Cargo.toml | 2 +- lib/engine-object-file/Cargo.toml | 2 +- lib/engine/Cargo.toml | 2 +- lib/middlewares/Cargo.toml | 2 +- lib/vm/Cargo.toml | 2 +- lib/wasmer-types/Cargo.toml | 2 +- tests/lib/engine-dummy/Cargo.toml | 2 +- 16 files changed, 66 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ba2e51eb..052da5f44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1157,7 +1157,8 @@ dependencies = [ [[package]] name = "loupe" version = "0.1.0" -source = "git+https://github.com/wasmerio/loupe?branch=master#63c2f4a5acf1f3a8ed3568119cad96a731c71d21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0700ebea6c2a63815aa6f376f1c6dac93223d7b11c4728a7f71ff951a6eca67" dependencies = [ "loupe-derive", "rustversion", @@ -1166,7 +1167,8 @@ dependencies = [ [[package]] name = "loupe-derive" version = "0.1.0" -source = "git+https://github.com/wasmerio/loupe?branch=master#63c2f4a5acf1f3a8ed3568119cad96a731c71d21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9a2f753a29753600fa1e3f5c2b311babaca3bb66929bdc37082996e9c46cfb" dependencies = [ "quote", "syn", diff --git a/Cargo.toml b/Cargo.toml index 7bd6fe842..94c27a92e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ criterion = "0.3" lazy_static = "1.4" wasmer-engine-dummy = { path = "tests/lib/engine-dummy" } tempfile = "3.1" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [features] # Don't add the compiler features in default, please add them on the Makefile diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 9d6af389f..456f4fbf9 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -28,9 +28,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" +checksum = "81cddc5f91628367664cc7c69714ff08deee8a3efc54623011c772544d7b2767" [[package]] name = "arbitrary" @@ -454,9 +454,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.89" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "538c092e5586f4cdd7dd8078c4a79220e3e168880218124dcbce860f0ea938c6" +checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" [[package]] name = "libfuzzer-sys" @@ -509,6 +509,26 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "loupe" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0700ebea6c2a63815aa6f376f1c6dac93223d7b11c4728a7f71ff951a6eca67" +dependencies = [ + "loupe-derive", + "rustversion", +] + +[[package]] +name = "loupe-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9a2f753a29753600fa1e3f5c2b311babaca3bb66929bdc37082996e9c46cfb" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "mach" version = "0.3.2" @@ -822,6 +842,12 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustversion" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" + [[package]] name = "scopeguard" version = "1.1.0" @@ -883,9 +909,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.124" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" +checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" dependencies = [ "serde_derive", ] @@ -901,9 +927,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.124" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" +checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ "proc-macro2", "quote", @@ -1038,7 +1064,7 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-encoder" version = "0.4.0" -source = "git+https://github.com/bytecodealliance/wasm-tools#ea17086f38b3bd452a99340109bfdc9759f109a1" +source = "git+https://github.com/bytecodealliance/wasm-tools#4e86f2a84fc54264388040b200eb32a165ec6453" dependencies = [ "leb128", ] @@ -1046,7 +1072,7 @@ dependencies = [ [[package]] name = "wasm-smith" version = "0.4.0" -source = "git+https://github.com/bytecodealliance/wasm-tools#ea17086f38b3bd452a99340109bfdc9759f109a1" +source = "git+https://github.com/bytecodealliance/wasm-tools#4e86f2a84fc54264388040b200eb32a165ec6453" dependencies = [ "arbitrary", "indexmap", @@ -1060,6 +1086,7 @@ version = "1.0.2" dependencies = [ "cfg-if 0.1.10", "indexmap", + "loupe", "more-asserts", "target-lexicon", "thiserror", @@ -1096,6 +1123,7 @@ name = "wasmer-compiler" version = "1.0.2" dependencies = [ "enumset", + "loupe", "serde", "serde_bytes", "smallvec", @@ -1111,8 +1139,10 @@ name = "wasmer-compiler-cranelift" version = "1.0.2" dependencies = [ "cranelift-codegen", + "cranelift-entity", "cranelift-frontend", "gimli", + "loupe", "more-asserts", "rayon", "serde", @@ -1134,6 +1164,7 @@ dependencies = [ "itertools", "lazy_static", "libc", + "loupe", "rayon", "regex", "rustc_version", @@ -1153,6 +1184,7 @@ dependencies = [ "dynasm", "dynasmrt", "lazy_static", + "loupe", "more-asserts", "rayon", "serde", @@ -1179,6 +1211,7 @@ dependencies = [ "backtrace", "bincode", "lazy_static", + "loupe", "memmap2", "more-asserts", "rustc-demangle", @@ -1197,6 +1230,7 @@ version = "1.0.2" dependencies = [ "bincode", "cfg-if 0.1.10", + "loupe", "region", "serde", "serde_bytes", @@ -1215,6 +1249,7 @@ dependencies = [ "cfg-if 0.1.10", "leb128", "libloading", + "loupe", "serde", "tempfile", "tracing", @@ -1230,6 +1265,7 @@ dependencies = [ name = "wasmer-middlewares" version = "1.0.2" dependencies = [ + "loupe", "wasmer", "wasmer-types", "wasmer-vm", @@ -1249,7 +1285,7 @@ dependencies = [ name = "wasmer-types" version = "1.0.2" dependencies = [ - "cranelift-entity", + "loupe", "serde", "thiserror", ] @@ -1263,6 +1299,7 @@ dependencies = [ "cfg-if 0.1.10", "indexmap", "libc", + "loupe", "memoffset", "more-asserts", "region", diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index f69280e6d..817061f0d 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -27,7 +27,7 @@ wat = { version = "1.0", optional = true } thiserror = "1.0" more-asserts = "0.2" target-lexicon = { version = "0.11", default-features = false } -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [target.'cfg(target_os = "windows")'.dependencies] winapi = "0.3" diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index cb0d3630d..c5ec84b03 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -25,7 +25,7 @@ serde = { version = "1.0", features = ["derive"] } more-asserts = "0.2" gimli = { version = "0.23", optional = true } smallvec = "1.6" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index d6aac52fa..04052feaf 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -22,7 +22,7 @@ libc = { version = "^0.2", default-features = false } byteorder = "1" itertools = "0.10" rayon = "1.5" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [dependencies.inkwell] version = "=0.1.0-beta.2" diff --git a/lib/compiler-singlepass/Cargo.toml b/lib/compiler-singlepass/Cargo.toml index ede05f8bb..9af24654b 100644 --- a/lib/compiler-singlepass/Cargo.toml +++ b/lib/compiler-singlepass/Cargo.toml @@ -24,7 +24,7 @@ dynasmrt = "1.0" lazy_static = "1.4" byteorder = "1.3" smallvec = "1.6" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index 579f7814e..1c3941963 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive"], optional = true } thiserror = "1.0" serde_bytes = { version = "0.11", optional = true } smallvec = "1.6" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [features] default = ["std", "enable-serde"] diff --git a/lib/engine-jit/Cargo.toml b/lib/engine-jit/Cargo.toml index 38b70474e..9d54965d4 100644 --- a/lib/engine-jit/Cargo.toml +++ b/lib/engine-jit/Cargo.toml @@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" cfg-if = "0.1" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winnt", "impl-default"] } diff --git a/lib/engine-native/Cargo.toml b/lib/engine-native/Cargo.toml index be045b7a4..3e69503a1 100644 --- a/lib/engine-native/Cargo.toml +++ b/lib/engine-native/Cargo.toml @@ -24,7 +24,7 @@ leb128 = "0.2" libloading = "0.7" tempfile = "3.1" which = "4.0" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine-object-file/Cargo.toml b/lib/engine-object-file/Cargo.toml index 17ee1e016..51defdb94 100644 --- a/lib/engine-object-file/Cargo.toml +++ b/lib/engine-object-file/Cargo.toml @@ -23,7 +23,7 @@ bincode = "1.3" leb128 = "0.2" libloading = "0.7" tempfile = "3.1" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml index a8ae21bec..8cd8c2f54 100644 --- a/lib/engine/Cargo.toml +++ b/lib/engine/Cargo.toml @@ -25,7 +25,7 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" lazy_static = "1.4" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [badges] maintenance = { status = "actively-developed" } diff --git a/lib/middlewares/Cargo.toml b/lib/middlewares/Cargo.toml index 5fd6837df..3cf6cca76 100644 --- a/lib/middlewares/Cargo.toml +++ b/lib/middlewares/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" wasmer = { path = "../api", version = "1.0.2" } wasmer-types = { path = "../wasmer-types", version = "1.0.2" } wasmer-vm = { path = "../vm", version = "1.0.2" } -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [badges] maintenance = { status = "actively-developed" } diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index cc12923e6..a721dc115 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 = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] } diff --git a/lib/wasmer-types/Cargo.toml b/lib/wasmer-types/Cargo.toml index 8bff64a3d..340c0fe19 100644 --- a/lib/wasmer-types/Cargo.toml +++ b/lib/wasmer-types/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"], optional = true, default-features = false } thiserror = "1.0" -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [features] default = ["std", "enable-serde"] diff --git a/tests/lib/engine-dummy/Cargo.toml b/tests/lib/engine-dummy/Cargo.toml index 2a12de6d8..01a50903a 100644 --- a/tests/lib/engine-dummy/Cargo.toml +++ b/tests/lib/engine-dummy/Cargo.toml @@ -15,7 +15,7 @@ wasmer-engine = { path = "../../../lib/engine", version = "1.0.2" } serde = { version = "1.0", features = ["derive", "rc"], optional = true } serde_bytes = { version = "0.11", optional = true } bincode = { version = "1.2", optional = true } -loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } +loupe = "0.1" [features] # Enable the `compiler` feature if you want the engine to compile From 0fe618a803b3ad07a8782bd724506b7c5ffd50c9 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 11:19:57 +0100 Subject: [PATCH 12/26] doc(changelog) Add #2199. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 258168311..4086e134e 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 +- [#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 - [#2144](https://github.com/wasmerio/wasmer/pull/2144) Bump cranelift version to 0.70 From 44dc884260b030dfb4f8e015f74b0ed3c5756815 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 11:23:32 +0100 Subject: [PATCH 13/26] feat: Start implementing `loupe::MemoryUsage` on `wasmer::Module`. --- Cargo.lock | 1 + lib/api/src/module.rs | 3 +- lib/compiler-llvm/src/config.rs | 2 +- lib/compiler/src/address_map.rs | 5 ++- lib/compiler/src/function.rs | 7 +-- lib/compiler/src/jump_table.rs | 3 +- lib/compiler/src/module.rs | 3 +- lib/compiler/src/relocation.rs | 7 +-- lib/compiler/src/section.rs | 9 ++-- lib/compiler/src/sourceloc.rs | 4 +- lib/compiler/src/target.rs | 2 +- lib/compiler/src/trap.rs | 3 +- lib/compiler/src/unwind.rs | 3 +- lib/engine-jit/src/artifact.rs | 3 ++ lib/engine-jit/src/serialize.rs | 5 ++- lib/engine-native/src/artifact.rs | 3 ++ lib/engine-native/src/engine.rs | 2 +- lib/engine-native/src/serialize.rs | 3 +- lib/engine-object-file/src/artifact.rs | 3 ++ lib/engine-object-file/src/serialize.rs | 4 +- lib/engine/src/artifact.rs | 3 +- lib/engine/src/serialize.rs | 5 ++- lib/engine/src/trap/frame_info.rs | 2 + lib/vm/Cargo.toml | 2 +- lib/vm/src/global.rs | 3 +- lib/vm/src/instance/mod.rs | 13 +++++- lib/vm/src/lib.rs | 3 +- lib/vm/src/libcalls.rs | 3 +- lib/vm/src/memory.rs | 12 ++--- lib/vm/src/module.rs | 5 ++- lib/vm/src/table.rs | 10 +++-- lib/vm/src/trap/trapcode.rs | 3 +- lib/vm/src/vmcontext.rs | 47 +++++++++++++++++--- lib/wasmer-types/src/entity/boxed_slice.rs | 17 +++++++ lib/wasmer-types/src/entity/primary_map.rs | 17 +++++++ lib/wasmer-types/src/entity/secondary_map.rs | 17 +++++++ lib/wasmer-types/src/initializers.rs | 7 +-- lib/wasmer-types/src/types.rs | 12 ++--- tests/lib/engine-dummy/src/artifact.rs | 5 ++- 39 files changed, 197 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 052da5f44..1223629af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1162,6 +1162,7 @@ checksum = "f0700ebea6c2a63815aa6f376f1c6dac93223d7b11c4728a7f71ff951a6eca67" dependencies = [ "loupe-derive", "rustversion", + "indexmap", ] [[package]] diff --git a/lib/api/src/module.rs b/lib/api/src/module.rs index 714991cba..7702fb56d 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_derive::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-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 245a27e92..fdcc5fad3 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -5,7 +5,7 @@ use inkwell::targets::{ }; pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use std::fmt::Debug; use std::sync::Arc; use target_lexicon::Architecture; diff --git a/lib/compiler/src/address_map.rs b/lib/compiler/src/address_map.rs index 40d37a073..ab6b227da 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_derive::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 6be0ae9ac..f2567559d 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_derive::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 19da678c7..5f4ff41c5 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_derive::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 dacbdf356..a0e90c186 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_derive::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 c0e6306ed..8e110a274 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_derive::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 096cbcc8c..8879a4573 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_derive::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 2964e144d..82b3577d4 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_derive::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/target.rs b/lib/compiler/src/target.rs index 12b2b06f1..1f569b3d5 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,7 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, diff --git a/lib/compiler/src/trap.rs b/lib/compiler/src/trap.rs index 058f7e21c..e52767bbe 100644 --- a/lib/compiler/src/trap.rs +++ b/lib/compiler/src/trap.rs @@ -1,11 +1,12 @@ use crate::CodeOffset; +use loupe_derive::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 309492814..fce474a7f 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_derive::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 e9d91e10b..fdba30969 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_derive::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, + #[memoryusage(ignore)] 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 92596ff33..b02823a53 100644 --- a/lib/engine-jit/src/serialize.rs +++ b/lib/engine-jit/src/serialize.rs @@ -1,3 +1,4 @@ +use loupe_derive::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 8c77216cf..c767a576d 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_derive::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, + #[memoryusage(ignore)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 84f857fd6..a7797b98a 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,7 +2,7 @@ use crate::NativeArtifact; use libloading::Library; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; diff --git a/lib/engine-native/src/serialize.rs b/lib/engine-native/src/serialize.rs index 88fa9965d..b1bdf0595 100644 --- a/lib/engine-native/src/serialize.rs +++ b/lib/engine-native/src/serialize.rs @@ -1,10 +1,11 @@ +use loupe_derive::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 fcba78722..46c370269 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_derive::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, + #[memoryusage(ignore)] 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 8ec7da030..30143a66a 100644 --- a/lib/engine-object-file/src/serialize.rs +++ b/lib/engine-object-file/src/serialize.rs @@ -1,10 +1,11 @@ +use loupe_derive::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 3a93fe4ce..db420f4f9 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 d501332c9..240fba41c 100644 --- a/lib/engine/src/serialize.rs +++ b/lib/engine/src/serialize.rs @@ -1,3 +1,4 @@ +use loupe_derive::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 8906a4478..c479e2341 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_derive::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 a721dc115..4e95f79f0 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 bdf65af63..e04825807 100644 --- a/lib/vm/src/global.rs +++ b/lib/vm/src/global.rs @@ -1,11 +1,12 @@ use crate::vmcontext::VMGlobalDefinition; +use loupe_derive::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 77849e3b2..986ee9d51 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 c46eab9fe..57753fca9 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_derive::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 5267d35a6..00c50b4fa 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_derive::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 8ab785605..037e9d056 100644 --- a/lib/vm/src/memory.rs +++ b/lib/vm/src/memory.rs @@ -7,6 +7,8 @@ use crate::mmap::Mmap; use crate::vmcontext::VMMemoryDefinition; +use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use more_asserts::assert_ge; use serde::{Deserialize, Serialize}; use std::borrow::BorrowMut; @@ -61,7 +63,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 +98,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 +118,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 +146,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 +169,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 82d951f46..6f7ccefff 100644 --- a/lib/vm/src/module.rs +++ b/lib/vm/src/module.rs @@ -5,6 +5,7 @@ //! `wasmer::Module`. use indexmap::IndexMap; +use loupe_derive::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 66fb0e8a1..aa423bee3 100644 --- a/lib/vm/src/table.rs +++ b/lib/vm/src/table.rs @@ -7,6 +7,8 @@ use crate::trap::{Trap, TrapCode}; use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition}; +use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use serde::{Deserialize, Serialize}; use std::borrow::{Borrow, BorrowMut}; use std::cell::UnsafeCell; @@ -17,14 +19,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 +105,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 +119,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 32121fbd0..e3740339e 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_derive::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 929c1126f..9479f8121 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 4f9aa95ea..19fdd4b45 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 c82bf4d5a..a3a07eec8 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 9fd474d4d..ac19c432f 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 0d47554c5..d8cf3d51b 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_derive::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 168f94761..3f5d8f5d8 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 ea542256d..89e3070a7 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_derive::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, + #[memoryusage(ignore)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, From 03486f3b8a9608673c8e909dcee4f4ac3a19d122 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 22 Mar 2021 12:10:39 +0100 Subject: [PATCH 14/26] feat: Use latest version of `loupe`. --- Cargo.lock | 2 +- lib/api/src/module.rs | 2 +- lib/compiler-llvm/src/config.rs | 2 +- lib/compiler/src/address_map.rs | 2 +- lib/compiler/src/function.rs | 2 +- lib/compiler/src/jump_table.rs | 2 +- lib/compiler/src/module.rs | 2 +- lib/compiler/src/relocation.rs | 2 +- lib/compiler/src/section.rs | 2 +- lib/compiler/src/sourceloc.rs | 2 +- lib/compiler/src/target.rs | 2 +- lib/compiler/src/trap.rs | 2 +- lib/compiler/src/unwind.rs | 2 +- lib/engine-jit/src/artifact.rs | 4 ++-- lib/engine-jit/src/serialize.rs | 2 +- lib/engine-native/src/artifact.rs | 4 ++-- lib/engine-native/src/engine.rs | 2 +- lib/engine-native/src/serialize.rs | 2 +- lib/engine-object-file/src/artifact.rs | 2 +- lib/engine-object-file/src/serialize.rs | 2 +- lib/engine/src/serialize.rs | 2 +- lib/engine/src/trap/frame_info.rs | 2 +- lib/vm/src/global.rs | 2 +- lib/vm/src/lib.rs | 2 +- lib/vm/src/libcalls.rs | 2 +- lib/vm/src/memory.rs | 1 - lib/vm/src/module.rs | 2 +- lib/vm/src/table.rs | 1 - lib/vm/src/trap/trapcode.rs | 2 +- lib/wasmer-types/src/initializers.rs | 2 +- 30 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1223629af..4f48c1e1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1160,9 +1160,9 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0700ebea6c2a63815aa6f376f1c6dac93223d7b11c4728a7f71ff951a6eca67" dependencies = [ + "indexmap", "loupe-derive", "rustversion", - "indexmap", ] [[package]] diff --git a/lib/api/src/module.rs b/lib/api/src/module.rs index 7702fb56d..ea2b8b8d8 100644 --- a/lib/api/src/module.rs +++ b/lib/api/src/module.rs @@ -1,7 +1,7 @@ use crate::store::Store; use crate::types::{ExportType, ImportType}; use crate::InstantiationError; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt; use std::io; use std::path::Path; diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index fdcc5fad3..245a27e92 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -5,7 +5,7 @@ use inkwell::targets::{ }; pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt::Debug; use std::sync::Arc; use target_lexicon::Architecture; diff --git a/lib/compiler/src/address_map.rs b/lib/compiler/src/address_map.rs index ab6b227da..4fd8c1a23 100644 --- a/lib/compiler/src/address_map.rs +++ b/lib/compiler/src/address_map.rs @@ -3,7 +3,7 @@ use crate::lib::std::vec::Vec; use crate::sourceloc::SourceLoc; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/compiler/src/function.rs b/lib/compiler/src/function.rs index f2567559d..e431f3bb7 100644 --- a/lib/compiler/src/function.rs +++ b/lib/compiler/src/function.rs @@ -12,7 +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_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::PrimaryMap; diff --git a/lib/compiler/src/jump_table.rs b/lib/compiler/src/jump_table.rs index 5f4ff41c5..25fdbb60c 100644 --- a/lib/compiler/src/jump_table.rs +++ b/lib/compiler/src/jump_table.rs @@ -5,7 +5,7 @@ //! [Learn more](https://en.wikipedia.org/wiki/Branch_table). use super::CodeOffset; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::{entity_impl, SecondaryMap}; diff --git a/lib/compiler/src/module.rs b/lib/compiler/src/module.rs index a0e90c186..b78821312 100644 --- a/lib/compiler/src/module.rs +++ b/lib/compiler/src/module.rs @@ -1,5 +1,5 @@ use crate::lib::std::sync::Arc; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::PrimaryMap; diff --git a/lib/compiler/src/relocation.rs b/lib/compiler/src/relocation.rs index 8e110a274..25cec340a 100644 --- a/lib/compiler/src/relocation.rs +++ b/lib/compiler/src/relocation.rs @@ -13,7 +13,7 @@ use crate::lib::std::fmt; use crate::lib::std::vec::Vec; use crate::section::SectionIndex; use crate::{Addend, CodeOffset, JumpTable}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::PrimaryMap; diff --git a/lib/compiler/src/section.rs b/lib/compiler/src/section.rs index 8879a4573..f6f3ee404 100644 --- a/lib/compiler/src/section.rs +++ b/lib/compiler/src/section.rs @@ -7,7 +7,7 @@ use crate::lib::std::vec::Vec; use crate::Relocation; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_types::entity::entity_impl; diff --git a/lib/compiler/src/sourceloc.rs b/lib/compiler/src/sourceloc.rs index 82b3577d4..fa61e4ab8 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_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 1f569b3d5..12b2b06f1 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,7 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, diff --git a/lib/compiler/src/trap.rs b/lib/compiler/src/trap.rs index e52767bbe..80aecc73a 100644 --- a/lib/compiler/src/trap.rs +++ b/lib/compiler/src/trap.rs @@ -1,5 +1,5 @@ use crate::CodeOffset; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmer_vm::TrapCode; diff --git a/lib/compiler/src/unwind.rs b/lib/compiler/src/unwind.rs index fce474a7f..128c300de 100644 --- a/lib/compiler/src/unwind.rs +++ b/lib/compiler/src/unwind.rs @@ -6,7 +6,7 @@ //! //! [Learn more](https://en.wikipedia.org/wiki/Call_stack). use crate::lib::std::vec::Vec; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; diff --git a/lib/engine-jit/src/artifact.rs b/lib/engine-jit/src/artifact.rs index fdba30969..d0a548bb8 100644 --- a/lib/engine-jit/src/artifact.rs +++ b/lib/engine-jit/src/artifact.rs @@ -6,7 +6,7 @@ use crate::link::link_module; #[cfg(feature = "compiler")] use crate::serialize::SerializableCompilation; use crate::serialize::SerializableModule; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::{Arc, Mutex}; use wasmer_compiler::{CompileError, Features, Triple}; #[cfg(feature = "compiler")] @@ -31,7 +31,7 @@ use wasmer_vm::{ pub struct JITArtifact { serializable: SerializableModule, finished_functions: BoxedSlice, - #[memoryusage(ignore)] + #[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 b02823a53..c924381b9 100644 --- a/lib/engine-jit/src/serialize.rs +++ b/lib/engine-jit/src/serialize.rs @@ -1,4 +1,4 @@ -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use wasmer_compiler::{ CompileModuleInfo, CustomSection, Dwarf, FunctionBody, JumpTableOffsets, Relocation, diff --git a/lib/engine-native/src/artifact.rs b/lib/engine-native/src/artifact.rs index c767a576d..7f93b3f97 100644 --- a/lib/engine-native/src/artifact.rs +++ b/lib/engine-native/src/artifact.rs @@ -4,7 +4,7 @@ use crate::engine::{NativeEngine, NativeEngineInner}; use crate::serialize::ModuleMetadata; use libloading::{Library, Symbol as LibrarySymbol}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::error::Error; use std::fs::File; use std::io::{Read, Write}; @@ -43,7 +43,7 @@ pub struct NativeArtifact { sharedobject_path: PathBuf, metadata: ModuleMetadata, finished_functions: BoxedSlice, - #[memoryusage(ignore)] + #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index a7797b98a..84f857fd6 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,7 +2,7 @@ use crate::NativeArtifact; use libloading::Library; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; diff --git a/lib/engine-native/src/serialize.rs b/lib/engine-native/src/serialize.rs index b1bdf0595..47c012d77 100644 --- a/lib/engine-native/src/serialize.rs +++ b/lib/engine-native/src/serialize.rs @@ -1,4 +1,4 @@ -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use wasmer_compiler::{CompileModuleInfo, SectionIndex, Symbol, SymbolRegistry}; use wasmer_types::entity::{EntityRef, PrimaryMap}; diff --git a/lib/engine-object-file/src/artifact.rs b/lib/engine-object-file/src/artifact.rs index 46c370269..d5314f012 100644 --- a/lib/engine-object-file/src/artifact.rs +++ b/lib/engine-object-file/src/artifact.rs @@ -3,7 +3,7 @@ use crate::engine::{ObjectFileEngine, ObjectFileEngineInner}; use crate::serialize::{ModuleMetadata, ModuleMetadataSymbolRegistry}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::collections::BTreeMap; use std::error::Error; use std::mem; diff --git a/lib/engine-object-file/src/serialize.rs b/lib/engine-object-file/src/serialize.rs index 30143a66a..4077b68e6 100644 --- a/lib/engine-object-file/src/serialize.rs +++ b/lib/engine-object-file/src/serialize.rs @@ -1,4 +1,4 @@ -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use wasmer_compiler::{CompileModuleInfo, SectionIndex, Symbol, SymbolRegistry}; use wasmer_types::entity::{EntityRef, PrimaryMap}; diff --git a/lib/engine/src/serialize.rs b/lib/engine/src/serialize.rs index 240fba41c..a36b47da3 100644 --- a/lib/engine/src/serialize.rs +++ b/lib/engine/src/serialize.rs @@ -1,4 +1,4 @@ -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use serde::de::{Deserializer, Visitor}; use serde::ser::Serializer; use serde::{Deserialize, Serialize}; diff --git a/lib/engine/src/trap/frame_info.rs b/lib/engine/src/trap/frame_info.rs index c479e2341..3407ab742 100644 --- a/lib/engine/src/trap/frame_info.rs +++ b/lib/engine/src/trap/frame_info.rs @@ -11,7 +11,7 @@ //! FRAME_INFO.register(module, compiled_functions); //! ``` use crate::serialize::SerializableFunctionFrameInfo; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::cmp; use std::collections::BTreeMap; use std::sync::{Arc, RwLock}; diff --git a/lib/vm/src/global.rs b/lib/vm/src/global.rs index e04825807..35f41fdfd 100644 --- a/lib/vm/src/global.rs +++ b/lib/vm/src/global.rs @@ -1,5 +1,5 @@ use crate::vmcontext::VMGlobalDefinition; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::cell::UnsafeCell; use std::ptr::NonNull; use std::sync::Mutex; diff --git a/lib/vm/src/lib.rs b/lib/vm/src/lib.rs index 57753fca9..8d63c3039 100644 --- a/lib/vm/src/lib.rs +++ b/lib/vm/src/lib.rs @@ -56,7 +56,7 @@ pub use crate::vmcontext::{ VMTableImport, VMTrampoline, }; pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMOffsets}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/vm/src/libcalls.rs b/lib/vm/src/libcalls.rs index 00c50b4fa..a602af1ac 100644 --- a/lib/vm/src/libcalls.rs +++ b/lib/vm/src/libcalls.rs @@ -38,7 +38,7 @@ use crate::probestack::PROBESTACK; use crate::trap::{raise_lib_trap, Trap, TrapCode}; use crate::vmcontext::VMContext; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use std::fmt; use wasmer_types::{DataIndex, ElemIndex, LocalMemoryIndex, MemoryIndex, TableIndex}; diff --git a/lib/vm/src/memory.rs b/lib/vm/src/memory.rs index 037e9d056..e64cfd132 100644 --- a/lib/vm/src/memory.rs +++ b/lib/vm/src/memory.rs @@ -8,7 +8,6 @@ use crate::mmap::Mmap; use crate::vmcontext::VMMemoryDefinition; use loupe::MemoryUsage; -use loupe_derive::MemoryUsage; use more_asserts::assert_ge; use serde::{Deserialize, Serialize}; use std::borrow::BorrowMut; diff --git a/lib/vm/src/module.rs b/lib/vm/src/module.rs index 6f7ccefff..d43aa5dce 100644 --- a/lib/vm/src/module.rs +++ b/lib/vm/src/module.rs @@ -5,7 +5,7 @@ //! `wasmer::Module`. use indexmap::IndexMap; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fmt; diff --git a/lib/vm/src/table.rs b/lib/vm/src/table.rs index aa423bee3..90f2069a1 100644 --- a/lib/vm/src/table.rs +++ b/lib/vm/src/table.rs @@ -8,7 +8,6 @@ use crate::trap::{Trap, TrapCode}; use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition}; use loupe::MemoryUsage; -use loupe_derive::MemoryUsage; use serde::{Deserialize, Serialize}; use std::borrow::{Borrow, BorrowMut}; use std::cell::UnsafeCell; diff --git a/lib/vm/src/trap/trapcode.rs b/lib/vm/src/trap/trapcode.rs index e3740339e..31a25765f 100644 --- a/lib/vm/src/trap/trapcode.rs +++ b/lib/vm/src/trap/trapcode.rs @@ -5,7 +5,7 @@ use core::fmt::{self, Display, Formatter}; use core::str::FromStr; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use serde::{Deserialize, Serialize}; use thiserror::Error; diff --git a/lib/wasmer-types/src/initializers.rs b/lib/wasmer-types/src/initializers.rs index d8cf3d51b..3683ecf04 100644 --- a/lib/wasmer-types/src/initializers.rs +++ b/lib/wasmer-types/src/initializers.rs @@ -1,6 +1,6 @@ use crate::indexes::{FunctionIndex, GlobalIndex, MemoryIndex, TableIndex}; use crate::lib::std::boxed::Box; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; From deb097c5850cd15a2fce910c84b9a2a1f29efd3f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 13:07:52 +0100 Subject: [PATCH 15/26] fix: Update `loupe` to 0.1.1. --- Cargo.lock | 8 ++++---- examples/tunables_limit_memory.rs | 10 ++-------- lib/engine-object-file/src/artifact.rs | 2 +- tests/lib/engine-dummy/src/artifact.rs | 4 ++-- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f48c1e1e..3baa7f367 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1156,9 +1156,9 @@ 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", @@ -1167,9 +1167,9 @@ dependencies = [ [[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 143682491..8d2f92d3b 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/engine-object-file/src/artifact.rs b/lib/engine-object-file/src/artifact.rs index d5314f012..276f53cc0 100644 --- a/lib/engine-object-file/src/artifact.rs +++ b/lib/engine-object-file/src/artifact.rs @@ -36,7 +36,7 @@ pub struct ObjectFileArtifact { metadata: ModuleMetadata, module_bytes: Vec, finished_functions: BoxedSlice, - #[memoryusage(ignore)] + #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, diff --git a/tests/lib/engine-dummy/src/artifact.rs b/tests/lib/engine-dummy/src/artifact.rs index 89e3070a7..4467d2205 100644 --- a/tests/lib/engine-dummy/src/artifact.rs +++ b/tests/lib/engine-dummy/src/artifact.rs @@ -2,7 +2,7 @@ //! done as separate steps. use crate::engine::DummyEngine; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; #[cfg(feature = "serialize")] use serde::{Deserialize, Serialize}; use std::sync::Arc; @@ -40,7 +40,7 @@ pub struct DummyArtifactMetadata { pub struct DummyArtifact { metadata: DummyArtifactMetadata, finished_functions: BoxedSlice, - #[memoryusage(ignore)] + #[loupe(skip)] finished_function_call_trampolines: BoxedSlice, finished_dynamic_function_trampolines: BoxedSlice, signatures: BoxedSlice, From 83461c3d77078b637735dfd8ca50e88ba9456927 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 13:09:01 +0100 Subject: [PATCH 16/26] doc(changelog) Add #2200. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4086e134e..8b2fa3b4c 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 From 134be5dafabe92a12fa1dfb66e08a2ae2b186265 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 13:17:15 +0100 Subject: [PATCH 17/26] fix(types) Re-implement `MemoryUsage` for `V128`. `MemoryUsage` is implemented for `[T; N]` only on rustc nightly. Wasmer uses the stable channel of rustc. Thus, we re-implement `MemoryUsage` for `V128` by using `V128.as_slice()`. --- lib/wasmer-types/src/types.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs index 3f5d8f5d8..6bb3ee370 100644 --- a/lib/wasmer-types/src/types.rs +++ b/lib/wasmer-types/src/types.rs @@ -6,7 +6,7 @@ use crate::lib::std::string::{String, ToString}; use crate::lib::std::vec::Vec; use crate::units::Pages; use crate::values::Value; -use loupe::MemoryUsage; +use loupe::{MemoryUsage, MemoryUsageTracker}; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -57,7 +57,7 @@ impl fmt::Display for Type { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, MemoryUsage)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] /// The WebAssembly V128 type pub struct V128(pub(crate) [u8; 16]); @@ -98,6 +98,12 @@ impl From<&[u8]> for V128 { } } +impl MemoryUsage for V128 { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + self.as_slice().size_of_val(tracker) + } +} + // External Types /// A list of all possible types which can be externally referenced from a From dcebdfdac65ad96c96ef9abb97dfc5933e08ecbd Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 13:29:57 +0100 Subject: [PATCH 18/26] fix(fuzz) Update `Cargo.lock`. --- fuzz/Cargo.lock | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 456f4fbf9..d19cdc2c9 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -511,19 +511,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", From fc31688700aa2b5850675734d0a0e6627e189e71 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 14:57:28 +0100 Subject: [PATCH 19/26] feat: Start implementing `loupe::MemoryUsage` on `wasmer::Module`. --- lib/compiler-llvm/src/config.rs | 2 +- lib/compiler/src/target.rs | 2 +- lib/engine-native/src/engine.rs | 2 +- lib/wasmer-types/src/types.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 245a27e92..fdcc5fad3 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -5,7 +5,7 @@ use inkwell::targets::{ }; pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use std::fmt::Debug; use std::sync::Arc; use target_lexicon::Architecture; diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 12b2b06f1..1f569b3d5 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,7 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 84f857fd6..a7797b98a 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,7 +2,7 @@ use crate::NativeArtifact; use libloading::Library; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs index 6bb3ee370..97f54e746 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]); From 768adb936090a29a390fd449f07b082699623642 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 22 Mar 2021 12:10:39 +0100 Subject: [PATCH 20/26] feat: Use latest version of `loupe`. --- lib/compiler-llvm/src/config.rs | 2 +- lib/compiler/src/target.rs | 2 +- lib/engine-native/src/engine.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index fdcc5fad3..245a27e92 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -5,7 +5,7 @@ use inkwell::targets::{ }; pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt::Debug; use std::sync::Arc; use target_lexicon::Architecture; diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 1f569b3d5..12b2b06f1 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,7 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index a7797b98a..84f857fd6 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,7 +2,7 @@ use crate::NativeArtifact; use libloading::Library; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; From 906079fd9db50e619d2ce21ad58f16c68620014e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 22 Mar 2021 15:46:40 +0100 Subject: [PATCH 21/26] feat: Implement `MemoryUsage` for `Instance`. --- Cargo.toml | 1 + examples/hello_world.rs | 10 ++++++++++ lib/api/src/exports.rs | 3 ++- lib/api/src/externals/function.rs | 10 ++++++---- lib/api/src/externals/global.rs | 3 ++- lib/api/src/externals/memory.rs | 3 ++- lib/api/src/externals/mod.rs | 3 ++- lib/api/src/externals/table.rs | 3 ++- lib/api/src/instance.rs | 3 ++- lib/compiler/src/target.rs | 2 +- lib/engine-native/src/engine.rs | 2 +- lib/engine/src/export.rs | 14 ++++++++++---- lib/vm/src/export.rs | 4 +++- lib/vm/src/instance/mod.rs | 7 ++++++- lib/vm/src/instance/ref.rs | 12 ++++++++++++ lib/vm/src/vmcontext.rs | 2 +- lib/vm/src/vmoffsets.rs | 3 ++- 17 files changed, 65 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 94c27a92e..1ea883800 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ wasmer-cache = { version = "1.0.2", path = "lib/cache", optional = true } wasmer-types = { version = "1.0.2", path = "lib/wasmer-types" } wasmer-middlewares = { version = "1.0.2", path = "lib/middlewares", optional = true } cfg-if = "1.0" +loupe = { path = "../loupe/crates/loupe" } [workspace] members = [ diff --git a/examples/hello_world.rs b/examples/hello_world.rs index dbe559226..87cb3a0ef 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -6,6 +6,7 @@ //! cargo run --example hello-world --release --features "cranelift" //! ``` +use loupe::size_of_val; use wasmer::{imports, wat2wasm, Function, Instance, Module, NativeFunc, Store}; use wasmer_compiler_cranelift::Cranelift; use wasmer_engine_jit::JIT; @@ -45,10 +46,15 @@ fn main() -> anyhow::Result<()> { // (`Cranelift`) and pass it to an engine (`JIT`). We then pass the engine to // the store and are now ready to compile and run WebAssembly! let store = Store::new(&JIT::new(Cranelift::default()).engine()); + dbg!(size_of_val(&store)); + // We then use our store and Wasm bytes to compile a `Module`. // A `Module` is a compiled WebAssembly module that isn't ready to execute yet. let module = Module::new(&store, wasm_bytes)?; + dbg!(size_of_val(&store)); + dbg!(size_of_val(&module)); + // Next we'll set up our `Module` so that we can execute it. // We define a function to act as our "env" "say_hello" function imported in the @@ -71,6 +77,10 @@ fn main() -> anyhow::Result<()> { // An `Instance` is a compiled WebAssembly module that has been set up // and is ready to execute. let instance = Instance::new(&module, &import_object)?; + + dbg!(size_of_val(&instance)); + dbg!(&instance.exports); + // We get the `NativeFunc` with no parameters and no results from the instance. // // Recall that the Wasm module exported a function named "run", this is getting diff --git a/lib/api/src/exports.rs b/lib/api/src/exports.rs index 606a052e5..13082248f 100644 --- a/lib/api/src/exports.rs +++ b/lib/api/src/exports.rs @@ -3,6 +3,7 @@ use crate::import_object::LikeNamespace; use crate::native::NativeFunc; use crate::WasmTypeList; use indexmap::IndexMap; +use loupe_derive::MemoryUsage; use std::fmt; use std::iter::{ExactSizeIterator, FromIterator}; use std::sync::Arc; @@ -61,7 +62,7 @@ pub enum ExportError { /// the types of instances. /// /// TODO: add examples of using exports -#[derive(Clone, Default)] +#[derive(Clone, Default, MemoryUsage)] pub struct Exports { map: Arc>, } diff --git a/lib/api/src/externals/function.rs b/lib/api/src/externals/function.rs index f925852af..889b8f375 100644 --- a/lib/api/src/externals/function.rs +++ b/lib/api/src/externals/function.rs @@ -10,6 +10,7 @@ pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, Witho #[cfg(feature = "deprecated")] pub use inner::{UnsafeMutableEnv, WithUnsafeMutableEnv}; +use loupe_derive::MemoryUsage; use std::cmp::max; use std::ffi::c_void; use std::fmt; @@ -22,21 +23,22 @@ use wasmer_vm::{ }; /// A function defined in the Wasm module -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, MemoryUsage)] pub struct WasmFunctionDefinition { // Address of the trampoline to do the call. + #[memoryusage(ignore)] pub(crate) trampoline: VMTrampoline, } /// A function defined in the Host -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, MemoryUsage)] pub struct HostFunctionDefinition { /// If the host function has a custom environment attached pub(crate) has_env: bool, } /// The inner helper -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, MemoryUsage)] pub enum FunctionDefinition { /// A function defined in the Wasm side Wasm(WasmFunctionDefinition), @@ -61,7 +63,7 @@ pub enum FunctionDefinition { /// with native functions. Attempting to create a native `Function` with one will /// result in a panic. /// [Closures as host functions tracking issue](https://github.com/wasmerio/wasmer/issues/1840) -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, MemoryUsage)] pub struct Function { pub(crate) store: Store, pub(crate) definition: FunctionDefinition, diff --git a/lib/api/src/externals/global.rs b/lib/api/src/externals/global.rs index 49f2a4c12..2f7ce83f7 100644 --- a/lib/api/src/externals/global.rs +++ b/lib/api/src/externals/global.rs @@ -5,6 +5,7 @@ use crate::types::Val; use crate::GlobalType; use crate::Mutability; use crate::RuntimeError; +use loupe_derive::MemoryUsage; use std::fmt; use std::sync::Arc; use wasmer_engine::{Export, ExportGlobal}; @@ -16,7 +17,7 @@ use wasmer_vm::{Global as RuntimeGlobal, VMExportGlobal}; /// It consists of an individual value and a flag indicating whether it is mutable. /// /// Spec: -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct Global { store: Store, global: Arc, diff --git a/lib/api/src/externals/memory.rs b/lib/api/src/externals/memory.rs index 423345a27..e140c1e5f 100644 --- a/lib/api/src/externals/memory.rs +++ b/lib/api/src/externals/memory.rs @@ -2,6 +2,7 @@ use crate::exports::{ExportError, Exportable}; use crate::externals::Extern; use crate::store::Store; use crate::{MemoryType, MemoryView}; +use loupe_derive::MemoryUsage; use std::convert::TryInto; use std::slice; use std::sync::Arc; @@ -23,7 +24,7 @@ use wasmer_vm::{Memory as RuntimeMemory, MemoryError, VMExportMemory}; /// mutable from both host and WebAssembly. /// /// Spec: -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct Memory { store: Store, memory: Arc, diff --git a/lib/api/src/externals/mod.rs b/lib/api/src/externals/mod.rs index c8f15e3c1..8927f830b 100644 --- a/lib/api/src/externals/mod.rs +++ b/lib/api/src/externals/mod.rs @@ -16,6 +16,7 @@ pub use self::table::Table; use crate::exports::{ExportError, Exportable}; use crate::store::{Store, StoreObject}; use crate::ExternType; +use loupe_derive::MemoryUsage; use std::fmt; use wasmer_engine::Export; @@ -23,7 +24,7 @@ use wasmer_engine::Export; /// can be imported or exported. /// /// Spec: -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub enum Extern { /// A external [`Function`]. Function(Function), diff --git a/lib/api/src/externals/table.rs b/lib/api/src/externals/table.rs index 8e2f43696..3c625ae27 100644 --- a/lib/api/src/externals/table.rs +++ b/lib/api/src/externals/table.rs @@ -4,6 +4,7 @@ use crate::store::Store; use crate::types::{Val, ValFuncRef}; use crate::RuntimeError; use crate::TableType; +use loupe_derive::MemoryUsage; use std::sync::Arc; use wasmer_engine::{Export, ExportTable}; use wasmer_vm::{Table as RuntimeTable, VMCallerCheckedAnyfunc, VMExportTable}; @@ -17,7 +18,7 @@ use wasmer_vm::{Table as RuntimeTable, VMCallerCheckedAnyfunc, VMExportTable}; /// mutable from both host and WebAssembly. /// /// Spec: -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct Table { store: Store, table: Arc, diff --git a/lib/api/src/instance.rs b/lib/api/src/instance.rs index 93c0b42fe..327bfb60d 100644 --- a/lib/api/src/instance.rs +++ b/lib/api/src/instance.rs @@ -3,6 +3,7 @@ use crate::externals::Extern; use crate::module::Module; use crate::store::Store; use crate::{HostEnvInitError, LinkError, RuntimeError}; +use loupe_derive::MemoryUsage; use std::fmt; use std::sync::{Arc, Mutex}; use thiserror::Error; @@ -17,7 +18,7 @@ use wasmer_vm::{InstanceHandle, VMContext}; /// interacting with WebAssembly. /// /// Spec: -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct Instance { handle: Arc>, module: Module, diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 12b2b06f1..1f569b3d5 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,7 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 84f857fd6..a7797b98a 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,7 +2,7 @@ use crate::NativeArtifact; use libloading::Library; -use loupe::MemoryUsage; +use loupe_derive::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; diff --git a/lib/engine/src/export.rs b/lib/engine/src/export.rs index e3342265a..754cc689d 100644 --- a/lib/engine/src/export.rs +++ b/lib/engine/src/export.rs @@ -1,10 +1,10 @@ +use loupe_derive::MemoryUsage; +use std::sync::Arc; use wasmer_vm::{ ImportInitializerFuncPtr, VMExport, VMExportFunction, VMExportGlobal, VMExportMemory, VMExportTable, }; -use std::sync::Arc; - /// The value of an export passed from one instance to another. #[derive(Debug, Clone)] pub enum Export { @@ -54,7 +54,7 @@ impl From for Export { /// /// This struct owns the original `host_env`, thus when it gets dropped /// it calls the `drop` function on it. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, MemoryUsage)] pub struct ExportFunctionMetadata { /// This field is stored here to be accessible by `Drop`. /// @@ -69,20 +69,26 @@ pub struct ExportFunctionMetadata { /// See `wasmer_vm::export::VMExportFunction::vmctx` for the version of /// this pointer that is used by the VM when creating an `Instance`. pub(crate) host_env: *mut std::ffi::c_void, + /// Function pointer to `WasmerEnv::init_with_instance(&mut self, instance: &Instance)`. /// /// This function is called to finish setting up the environment after /// we create the `api::Instance`. // This one is optional for now because dynamic host envs need the rest // of this without the init fn + #[memoryusage(ignore)] pub(crate) import_init_function_ptr: Option, + /// A function analogous to `Clone::clone` that returns a leaked `Box`. + #[memoryusage(ignore)] pub(crate) host_env_clone_fn: fn(*mut std::ffi::c_void) -> *mut std::ffi::c_void, + /// The destructor to free the host environment. /// /// # Safety /// - This function should only be called in when properly synchronized. /// For example, in the `Drop` implementation of this type. + #[memoryusage(ignore)] pub(crate) host_env_drop_fn: unsafe fn(*mut std::ffi::c_void), } @@ -132,7 +138,7 @@ impl Drop for ExportFunctionMetadata { /// A function export value with an extra function pointer to initialize /// host environments. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, MemoryUsage)] pub struct ExportFunction { /// The VM function, containing most of the data. pub vm_function: VMExportFunction, diff --git a/lib/vm/src/export.rs b/lib/vm/src/export.rs index e5d3475ea..500ae9675 100644 --- a/lib/vm/src/export.rs +++ b/lib/vm/src/export.rs @@ -6,6 +6,7 @@ use crate::instance::InstanceRef; use crate::memory::{Memory, MemoryStyle}; use crate::table::{Table, TableStyle}; use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline}; +use loupe_derive::MemoryUsage; use std::sync::Arc; use wasmer_types::{FunctionType, MemoryType, TableType}; @@ -26,7 +27,7 @@ pub enum VMExport { } /// A function export value. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, MemoryUsage)] pub struct VMExportFunction { /// The address of the native-code function. pub address: *const VMFunctionBody, @@ -46,6 +47,7 @@ pub struct VMExportFunction { /// /// May be `None` when the function is a host function (`FunctionType` /// == `Dynamic` or `vmctx` == `nullptr`). + #[memoryusage(ignore)] pub call_trampoline: Option, /// A “reference” to the instance through the diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index 986ee9d51..dd31d3617 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -28,6 +28,7 @@ use crate::vmcontext::{ use crate::{FunctionBodyPtr, ModuleInfo, VMOffsets}; use crate::{VMExportFunction, VMExportGlobal, VMExportMemory, VMExportTable}; use loupe::{MemoryUsage, MemoryUsageTracker}; +use loupe_derive::MemoryUsage; use memoffset::offset_of; use more_asserts::assert_lt; use std::any::Any; @@ -57,6 +58,7 @@ pub type ImportInitializerFuncPtr = /// contain various data. That's why the type has a C representation /// to ensure that the `vmctx` field is last. See the documentation of /// the `vmctx` field to learn more. +#[derive(MemoryUsage)] #[repr(C)] pub(crate) struct Instance { /// The `ModuleInfo` this `Instance` was instantiated from. @@ -78,6 +80,7 @@ pub(crate) struct Instance { functions: BoxedSlice, /// Pointers to function call trampolines in executable memory. + #[memoryusage(ignore)] function_call_trampolines: BoxedSlice, /// Passive elements in this instantiation. As `elem.drop`s happen, these @@ -92,6 +95,7 @@ pub(crate) struct Instance { host_state: Box, /// Handler run when `SIGBUS`, `SIGFPE`, `SIGILL`, or `SIGSEGV` are caught by the instance thread. + #[memoryusage(ignore)] pub(crate) signal_handler: Cell>>, /// Functions to operate on host environments in the imports @@ -105,6 +109,7 @@ pub(crate) struct Instance { /// field is last, and represents a dynamically-sized array that /// extends beyond the nominal end of the struct (similar to a /// flexible array member). + #[memoryusage(ignore)] vmctx: VMContext, } @@ -785,7 +790,7 @@ impl Instance { /// /// This is more or less a public facade of the private `Instance`, /// providing useful higher-level API. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, MemoryUsage)] pub struct InstanceHandle { /// The [`InstanceRef`]. See its documentation to learn more. instance: InstanceRef, diff --git a/lib/vm/src/instance/ref.rs b/lib/vm/src/instance/ref.rs index c9081bba6..77daeddc6 100644 --- a/lib/vm/src/instance/ref.rs +++ b/lib/vm/src/instance/ref.rs @@ -1,5 +1,7 @@ use super::Instance; +use loupe::{MemoryUsage, MemoryUsageTracker}; use std::alloc::Layout; +use std::mem; use std::ptr::{self, NonNull}; use std::sync::{atomic, Arc}; @@ -208,3 +210,13 @@ impl Drop for InstanceRef { unsafe { Self::deallocate_instance(self) }; } } + +impl MemoryUsage for InstanceRef { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + self.strong.size_of_val(tracker) - mem::size_of_val(&self.strong) + + self.instance_layout.size_of_val(tracker) + - mem::size_of_val(&self.instance_layout) + + self.as_ref().size_of_val(tracker) + - mem::size_of_val(&self.instance) + } +} diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index 9479f8121..65657e23f 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -175,7 +175,7 @@ mod test_vmfunction_body { } /// A function kind is a calling convention into and out of wasm code. -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, MemoryUsage)] #[repr(C)] pub enum VMFunctionKind { /// A static function has the native signature: diff --git a/lib/vm/src/vmoffsets.rs b/lib/vm/src/vmoffsets.rs index a78611470..4b86212c5 100644 --- a/lib/vm/src/vmoffsets.rs +++ b/lib/vm/src/vmoffsets.rs @@ -8,6 +8,7 @@ use crate::module::ModuleInfo; use crate::VMBuiltinFunctionIndex; +use loupe_derive::MemoryUsage; use more_asserts::assert_lt; use std::convert::TryFrom; use wasmer_types::{ @@ -33,7 +34,7 @@ const fn align(offset: u32, width: u32) -> u32 { /// related structs that JIT code accesses directly. /// /// [`VMContext`]: crate::vmcontext::VMContext -#[derive(Clone, Debug)] +#[derive(Clone, Debug, MemoryUsage)] pub struct VMOffsets { /// The size in bytes of a pointer on the target. pub pointer_size: u8, From d801eb4bfed3b59d2810091bfff6d406e6d6c167 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 22 Mar 2021 16:06:58 +0100 Subject: [PATCH 22/26] feat: Use latest version of `loupe`. --- Cargo.toml | 1 - lib/api/src/exports.rs | 2 +- lib/api/src/externals/function.rs | 4 ++-- lib/api/src/externals/global.rs | 2 +- lib/api/src/externals/memory.rs | 2 +- lib/api/src/externals/mod.rs | 2 +- lib/api/src/externals/table.rs | 2 +- lib/api/src/instance.rs | 2 +- lib/compiler/src/target.rs | 2 +- lib/engine-native/src/engine.rs | 2 +- lib/engine/src/export.rs | 8 ++++---- lib/vm/src/export.rs | 4 ++-- lib/vm/src/instance/mod.rs | 7 +++---- lib/vm/src/vmoffsets.rs | 2 +- 14 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ea883800..94c27a92e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ wasmer-cache = { version = "1.0.2", path = "lib/cache", optional = true } wasmer-types = { version = "1.0.2", path = "lib/wasmer-types" } wasmer-middlewares = { version = "1.0.2", path = "lib/middlewares", optional = true } cfg-if = "1.0" -loupe = { path = "../loupe/crates/loupe" } [workspace] members = [ diff --git a/lib/api/src/exports.rs b/lib/api/src/exports.rs index 13082248f..4bfea97ed 100644 --- a/lib/api/src/exports.rs +++ b/lib/api/src/exports.rs @@ -3,7 +3,7 @@ use crate::import_object::LikeNamespace; use crate::native::NativeFunc; use crate::WasmTypeList; use indexmap::IndexMap; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt; use std::iter::{ExactSizeIterator, FromIterator}; use std::sync::Arc; diff --git a/lib/api/src/externals/function.rs b/lib/api/src/externals/function.rs index 889b8f375..a396c1ca2 100644 --- a/lib/api/src/externals/function.rs +++ b/lib/api/src/externals/function.rs @@ -10,7 +10,7 @@ pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, Witho #[cfg(feature = "deprecated")] pub use inner::{UnsafeMutableEnv, WithUnsafeMutableEnv}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::cmp::max; use std::ffi::c_void; use std::fmt; @@ -26,7 +26,7 @@ use wasmer_vm::{ #[derive(Clone, PartialEq, MemoryUsage)] pub struct WasmFunctionDefinition { // Address of the trampoline to do the call. - #[memoryusage(ignore)] + #[loupe(skip)] pub(crate) trampoline: VMTrampoline, } diff --git a/lib/api/src/externals/global.rs b/lib/api/src/externals/global.rs index 2f7ce83f7..4f85aba5d 100644 --- a/lib/api/src/externals/global.rs +++ b/lib/api/src/externals/global.rs @@ -5,7 +5,7 @@ use crate::types::Val; use crate::GlobalType; use crate::Mutability; use crate::RuntimeError; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt; use std::sync::Arc; use wasmer_engine::{Export, ExportGlobal}; diff --git a/lib/api/src/externals/memory.rs b/lib/api/src/externals/memory.rs index e140c1e5f..8cfe9f876 100644 --- a/lib/api/src/externals/memory.rs +++ b/lib/api/src/externals/memory.rs @@ -2,7 +2,7 @@ use crate::exports::{ExportError, Exportable}; use crate::externals::Extern; use crate::store::Store; use crate::{MemoryType, MemoryView}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::convert::TryInto; use std::slice; use std::sync::Arc; diff --git a/lib/api/src/externals/mod.rs b/lib/api/src/externals/mod.rs index 8927f830b..ead70f2ec 100644 --- a/lib/api/src/externals/mod.rs +++ b/lib/api/src/externals/mod.rs @@ -16,7 +16,7 @@ pub use self::table::Table; use crate::exports::{ExportError, Exportable}; use crate::store::{Store, StoreObject}; use crate::ExternType; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt; use wasmer_engine::Export; diff --git a/lib/api/src/externals/table.rs b/lib/api/src/externals/table.rs index 3c625ae27..6423c6cd9 100644 --- a/lib/api/src/externals/table.rs +++ b/lib/api/src/externals/table.rs @@ -4,7 +4,7 @@ use crate::store::Store; use crate::types::{Val, ValFuncRef}; use crate::RuntimeError; use crate::TableType; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_engine::{Export, ExportTable}; use wasmer_vm::{Table as RuntimeTable, VMCallerCheckedAnyfunc, VMExportTable}; diff --git a/lib/api/src/instance.rs b/lib/api/src/instance.rs index 327bfb60d..592fd2eec 100644 --- a/lib/api/src/instance.rs +++ b/lib/api/src/instance.rs @@ -3,7 +3,7 @@ use crate::externals::Extern; use crate::module::Module; use crate::store::Store; use crate::{HostEnvInitError, LinkError, RuntimeError}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::fmt; use std::sync::{Arc, Mutex}; use thiserror::Error; diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 1f569b3d5..12b2b06f1 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,7 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index a7797b98a..84f857fd6 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,7 +2,7 @@ use crate::NativeArtifact; use libloading::Library; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; diff --git a/lib/engine/src/export.rs b/lib/engine/src/export.rs index 754cc689d..d0014eb8c 100644 --- a/lib/engine/src/export.rs +++ b/lib/engine/src/export.rs @@ -1,4 +1,4 @@ -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_vm::{ ImportInitializerFuncPtr, VMExport, VMExportFunction, VMExportGlobal, VMExportMemory, @@ -76,11 +76,11 @@ pub struct ExportFunctionMetadata { /// we create the `api::Instance`. // This one is optional for now because dynamic host envs need the rest // of this without the init fn - #[memoryusage(ignore)] + #[loupe(skip)] pub(crate) import_init_function_ptr: Option, /// A function analogous to `Clone::clone` that returns a leaked `Box`. - #[memoryusage(ignore)] + #[loupe(skip)] pub(crate) host_env_clone_fn: fn(*mut std::ffi::c_void) -> *mut std::ffi::c_void, /// The destructor to free the host environment. @@ -88,7 +88,7 @@ pub struct ExportFunctionMetadata { /// # Safety /// - This function should only be called in when properly synchronized. /// For example, in the `Drop` implementation of this type. - #[memoryusage(ignore)] + #[loupe(skip)] pub(crate) host_env_drop_fn: unsafe fn(*mut std::ffi::c_void), } diff --git a/lib/vm/src/export.rs b/lib/vm/src/export.rs index 500ae9675..806178ab4 100644 --- a/lib/vm/src/export.rs +++ b/lib/vm/src/export.rs @@ -6,7 +6,7 @@ use crate::instance::InstanceRef; use crate::memory::{Memory, MemoryStyle}; use crate::table::{Table, TableStyle}; use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline}; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_types::{FunctionType, MemoryType, TableType}; @@ -47,7 +47,7 @@ pub struct VMExportFunction { /// /// May be `None` when the function is a host function (`FunctionType` /// == `Dynamic` or `vmctx` == `nullptr`). - #[memoryusage(ignore)] + #[loupe(skip)] pub call_trampoline: Option, /// A “reference” to the instance through the diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index dd31d3617..c0b4ae7a0 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -28,7 +28,6 @@ use crate::vmcontext::{ use crate::{FunctionBodyPtr, ModuleInfo, VMOffsets}; use crate::{VMExportFunction, VMExportGlobal, VMExportMemory, VMExportTable}; use loupe::{MemoryUsage, MemoryUsageTracker}; -use loupe_derive::MemoryUsage; use memoffset::offset_of; use more_asserts::assert_lt; use std::any::Any; @@ -80,7 +79,7 @@ pub(crate) struct Instance { functions: BoxedSlice, /// Pointers to function call trampolines in executable memory. - #[memoryusage(ignore)] + #[loupe(skip)] function_call_trampolines: BoxedSlice, /// Passive elements in this instantiation. As `elem.drop`s happen, these @@ -95,7 +94,7 @@ pub(crate) struct Instance { host_state: Box, /// Handler run when `SIGBUS`, `SIGFPE`, `SIGILL`, or `SIGSEGV` are caught by the instance thread. - #[memoryusage(ignore)] + #[loupe(skip)] pub(crate) signal_handler: Cell>>, /// Functions to operate on host environments in the imports @@ -109,7 +108,7 @@ pub(crate) struct Instance { /// field is last, and represents a dynamically-sized array that /// extends beyond the nominal end of the struct (similar to a /// flexible array member). - #[memoryusage(ignore)] + #[loupe(skip)] vmctx: VMContext, } diff --git a/lib/vm/src/vmoffsets.rs b/lib/vm/src/vmoffsets.rs index 4b86212c5..6a6fa5b26 100644 --- a/lib/vm/src/vmoffsets.rs +++ b/lib/vm/src/vmoffsets.rs @@ -8,7 +8,7 @@ use crate::module::ModuleInfo; use crate::VMBuiltinFunctionIndex; -use loupe_derive::MemoryUsage; +use loupe::MemoryUsage; use more_asserts::assert_lt; use std::convert::TryFrom; use wasmer_types::{ From 4e00a5eccfd03c832ba79cff6c2a57a8c8ba7d88 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 13:17:15 +0100 Subject: [PATCH 23/26] fix(types) Re-implement `MemoryUsage` for `V128`. `MemoryUsage` is implemented for `[T; N]` only on rustc nightly. Wasmer uses the stable channel of rustc. Thus, we re-implement `MemoryUsage` for `V128` by using `V128.as_slice()`. --- lib/wasmer-types/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs index 97f54e746..6bb3ee370 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, MemoryUsage)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] /// The WebAssembly V128 type pub struct V128(pub(crate) [u8; 16]); From 4eb7f7876e0a59b78e2fae48fa0788ceb6ca25f4 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 15:02:24 +0100 Subject: [PATCH 24/26] chore: Remove debug instructions. --- Cargo.toml | 1 - examples/hello_world.rs | 8 -------- 2 files changed, 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 94c27a92e..40fda1950 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,6 @@ criterion = "0.3" lazy_static = "1.4" wasmer-engine-dummy = { path = "tests/lib/engine-dummy" } tempfile = "3.1" -loupe = "0.1" [features] # Don't add the compiler features in default, please add them on the Makefile diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 87cb3a0ef..55142db1c 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -6,7 +6,6 @@ //! cargo run --example hello-world --release --features "cranelift" //! ``` -use loupe::size_of_val; use wasmer::{imports, wat2wasm, Function, Instance, Module, NativeFunc, Store}; use wasmer_compiler_cranelift::Cranelift; use wasmer_engine_jit::JIT; @@ -46,15 +45,11 @@ fn main() -> anyhow::Result<()> { // (`Cranelift`) and pass it to an engine (`JIT`). We then pass the engine to // the store and are now ready to compile and run WebAssembly! let store = Store::new(&JIT::new(Cranelift::default()).engine()); - dbg!(size_of_val(&store)); // We then use our store and Wasm bytes to compile a `Module`. // A `Module` is a compiled WebAssembly module that isn't ready to execute yet. let module = Module::new(&store, wasm_bytes)?; - dbg!(size_of_val(&store)); - dbg!(size_of_val(&module)); - // Next we'll set up our `Module` so that we can execute it. // We define a function to act as our "env" "say_hello" function imported in the @@ -78,9 +73,6 @@ fn main() -> anyhow::Result<()> { // and is ready to execute. let instance = Instance::new(&module, &import_object)?; - dbg!(size_of_val(&instance)); - dbg!(&instance.exports); - // We get the `NativeFunc` with no parameters and no results from the instance. // // Recall that the Wasm module exported a function named "run", this is getting From 05c7f62500cdfa5f548b0dae8048134f9ed6dd35 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 15:02:37 +0100 Subject: [PATCH 25/26] doc(changelog) Add #2201. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b2fa3b4c..7b9226707 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 +- [#2201](https://github.com/wasmerio/wasmer/pull/2201) Implement `loupe::MemoryUsage` for `wasmer::Instance`. - [#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. From f19b044990d18b4d42ab4399fc018ed29f1f55ad Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 23 Mar 2021 15:34:20 +0100 Subject: [PATCH 26/26] test: Add `loupe` as a dev-dep. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 40fda1950..94c27a92e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,7 @@ criterion = "0.3" lazy_static = "1.4" wasmer-engine-dummy = { path = "tests/lib/engine-dummy" } tempfile = "3.1" +loupe = "0.1" [features] # Don't add the compiler features in default, please add them on the Makefile