Skip to content

Commit

Permalink
Try #2199:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Mar 23, 2021
2 parents e46c397 + 1a2dbda commit 6dc9477
Show file tree
Hide file tree
Showing 46 changed files with 215 additions and 76 deletions.
90 changes: 56 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions examples/tunables_limit_memory.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -131,6 +133,12 @@ impl<T: Tunables> Tunables for LimitingTunables<T> {
}
}

impl<T: Tunables> MemoryUsage for LimitingTunables<T> {
fn size_of_val(&self, _tracker: &mut dyn MemoryUsageTracker) -> usize {
mem::size_of_val(self)
}
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// A Wasm module with one exported memory (min: 7 pages, max: unset)
let wat = br#"(module (memory 7) (export "memory" (memory 0)))"#;
Expand Down
1 change: 1 addition & 0 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +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" }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = "0.3"
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::tunables::BaseTunables;
use loupe::MemoryUsage;
use std::fmt;
use std::sync::Arc;
#[cfg(all(feature = "compiler", feature = "engine"))]
Expand All @@ -15,7 +16,7 @@ use wasmer_engine::{Engine, Tunables};
/// [`Tunables`] (that are used to create the memories, tables and globals).
///
/// Spec: <https://webassembly.github.io/spec/core/exec/runtime.html#store>
#[derive(Clone)]
#[derive(Clone, MemoryUsage)]
pub struct Store {
engine: Arc<dyn Engine + Send + Sync>,
tunables: Arc<dyn Tunables + Send + Sync>,
Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/tunables.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{MemoryType, Pages, TableType};
use loupe::MemoryUsage;
use std::cmp::min;
use std::ptr::NonNull;
use std::sync::Arc;
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/compiler-cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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" }

[dev-dependencies]
target-lexicon = { version = "0.11", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions lib/compiler-cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::MemoryUsage;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use std::sync::Arc;
use wasmer_compiler::CompileError;
Expand All @@ -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,
}
Expand Down
Loading

0 comments on commit 6dc9477

Please sign in to comment.