Skip to content

Commit

Permalink
!module second
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Mar 22, 2021
1 parent 96719f1 commit fd15636
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions lib/compiler/src/address_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions lib/compiler/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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).
///
Expand All @@ -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"))]
Expand Down Expand Up @@ -79,7 +80,7 @@ pub type CustomSections = PrimaryMap<SectionIndex, CustomSection>;
/// 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
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/src/jump_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/src/module.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/compiler/src/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions lib/compiler/src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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<u8>);

impl SectionBody {
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/src/sourceloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! and tracing errors.
use crate::lib::std::fmt;

use loupe_derive::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/src/trap.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/src/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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<u8>),
Expand Down
3 changes: 3 additions & 0 deletions lib/engine-jit/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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<LocalFunctionIndex, FunctionBodyPtr>,
#[memoryusage(ignore)]
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
Expand Down
5 changes: 3 additions & 2 deletions lib/engine-jit/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use loupe_derive::MemoryUsage;
use serde::{Deserialize, Serialize};
use wasmer_compiler::{
CompileModuleInfo, CustomSection, Dwarf, FunctionBody, JumpTableOffsets, Relocation,
Expand All @@ -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<LocalFunctionIndex, FunctionBody>,
pub function_relocations: PrimaryMap<LocalFunctionIndex, Vec<Relocation>>,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/engine-native/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ use wasmer_vm::{
#[derive(MemoryUsage)]
pub struct NativeArtifact {
sharedobject_path: PathBuf,
#[memoryusage(ignore)]
metadata: ModuleMetadata,
finished_functions: BoxedSlice<LocalFunctionIndex, FunctionBodyPtr>,
#[memoryusage(ignore)]
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
Expand Down
3 changes: 2 additions & 1 deletion lib/engine-native/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 3 additions & 0 deletions lib/engine-object-file/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<u8>,
finished_functions: BoxedSlice<LocalFunctionIndex, FunctionBodyPtr>,
#[memoryusage(ignore)]
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
Expand Down
4 changes: 3 additions & 1 deletion lib/engine-object-file/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,6 +14,7 @@ pub struct ModuleMetadata {
pub function_body_lengths: PrimaryMap<LocalFunctionIndex, u64>,
}

#[derive(MemoryUsage)]
pub struct ModuleMetadataSymbolRegistry {
pub prefix: String,
}
Expand Down
5 changes: 3 additions & 2 deletions lib/engine/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use loupe_derive::MemoryUsage;
use serde::de::{Deserializer, Visitor};
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
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 {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions lib/engine/src/trap/frame_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { git = "https://github.com/wasmerio/loupe", branch = "master", features = ["enable-indexmap"] }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] }
Expand Down
1 change: 0 additions & 1 deletion lib/vm/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit fd15636

Please sign in to comment.