mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
feat: Start implementing loupe::MemoryUsage on wasmer::Module.
This commit is contained in:
@@ -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<WasmMmap>,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user