diff --git a/CHANGELOG.md b/CHANGELOG.md
index 258168311..7b9226707 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,9 @@
- [#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.
- [#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
diff --git a/Cargo.lock b/Cargo.lock
index 047863405..3baa7f367 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,27 @@ dependencies = [
"cfg-if 1.0.0",
]
+[[package]]
+name = "loupe"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1acf065b51eb58abbc66a07c27ec63142205d339a9f5093dc3e1d7cda3d5c9a3"
+dependencies = [
+ "indexmap",
+ "loupe-derive",
+ "rustversion",
+]
+
+[[package]]
+name = "loupe-derive"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e40881c741681f26b0f4c0261f493c8df600998807184b524e34b7e208324834"
+dependencies = [
+ "quote",
+ "syn",
+]
+
[[package]]
name = "mach"
version = "0.3.2"
@@ -1372,9 +1393,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 +1414,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 +1648,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 +1668,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 +1845,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 +1873,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 +1942,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 +2061,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 +2105,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 +2131,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 +2306,7 @@ dependencies = [
"cfg-if 0.1.10",
"indexmap",
"libc",
+ "loupe",
"more-asserts",
"target-lexicon",
"tempfile",
@@ -2390,6 +2402,7 @@ version = "1.0.2"
dependencies = [
"enumset",
"hashbrown",
+ "loupe",
"serde",
"serde_bytes",
"smallvec",
@@ -2410,6 +2423,7 @@ dependencies = [
"gimli",
"hashbrown",
"lazy_static",
+ "loupe",
"more-asserts",
"rayon",
"serde",
@@ -2432,6 +2446,7 @@ dependencies = [
"itertools 0.10.0",
"lazy_static",
"libc",
+ "loupe",
"rayon",
"regex",
"rustc_version 0.2.3",
@@ -2452,6 +2467,7 @@ dependencies = [
"dynasmrt",
"hashbrown",
"lazy_static",
+ "loupe",
"more-asserts",
"rayon",
"serde",
@@ -2494,6 +2510,7 @@ dependencies = [
"backtrace",
"bincode",
"lazy_static",
+ "loupe",
"memmap2",
"more-asserts",
"rustc-demangle",
@@ -2511,6 +2528,7 @@ name = "wasmer-engine-dummy"
version = "1.0.2"
dependencies = [
"bincode",
+ "loupe",
"serde",
"serde_bytes",
"wasmer-compiler",
@@ -2525,6 +2543,7 @@ version = "1.0.2"
dependencies = [
"bincode",
"cfg-if 0.1.10",
+ "loupe",
"region",
"serde",
"serde_bytes",
@@ -2543,6 +2562,7 @@ dependencies = [
"cfg-if 0.1.10",
"leb128",
"libloading",
+ "loupe",
"serde",
"tempfile",
"tracing",
@@ -2562,6 +2582,7 @@ dependencies = [
"cfg-if 0.1.10",
"leb128",
"libloading",
+ "loupe",
"serde",
"tempfile",
"tracing",
@@ -2584,6 +2605,7 @@ dependencies = [
name = "wasmer-middlewares"
version = "1.0.2"
dependencies = [
+ "loupe",
"wasmer",
"wasmer-types",
"wasmer-vm",
@@ -2603,6 +2625,7 @@ dependencies = [
name = "wasmer-types"
version = "1.0.2"
dependencies = [
+ "loupe",
"serde",
"thiserror",
]
@@ -2616,6 +2639,7 @@ dependencies = [
"cfg-if 0.1.10",
"indexmap",
"libc",
+ "loupe",
"memoffset",
"more-asserts",
"region",
@@ -2680,6 +2704,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..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
diff --git a/README.md b/README.md
index d1326658b..dd952cc15 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.
@@ -103,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
new file mode 100644
index 000000000..8ccbe74e1
--- /dev/null
+++ b/docs/cn/README.md
@@ -0,0 +1,192 @@
+
+
+
+
+[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] | *没有已发布的软件包* | |
+
+[👋 缺少语言?](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
+[`wasmer` rust crate]: https://crates.io/crates/wasmer/
+[rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime
+
+[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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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
+
+[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..8a6924a9f
--- /dev/null
+++ b/docs/es/README.md
@@ -0,0 +1,191 @@
+
+
+
+
+[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).
+
+## 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 >
+```
+
+#### Esto es lo que puedes hacer:
+
+- [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
+
+📦 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* | |
+
+[👋 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
+[`wasmer` en crates.io]: https://crates.io/crates/wasmer/
+[rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime
+
+[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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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
+
+[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..e6f87a90e
--- /dev/null
+++ b/docs/fr/README.md
@@ -0,0 +1,191 @@
+
+
+
+
+[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 contrôlé (bac à sable, _sandbox_).
+
+* **Modulaire**. Wasmer prend en charge différents frameworks de compilation pour répondre au mieux à vos besoins (LLVM, Cranelift ...).
+
+* **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 :
+
+```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 paquet Wasm sur WAPM](https://docs.wasmer.io/ecosystem/wapm/publishing-your-package)
+- [En savoir plus sur Wasmer](https://medium.com/wasmer/)
+
+## Intégrations
+
+📦 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 |
+|-|-|-|-|
+| ![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* | |
+
+[👋 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
+[`wasmer` rust crate]: https://crates.io/crates/wasmer/
+[rust docs]: https://wasmerio.github.io/wasmer/crates/wasmer_runtime
+
+[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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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]: 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
+
+[swift integration]: https://github.com/AlwaysRightInstitute/SwiftyWasmer
+
+## Contribuer
+
+**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 [notre documentation](https://docs.wasmer.io/ecosystem/wasmer/building-from-source)!
+
+### Test
+
+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é
+
+Wasmer a une incroyable communauté de développeurs et de contributeurs. Bienvenue et rejoignez-nous ! 👋
+
+### Canaux de communications
+
+- [Slack](https://slack.wasmer.io/)
+- [Twitter](https://twitter.com/wasmerio)
+- [Facebook](https://www.facebook.com/wasmerio)
+- [Email](mailto:hello@wasmer.io)
diff --git a/examples/hello_world.rs b/examples/hello_world.rs
index dbe559226..55142db1c 100644
--- a/examples/hello_world.rs
+++ b/examples/hello_world.rs
@@ -45,6 +45,7 @@ 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());
+
// 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)?;
@@ -71,6 +72,7 @@ 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)?;
+
// 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/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs
index ccd1ac773..8d2f92d3b 100644
--- a/examples/tunables_limit_memory.rs
+++ b/examples/tunables_limit_memory.rs
@@ -1,6 +1,7 @@
use std::ptr::NonNull;
use std::sync::Arc;
+use loupe::MemoryUsage;
use wasmer::{
imports,
vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition},
@@ -14,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
diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock
index 4d434c371..d19cdc2c9 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,27 @@ dependencies = [
"cfg-if 1.0.0",
]
+[[package]]
+name = "loupe"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1acf065b51eb58abbc66a07c27ec63142205d339a9f5093dc3e1d7cda3d5c9a3"
+dependencies = [
+ "indexmap",
+ "loupe-derive",
+ "rustversion",
+]
+
+[[package]]
+name = "loupe-derive"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e40881c741681f26b0f4c0261f493c8df600998807184b524e34b7e208324834"
+dependencies = [
+ "quote",
+ "syn",
+]
+
[[package]]
name = "mach"
version = "0.3.2"
@@ -822,6 +843,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 +910,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 +928,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 +1065,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 +1073,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 +1087,7 @@ version = "1.0.2"
dependencies = [
"cfg-if 0.1.10",
"indexmap",
+ "loupe",
"more-asserts",
"target-lexicon",
"thiserror",
@@ -1096,6 +1124,7 @@ name = "wasmer-compiler"
version = "1.0.2"
dependencies = [
"enumset",
+ "loupe",
"serde",
"serde_bytes",
"smallvec",
@@ -1114,6 +1143,7 @@ dependencies = [
"cranelift-entity",
"cranelift-frontend",
"gimli",
+ "loupe",
"more-asserts",
"rayon",
"serde",
@@ -1135,6 +1165,7 @@ dependencies = [
"itertools",
"lazy_static",
"libc",
+ "loupe",
"rayon",
"regex",
"rustc_version",
@@ -1154,6 +1185,7 @@ dependencies = [
"dynasm",
"dynasmrt",
"lazy_static",
+ "loupe",
"more-asserts",
"rayon",
"serde",
@@ -1180,6 +1212,7 @@ dependencies = [
"backtrace",
"bincode",
"lazy_static",
+ "loupe",
"memmap2",
"more-asserts",
"rustc-demangle",
@@ -1198,6 +1231,7 @@ version = "1.0.2"
dependencies = [
"bincode",
"cfg-if 0.1.10",
+ "loupe",
"region",
"serde",
"serde_bytes",
@@ -1216,6 +1250,7 @@ dependencies = [
"cfg-if 0.1.10",
"leb128",
"libloading",
+ "loupe",
"serde",
"tempfile",
"tracing",
@@ -1231,6 +1266,7 @@ dependencies = [
name = "wasmer-middlewares"
version = "1.0.2"
dependencies = [
+ "loupe",
"wasmer",
"wasmer-types",
"wasmer-vm",
@@ -1250,6 +1286,7 @@ dependencies = [
name = "wasmer-types"
version = "1.0.2"
dependencies = [
+ "loupe",
"serde",
"thiserror",
]
@@ -1263,6 +1300,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 07ccfe8e3..ed6cabf16 100644
--- a/lib/api/Cargo.toml
+++ b/lib/api/Cargo.toml
@@ -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 = "0.1"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = "0.3"
diff --git a/lib/api/src/exports.rs b/lib/api/src/exports.rs
index 606a052e5..4bfea97ed 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::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 633a1be82..16440e3c3 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::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.
+ #[loupe(skip)]
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 83d7630a1..0d111e0ee 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::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..8cfe9f876 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::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..ead70f2ec 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::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 f0b266234..98777ad2d 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::MemoryUsage;
use std::sync::Arc;
use wasmer_engine::{Export, ExportTable};
use wasmer_vm::{Table as RuntimeTable, TableReference, VMExportTable};
@@ -17,7 +18,7 @@ use wasmer_vm::{Table as RuntimeTable, TableReference, 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..592fd2eec 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::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/api/src/module.rs b/lib/api/src/module.rs
index 714991cba..ea2b8b8d8 100644
--- a/lib/api/src/module.rs
+++ b/lib/api/src/module.rs
@@ -1,6 +1,7 @@
use crate::store::Store;
use crate::types::{ExportType, ImportType};
use crate::InstantiationError;
+use loupe::MemoryUsage;
use std::fmt;
use std::io;
use std::path::Path;
@@ -30,7 +31,7 @@ pub enum IoCompileError {
///
/// Cloning a module is cheap: it does a shallow copy of the compiled
/// contents rather than a deep copy.
-#[derive(Clone)]
+#[derive(Clone, MemoryUsage)]
pub struct Module {
store: Store,
artifact: Arc,
diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs
index 661375082..2371fd18b 100644
--- a/lib/api/src/store.rs
+++ b/lib/api/src/store.rs
@@ -1,4 +1,5 @@
use crate::tunables::BaseTunables;
+use loupe::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..d714ffd60 100644
--- a/lib/api/src/tunables.rs
+++ b/lib/api/src/tunables.rs
@@ -1,4 +1,5 @@
use crate::{MemoryType, Pages, TableType};
+use loupe::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 017daca37..c5ec84b03 100644
--- a/lib/compiler-cranelift/Cargo.toml
+++ b/lib/compiler-cranelift/Cargo.toml
@@ -25,6 +25,7 @@ serde = { version = "1.0", features = ["derive"] }
more-asserts = "0.2"
gimli = { version = "0.23", optional = true }
smallvec = "1.6"
+loupe = "0.1"
[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..dd2970330 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::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 e9d0831c2..6834e1d52 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::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..04052feaf 100644
--- a/lib/compiler-llvm/Cargo.toml
+++ b/lib/compiler-llvm/Cargo.toml
@@ -22,6 +22,7 @@ libc = { version = "^0.2", default-features = false }
byteorder = "1"
itertools = "0.10"
rayon = "1.5"
+loupe = "0.1"
[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..d3d1b8428 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::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..245a27e92 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::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,
+ #[loupe(skip)]
pub(crate) opt_level: LLVMOptLevel,
is_pic: bool,
+ #[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 2c771c8c5..9af24654b 100644
--- a/lib/compiler-singlepass/Cargo.toml
+++ b/lib/compiler-singlepass/Cargo.toml
@@ -24,6 +24,7 @@ dynasmrt = "1.0"
lazy_static = "1.4"
byteorder = "1.3"
smallvec = "1.6"
+loupe = "0.1"
[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..edc1d93a4 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::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..d788478a9 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::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..1c3941963 100644
--- a/lib/compiler/Cargo.toml
+++ b/lib/compiler/Cargo.toml
@@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
thiserror = "1.0"
serde_bytes = { version = "0.11", optional = true }
smallvec = "1.6"
+loupe = "0.1"
[features]
default = ["std", "enable-serde"]
diff --git a/lib/compiler/src/address_map.rs b/lib/compiler/src/address_map.rs
index 40d37a073..4fd8c1a23 100644
--- a/lib/compiler/src/address_map.rs
+++ b/lib/compiler/src/address_map.rs
@@ -3,12 +3,13 @@
use crate::lib::std::vec::Vec;
use crate::sourceloc::SourceLoc;
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
/// Single source location to generated address mapping.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)]
pub struct InstructionAddressMap {
/// Original source location.
pub srcloc: SourceLoc,
@@ -22,7 +23,7 @@ pub struct InstructionAddressMap {
/// Function and its instructions addresses mappings.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Eq, Default)]
+#[derive(Debug, Clone, PartialEq, Eq, Default, MemoryUsage)]
pub struct FunctionAddressMap {
/// Instructions maps.
/// The array is sorted by the InstructionAddressMap::code_offset field.
diff --git a/lib/compiler/src/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/function.rs b/lib/compiler/src/function.rs
index 6be0ae9ac..e431f3bb7 100644
--- a/lib/compiler/src/function.rs
+++ b/lib/compiler/src/function.rs
@@ -12,6 +12,7 @@ use crate::lib::std::vec::Vec;
use crate::section::{CustomSection, SectionIndex};
use crate::trap::TrapInformation;
use crate::{CompiledFunctionUnwindInfo, FunctionAddressMap, JumpTableOffsets, Relocation};
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use wasmer_types::entity::PrimaryMap;
@@ -22,7 +23,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, SignatureIndex};
/// This structure is only used for reconstructing
/// the frame information after a `Trap`.
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
-#[derive(Debug, Clone, PartialEq, Eq, Default)]
+#[derive(Debug, Clone, PartialEq, Eq, Default, MemoryUsage)]
pub struct CompiledFunctionFrameInfo {
/// The traps (in the function body).
///
@@ -35,7 +36,7 @@ pub struct CompiledFunctionFrameInfo {
/// The function body.
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)]
pub struct FunctionBody {
/// The function body bytes.
#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))]
@@ -79,7 +80,7 @@ pub type CustomSections = PrimaryMap;
/// In the future this structure may also hold other information useful
/// for debugging.
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
-#[derive(Debug, PartialEq, Eq, Clone)]
+#[derive(Debug, PartialEq, Eq, Clone, MemoryUsage)]
pub struct Dwarf {
/// The section index in the [`Compilation`] that corresponds to the exception frames.
/// [Learn
diff --git a/lib/compiler/src/jump_table.rs b/lib/compiler/src/jump_table.rs
index 19da678c7..25fdbb60c 100644
--- a/lib/compiler/src/jump_table.rs
+++ b/lib/compiler/src/jump_table.rs
@@ -5,6 +5,7 @@
//! [Learn more](https://en.wikipedia.org/wiki/Branch_table).
use super::CodeOffset;
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use wasmer_types::entity::{entity_impl, SecondaryMap};
@@ -14,7 +15,7 @@ use wasmer_types::entity::{entity_impl, SecondaryMap};
/// `JumpTable`s are used for indirect branching and are specialized for dense,
/// 0-based jump offsets.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, MemoryUsage)]
pub struct JumpTable(u32);
entity_impl!(JumpTable, "jt");
diff --git a/lib/compiler/src/module.rs b/lib/compiler/src/module.rs
index dacbdf356..b78821312 100644
--- a/lib/compiler/src/module.rs
+++ b/lib/compiler/src/module.rs
@@ -1,4 +1,5 @@
use crate::lib::std::sync::Arc;
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use wasmer_types::entity::PrimaryMap;
@@ -10,7 +11,7 @@ use wasmer_vm::{MemoryStyle, ModuleInfo, TableStyle};
/// This differs from [`ModuleInfo`] because it have extra info only
/// possible after translation (such as the features used for compiling,
/// or the `MemoryStyle` and `TableStyle`).
-#[derive(Debug)]
+#[derive(Debug, MemoryUsage)]
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
pub struct CompileModuleInfo {
/// The features used for compiling the module
diff --git a/lib/compiler/src/relocation.rs b/lib/compiler/src/relocation.rs
index c0e6306ed..25cec340a 100644
--- a/lib/compiler/src/relocation.rs
+++ b/lib/compiler/src/relocation.rs
@@ -13,6 +13,7 @@ use crate::lib::std::fmt;
use crate::lib::std::vec::Vec;
use crate::section::SectionIndex;
use crate::{Addend, CodeOffset, JumpTable};
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use wasmer_types::entity::PrimaryMap;
@@ -21,7 +22,7 @@ use wasmer_vm::libcalls::LibCall;
/// Relocation kinds for every ISA.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, MemoryUsage)]
pub enum RelocationKind {
/// absolute 4-byte
Abs4,
@@ -79,7 +80,7 @@ impl fmt::Display for RelocationKind {
/// A record of a relocation to perform.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)]
pub struct Relocation {
/// The relocation kind.
pub kind: RelocationKind,
@@ -93,7 +94,7 @@ pub struct Relocation {
/// Destination function. Can be either user function or some special one, like `memory.grow`.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, MemoryUsage)]
pub enum RelocationTarget {
/// A relocation to a function defined locally in the wasm (not an imported one).
LocalFunc(LocalFunctionIndex),
diff --git a/lib/compiler/src/section.rs b/lib/compiler/src/section.rs
index 096cbcc8c..f6f3ee404 100644
--- a/lib/compiler/src/section.rs
+++ b/lib/compiler/src/section.rs
@@ -7,13 +7,14 @@
use crate::lib::std::vec::Vec;
use crate::Relocation;
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use wasmer_types::entity::entity_impl;
/// Index type of a Section defined inside a WebAssembly `Compilation`.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)]
pub struct SectionIndex(u32);
entity_impl!(SectionIndex);
@@ -22,7 +23,7 @@ entity_impl!(SectionIndex);
///
/// Determines how a custom section may be used.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)]
pub enum CustomSectionProtection {
/// A custom section with read permission.
Read,
@@ -36,7 +37,7 @@ pub enum CustomSectionProtection {
/// This is used so compilers can store arbitrary information
/// in the emitted module.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)]
pub struct CustomSection {
/// Memory protection that applies to this section.
pub protection: CustomSectionProtection,
@@ -55,7 +56,7 @@ pub struct CustomSection {
/// The bytes in the section.
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Eq, Default)]
+#[derive(Debug, Clone, PartialEq, Eq, Default, MemoryUsage)]
pub struct SectionBody(#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))] Vec);
impl SectionBody {
diff --git a/lib/compiler/src/sourceloc.rs b/lib/compiler/src/sourceloc.rs
index 2964e144d..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::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 9d18d79e8..12b2b06f1 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::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 {
+ #[loupe(skip)]
triple: Triple,
+ #[loupe(skip)]
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/compiler/src/trap.rs b/lib/compiler/src/trap.rs
index 058f7e21c..80aecc73a 100644
--- a/lib/compiler/src/trap.rs
+++ b/lib/compiler/src/trap.rs
@@ -1,11 +1,12 @@
use crate::CodeOffset;
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use wasmer_vm::TrapCode;
/// Information about trap.
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq, MemoryUsage)]
pub struct TrapInformation {
/// The offset of the trapping instruction in native code. It is relative to the beginning of the function.
pub code_offset: CodeOffset,
diff --git a/lib/compiler/src/unwind.rs b/lib/compiler/src/unwind.rs
index 309492814..128c300de 100644
--- a/lib/compiler/src/unwind.rs
+++ b/lib/compiler/src/unwind.rs
@@ -6,6 +6,7 @@
//!
//! [Learn more](https://en.wikipedia.org/wiki/Call_stack).
use crate::lib::std::vec::Vec;
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
@@ -17,7 +18,7 @@ use serde::{Deserialize, Serialize};
///
/// [unwind info]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq, MemoryUsage)]
pub enum CompiledFunctionUnwindInfo {
/// Windows UNWIND_INFO.
WindowsX64(Vec),
diff --git a/lib/engine-jit/Cargo.toml b/lib/engine-jit/Cargo.toml
index a4d1c6f90..9d54965d4 100644
--- a/lib/engine-jit/Cargo.toml
+++ b/lib/engine-jit/Cargo.toml
@@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive", "rc"] }
serde_bytes = { version = "0.11" }
bincode = "1.3"
cfg-if = "0.1"
+loupe = "0.1"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["winnt", "impl-default"] }
diff --git a/lib/engine-jit/src/artifact.rs b/lib/engine-jit/src/artifact.rs
index 050724985..a83e026e5 100644
--- a/lib/engine-jit/src/artifact.rs
+++ b/lib/engine-jit/src/artifact.rs
@@ -6,6 +6,7 @@ use crate::link::link_module;
#[cfg(feature = "compiler")]
use crate::serialize::SerializableCompilation;
use crate::serialize::SerializableModule;
+use loupe::MemoryUsage;
use std::sync::{Arc, Mutex};
use wasmer_compiler::{CompileError, Features, Triple};
#[cfg(feature = "compiler")]
@@ -27,9 +28,11 @@ use wasmer_vm::{
};
/// A compiled wasm module, ready to be instantiated.
+#[derive(MemoryUsage)]
pub struct JITArtifact {
serializable: SerializableModule,
finished_functions: BoxedSlice,
+ #[loupe(skip)]
finished_function_call_trampolines: BoxedSlice,
finished_dynamic_function_trampolines: BoxedSlice,
signatures: BoxedSlice,
diff --git a/lib/engine-jit/src/code_memory.rs b/lib/engine-jit/src/code_memory.rs
index 3d23e1eda..1498a23ea 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::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 7964f2dd3..b089bb1ff 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::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
@@ -145,6 +146,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/serialize.rs b/lib/engine-jit/src/serialize.rs
index 92596ff33..c924381b9 100644
--- a/lib/engine-jit/src/serialize.rs
+++ b/lib/engine-jit/src/serialize.rs
@@ -1,3 +1,4 @@
+use loupe::MemoryUsage;
use serde::{Deserialize, Serialize};
use wasmer_compiler::{
CompileModuleInfo, CustomSection, Dwarf, FunctionBody, JumpTableOffsets, Relocation,
@@ -18,7 +19,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, Sign
// }
/// The compilation related data for a serialized modules
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, MemoryUsage)]
pub struct SerializableCompilation {
pub function_bodies: PrimaryMap,
pub function_relocations: PrimaryMap>,
@@ -37,7 +38,7 @@ pub struct SerializableCompilation {
/// Serializable struct that is able to serialize from and to
/// a `JITArtifactInfo`.
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, MemoryUsage)]
pub struct SerializableModule {
pub compilation: SerializableCompilation,
pub compile_info: CompileModuleInfo,
diff --git a/lib/engine-jit/src/unwind/dummy.rs b/lib/engine-jit/src/unwind/dummy.rs
index 3d029ecd9..cfb636bd2 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::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..8362fec49 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::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..7d9e017c8 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(|(_, _)| 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..3e69503a1 100644
--- a/lib/engine-native/Cargo.toml
+++ b/lib/engine-native/Cargo.toml
@@ -24,6 +24,7 @@ leb128 = "0.2"
libloading = "0.7"
tempfile = "3.1"
which = "4.0"
+loupe = "0.1"
[features]
# Enable the `compiler` feature if you want the engine to compile
diff --git a/lib/engine-native/src/artifact.rs b/lib/engine-native/src/artifact.rs
index e4ceec3df..8f723c364 100644
--- a/lib/engine-native/src/artifact.rs
+++ b/lib/engine-native/src/artifact.rs
@@ -4,6 +4,7 @@
use crate::engine::{NativeEngine, NativeEngineInner};
use crate::serialize::ModuleMetadata;
use libloading::{Library, Symbol as LibrarySymbol};
+use loupe::MemoryUsage;
use std::error::Error;
use std::fs::File;
use std::io::{Read, Write};
@@ -37,10 +38,12 @@ use wasmer_vm::{
};
/// A compiled wasm module, ready to be instantiated.
+#[derive(MemoryUsage)]
pub struct NativeArtifact {
sharedobject_path: PathBuf,
metadata: ModuleMetadata,
finished_functions: BoxedSlice,
+ #[loupe(skip)]
finished_function_call_trampolines: BoxedSlice,
finished_dynamic_function_trampolines: BoxedSlice,
func_data_registry: Arc,
diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs
index 36c343ee5..196f743a0 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::MemoryUsage;
use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
@@ -17,7 +18,7 @@ use wasmer_vm::{
};
/// A WebAssembly `Native` Engine.
-#[derive(Clone)]
+#[derive(Clone, MemoryUsage)]
pub struct NativeEngine {
inner: Arc>,
/// The target for the compiler
@@ -183,7 +184,7 @@ impl Engine for NativeEngine {
}
}
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, MemoryUsage)]
pub(crate) enum Linker {
None,
Clang11,
@@ -228,29 +229,39 @@ 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 backing storage of `VMFuncRef`s. This centralized store ensures that 2
/// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`.
/// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped.
func_data: Arc,
+
/// 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.
+ #[loupe(skip)]
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.
+ #[loupe(skip)]
libraries: Vec,
}
diff --git a/lib/engine-native/src/serialize.rs b/lib/engine-native/src/serialize.rs
index 88fa9965d..47c012d77 100644
--- a/lib/engine-native/src/serialize.rs
+++ b/lib/engine-native/src/serialize.rs
@@ -1,10 +1,11 @@
+use loupe::MemoryUsage;
use serde::{Deserialize, Serialize};
use wasmer_compiler::{CompileModuleInfo, SectionIndex, Symbol, SymbolRegistry};
use wasmer_types::entity::{EntityRef, PrimaryMap};
use wasmer_types::{FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, SignatureIndex};
/// Serializable struct that represents the compiled metadata.
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Debug, MemoryUsage)]
pub struct ModuleMetadata {
pub compile_info: CompileModuleInfo,
pub prefix: String,
diff --git a/lib/engine-object-file/Cargo.toml b/lib/engine-object-file/Cargo.toml
index 36a0ee634..51defdb94 100644
--- a/lib/engine-object-file/Cargo.toml
+++ b/lib/engine-object-file/Cargo.toml
@@ -23,6 +23,7 @@ bincode = "1.3"
leb128 = "0.2"
libloading = "0.7"
tempfile = "3.1"
+loupe = "0.1"
[features]
# Enable the `compiler` feature if you want the engine to compile
diff --git a/lib/engine-object-file/src/artifact.rs b/lib/engine-object-file/src/artifact.rs
index 6e6ddc473..77ad08a9d 100644
--- a/lib/engine-object-file/src/artifact.rs
+++ b/lib/engine-object-file/src/artifact.rs
@@ -3,6 +3,7 @@
use crate::engine::{ObjectFileEngine, ObjectFileEngineInner};
use crate::serialize::{ModuleMetadata, ModuleMetadataSymbolRegistry};
+use loupe::MemoryUsage;
use std::collections::BTreeMap;
use std::error::Error;
use std::mem;
@@ -31,10 +32,12 @@ use wasmer_vm::{
};
/// A compiled wasm module, ready to be instantiated.
+#[derive(MemoryUsage)]
pub struct ObjectFileArtifact {
metadata: ModuleMetadata,
module_bytes: Vec,
finished_functions: BoxedSlice,
+ #[loupe(skip)]
finished_function_call_trampolines: BoxedSlice,
finished_dynamic_function_trampolines: BoxedSlice,
signatures: BoxedSlice,
diff --git a/lib/engine-object-file/src/engine.rs b/lib/engine-object-file/src/engine.rs
index 0d3888d82..2a15137bf 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::MemoryUsage;
use std::io::Read;
use std::path::Path;
use std::sync::{Arc, Mutex};
@@ -14,7 +15,7 @@ use wasmer_vm::{
};
/// A WebAssembly `ObjectFile` Engine.
-#[derive(Clone)]
+#[derive(Clone, MemoryUsage)]
pub struct ObjectFileEngine {
inner: Arc>,
/// The target for the compiler
@@ -174,23 +175,29 @@ 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 backing storage of `VMFuncRef`s. This centralized store ensures that 2
/// functions with the same `VMCallerCheckedAnyfunc` will have the same `VMFuncRef`.
/// It also guarantees that the `VMFuncRef`s stay valid until the engine is dropped.
func_data: Arc,
+
/// 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.
+ #[loupe(skip)]
prefixer: Option String + Send>>,
}
diff --git a/lib/engine-object-file/src/serialize.rs b/lib/engine-object-file/src/serialize.rs
index 8ec7da030..4077b68e6 100644
--- a/lib/engine-object-file/src/serialize.rs
+++ b/lib/engine-object-file/src/serialize.rs
@@ -1,10 +1,11 @@
+use loupe::MemoryUsage;
use serde::{Deserialize, Serialize};
use wasmer_compiler::{CompileModuleInfo, SectionIndex, Symbol, SymbolRegistry};
use wasmer_types::entity::{EntityRef, PrimaryMap};
use wasmer_types::{FunctionIndex, LocalFunctionIndex, OwnedDataInitializer, SignatureIndex};
/// Serializable struct that represents the compiled metadata.
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Debug, MemoryUsage)]
pub struct ModuleMetadata {
pub compile_info: CompileModuleInfo,
pub prefix: String,
@@ -13,6 +14,7 @@ pub struct ModuleMetadata {
pub function_body_lengths: PrimaryMap,
}
+#[derive(MemoryUsage)]
pub struct ModuleMetadataSymbolRegistry {
pub prefix: String,
}
diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml
index eab531b0f..8cd8c2f54 100644
--- a/lib/engine/Cargo.toml
+++ b/lib/engine/Cargo.toml
@@ -25,6 +25,7 @@ serde = { version = "1.0", features = ["derive", "rc"] }
serde_bytes = { version = "0.11" }
bincode = "1.3"
lazy_static = "1.4"
+loupe = "0.1"
[badges]
maintenance = { status = "actively-developed" }
diff --git a/lib/engine/src/artifact.rs b/lib/engine/src/artifact.rs
index 284710f05..a706dbdd7 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/engine.rs b/lib/engine/src/engine.rs
index bdf2deafc..b321c5c4b 100644
--- a/lib/engine/src/engine.rs
+++ b/lib/engine/src/engine.rs
@@ -2,6 +2,7 @@
use crate::tunables::Tunables;
use crate::{Artifact, DeserializeError};
+use loupe::MemoryUsage;
use memmap2::Mmap;
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
@@ -16,7 +17,7 @@ use wasmer_vm::{VMCallerCheckedAnyfunc, VMFuncRef, 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;
@@ -71,7 +72,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/export.rs b/lib/engine/src/export.rs
index e3342265a..d0014eb8c 100644
--- a/lib/engine/src/export.rs
+++ b/lib/engine/src/export.rs
@@ -1,10 +1,10 @@
+use loupe::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
+ #[loupe(skip)]
pub(crate) import_init_function_ptr: Option,
+
/// A function analogous to `Clone::clone` that returns a leaked `Box`.
+ #[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.
///
/// # Safety
/// - This function should only be called in when properly synchronized.
/// For example, in the `Drop` implementation of this type.
+ #[loupe(skip)]
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/engine/src/serialize.rs b/lib/engine/src/serialize.rs
index d501332c9..a36b47da3 100644
--- a/lib/engine/src/serialize.rs
+++ b/lib/engine/src/serialize.rs
@@ -1,3 +1,4 @@
+use loupe::MemoryUsage;
use serde::de::{Deserializer, Visitor};
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
@@ -5,7 +6,7 @@ use std::fmt;
use wasmer_compiler::CompiledFunctionFrameInfo;
/// This is the unserialized verison of `CompiledFunctionFrameInfo`.
-#[derive(Clone, Serialize, Deserialize)]
+#[derive(Clone, Serialize, Deserialize, MemoryUsage)]
#[serde(transparent)]
#[repr(transparent)]
pub struct UnprocessedFunctionFrameInfo {
@@ -44,7 +45,7 @@ impl UnprocessedFunctionFrameInfo {
/// of compiling at the same time that emiting the JIT.
/// In that case, we don't need to deserialize/process anything
/// as the data is already in memory.
-#[derive(Clone)]
+#[derive(Clone, MemoryUsage)]
pub enum SerializableFunctionFrameInfo {
/// The unprocessed frame info (binary)
Unprocessed(UnprocessedFunctionFrameInfo),
diff --git a/lib/engine/src/trap/frame_info.rs b/lib/engine/src/trap/frame_info.rs
index 8906a4478..3407ab742 100644
--- a/lib/engine/src/trap/frame_info.rs
+++ b/lib/engine/src/trap/frame_info.rs
@@ -11,6 +11,7 @@
//! FRAME_INFO.register(module, compiled_functions);
//! ```
use crate::serialize::SerializableFunctionFrameInfo;
+use loupe::MemoryUsage;
use std::cmp;
use std::collections::BTreeMap;
use std::sync::{Arc, RwLock};
@@ -44,6 +45,7 @@ pub struct GlobalFrameInfo {
/// An RAII structure used to unregister a module's frame information when the
/// module is destroyed.
+#[derive(MemoryUsage)]
pub struct GlobalFrameInfoRegistration {
/// The key that will be removed from the global `ranges` map when this is
/// dropped.
diff --git a/lib/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..3cf6cca76 100644
--- a/lib/middlewares/Cargo.toml
+++ b/lib/middlewares/Cargo.toml
@@ -14,6 +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 = "0.1"
[badges]
maintenance = { status = "actively-developed" }
diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs
index 94a07df28..faea363e0 100644
--- a/lib/middlewares/src/metering.rs
+++ b/lib/middlewares/src/metering.rs
@@ -1,8 +1,10 @@
//! `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 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 +14,7 @@ use wasmer::{
use wasmer_types::GlobalIndex;
use wasmer_vm::ModuleInfo;
-#[derive(Clone)]
+#[derive(Clone, MemoryUsage)]
struct MeteringGlobalIndexes(GlobalIndex, GlobalIndex);
impl MeteringGlobalIndexes {
@@ -154,6 +156,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..4e95f79f0 100644
--- a/lib/vm/Cargo.toml
+++ b/lib/vm/Cargo.toml
@@ -21,6 +21,7 @@ more-asserts = "0.2"
cfg-if = "0.1"
backtrace = "0.3"
serde = { version = "1.0", features = ["derive", "rc"] }
+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/export.rs b/lib/vm/src/export.rs
index e5d3475ea..806178ab4 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::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`).
+ #[loupe(skip)]
pub call_trampoline: Option,
/// A “reference” to the instance through the
diff --git a/lib/vm/src/func_data_registry.rs b/lib/vm/src/func_data_registry.rs
index 4ea8d36c0..7fc9fc24d 100644
--- a/lib/vm/src/func_data_registry.rs
+++ b/lib/vm/src/func_data_registry.rs
@@ -5,11 +5,12 @@
//! long as we need them to.
use crate::vmcontext::VMCallerCheckedAnyfunc;
+use loupe::MemoryUsage;
use std::collections::HashMap;
use std::sync::Mutex;
/// The registry that holds the values that `VMFuncRef`s point to.
-#[derive(Debug)]
+#[derive(Debug, MemoryUsage)]
pub struct FuncDataRegistry {
// 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 @@ unsafe impl Sync for FuncDataRegistry {}
/// A function reference. A single word that points to metadata about a function.
#[repr(transparent)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, MemoryUsage)]
pub struct VMFuncRef(pub(crate) *const VMCallerCheckedAnyfunc);
impl wasmer_types::NativeWasmType for VMFuncRef {
@@ -86,7 +87,7 @@ impl std::ops::DerefMut for VMFuncRef {
unsafe impl Send for VMFuncRef {}
unsafe impl Sync for VMFuncRef {}
-#[derive(Debug, Default)]
+#[derive(Debug, Default, MemoryUsage)]
struct Inner {
func_data: Vec>,
anyfunc_to_index: HashMap,
diff --git a/lib/vm/src/global.rs b/lib/vm/src/global.rs
index 6ef82b600..4e1f091a1 100644
--- a/lib/vm/src/global.rs
+++ b/lib/vm/src/global.rs
@@ -1,11 +1,12 @@
use crate::vmcontext::VMGlobalDefinition;
+use loupe::MemoryUsage;
use std::cell::UnsafeCell;
use std::ptr::NonNull;
use std::sync::Mutex;
use thiserror::Error;
use wasmer_types::{GlobalType, Mutability, Type, Value, ValueEnumType};
-#[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 7a16b749f..d46b159f6 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 memoffset::offset_of;
use more_asserts::assert_lt;
use std::any::Any;
@@ -36,9 +37,10 @@ use std::collections::HashMap;
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,
@@ -57,6 +59,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 +81,7 @@ pub(crate) struct Instance {
functions: BoxedSlice,
/// Pointers to function call trampolines in executable memory.
+ #[loupe(skip)]
function_call_trampolines: BoxedSlice,
/// Passive elements in this instantiation. As `elem.drop`s happen, these
@@ -95,6 +99,7 @@ pub(crate) struct Instance {
host_state: Box,
/// Handler run when `SIGBUS`, `SIGFPE`, `SIGILL`, or `SIGSEGV` are caught by the instance thread.
+ #[loupe(skip)]
pub(crate) signal_handler: Cell>>,
/// Functions to operate on host environments in the imports
@@ -108,6 +113,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).
+ #[loupe(skip)]
vmctx: VMContext,
}
@@ -127,6 +133,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
@@ -192,6 +199,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()
@@ -872,7 +885,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/lib.rs b/lib/vm/src/lib.rs
index 45af311b8..2a4b02bd8 100644
--- a/lib/vm/src/lib.rs
+++ b/lib/vm/src/lib.rs
@@ -58,13 +58,14 @@ pub use crate::vmcontext::{
VMTableImport, VMTrampoline,
};
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMOffsets};
+use loupe::MemoryUsage;
pub use wasmer_types::VMExternRef;
/// 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 b9de28bac..f93893331 100644
--- a/lib/vm/src/libcalls.rs
+++ b/lib/vm/src/libcalls.rs
@@ -41,6 +41,7 @@ use crate::table::{TableElement, TableReference};
use crate::trap::{raise_lib_trap, Trap, TrapCode};
use crate::vmcontext::VMContext;
use crate::VMExternRef;
+use loupe::MemoryUsage;
use serde::{Deserialize, Serialize};
use std::fmt;
use wasmer_types::{
@@ -680,7 +681,7 @@ pub static wasmer_vm_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..e64cfd132 100644
--- a/lib/vm/src/memory.rs
+++ b/lib/vm/src/memory.rs
@@ -7,6 +7,7 @@
use crate::mmap::Mmap;
use crate::vmcontext::VMMemoryDefinition;
+use loupe::MemoryUsage;
use more_asserts::assert_ge;
use serde::{Deserialize, Serialize};
use std::borrow::BorrowMut;
@@ -61,7 +62,7 @@ pub enum MemoryError {
}
/// Implementation styles for WebAssembly linear memory.
-#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, MemoryUsage)]
pub enum MemoryStyle {
/// The actual memory can be resized and moved.
Dynamic {
@@ -96,7 +97,7 @@ impl MemoryStyle {
}
/// Trait for implementing Wasm Memory used by Wasmer.
-pub trait Memory: fmt::Debug + Send + Sync {
+pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {
/// Returns the memory type for this memory.
fn ty(&self) -> &MemoryType;
@@ -116,7 +117,7 @@ pub trait Memory: fmt::Debug + Send + Sync {
}
/// A linear memory instance.
-#[derive(Debug)]
+#[derive(Debug, MemoryUsage)]
pub struct LinearMemory {
// The underlying allocation.
mmap: Mutex,
@@ -144,7 +145,7 @@ pub struct LinearMemory {
/// A type to help manage who is responsible for the backing memory of them
/// `VMMemoryDefinition`.
-#[derive(Debug)]
+#[derive(Debug, MemoryUsage)]
enum VMMemoryDefinitionOwnership {
/// The `VMMemoryDefinition` is owned by the `Instance` and we should use
/// its memory. This is how a local memory that's exported should be stored.
@@ -167,7 +168,7 @@ unsafe impl Send for LinearMemory {}
/// This is correct because all internal mutability is protected by a mutex.
unsafe impl Sync for LinearMemory {}
-#[derive(Debug)]
+#[derive(Debug, MemoryUsage)]
struct WasmMmap {
// Our OS allocation of mmap'd memory.
alloc: Mmap,
diff --git a/lib/vm/src/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/module.rs b/lib/vm/src/module.rs
index 79bb1b418..861ac4b94 100644
--- a/lib/vm/src/module.rs
+++ b/lib/vm/src/module.rs
@@ -5,6 +5,7 @@
//! `wasmer::Module`.
use indexmap::IndexMap;
+use loupe::MemoryUsage;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt;
@@ -19,7 +20,7 @@ use wasmer_types::{
TableIndex, TableInitializer, TableType,
};
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, MemoryUsage)]
pub struct ModuleId {
id: usize,
}
@@ -41,7 +42,7 @@ impl Default for ModuleId {
/// A translated WebAssembly module, excluding the function bodies and
/// memory initializers.
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize, MemoryUsage)]
pub struct ModuleInfo {
/// A unique identifier (within this process) for this module.
///
diff --git a/lib/vm/src/sig_registry.rs b/lib/vm/src/sig_registry.rs
index 58b690fc6..051006bc9 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::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/table.rs b/lib/vm/src/table.rs
index aa77ee491..6b299c7b7 100644
--- a/lib/vm/src/table.rs
+++ b/lib/vm/src/table.rs
@@ -9,6 +9,7 @@ use crate::func_data_registry::VMFuncRef;
use crate::trap::{Trap, TrapCode};
use crate::vmcontext::VMTableDefinition;
use crate::VMExternRef;
+use loupe::{MemoryUsage, MemoryUsageTracker};
use serde::{Deserialize, Serialize};
use std::borrow::{Borrow, BorrowMut};
use std::cell::UnsafeCell;
@@ -19,14 +20,14 @@ use std::sync::Mutex;
use wasmer_types::{ExternRef, 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;
@@ -134,6 +135,12 @@ pub union TableElement {
pub(crate) func_ref: VMFuncRef,
}
+impl MemoryUsage for TableElement {
+ fn size_of_val(&self, _: &mut dyn MemoryUsageTracker) -> usize {
+ std::mem::size_of_val(self)
+ }
+}
+
impl fmt::Debug for TableElement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("TableElement").finish()
@@ -155,7 +162,7 @@ impl Default for TableReference {
}
/// 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>,
@@ -169,7 +176,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 3f8113988..ee3e910fb 100644
--- a/lib/vm/src/trap/trapcode.rs
+++ b/lib/vm/src/trap/trapcode.rs
@@ -5,13 +5,14 @@
use core::fmt::{self, Display, Formatter};
use core::str::FromStr;
+use loupe::MemoryUsage;
use serde::{Deserialize, Serialize};
use thiserror::Error;
/// A trap code describing the reason for a trap.
///
/// All trap instructions have an explicit trap code.
-#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize, Deserialize, Error)]
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize, Deserialize, Error, MemoryUsage)]
#[repr(u32)]
pub enum TrapCode {
/// The current stack space was exhausted.
diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs
index c4b4e131e..9d294e9fc 100644
--- a/lib/vm/src/vmcontext.rs
+++ b/lib/vm/src/vmcontext.rs
@@ -11,9 +11,11 @@ use crate::memory::Memory;
use crate::table::Table;
use crate::trap::{Trap, TrapCode};
use crate::VMExternRef;
+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;
@@ -59,8 +61,14 @@ impl std::hash::Hash 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.
@@ -177,7 +185,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:
@@ -198,7 +206,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.
@@ -236,7 +244,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.
@@ -274,7 +282,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.
@@ -346,6 +354,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.
///
@@ -455,6 +473,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;
@@ -511,11 +539,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,
@@ -756,7 +790,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)]
@@ -801,7 +835,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, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, MemoryUsage)]
#[repr(C)]
pub struct VMCallerCheckedAnyfunc {
/// Function body.
diff --git a/lib/vm/src/vmoffsets.rs b/lib/vm/src/vmoffsets.rs
index 2a7ab375e..7d849e88e 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::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,
diff --git a/lib/wasmer-types/Cargo.toml b/lib/wasmer-types/Cargo.toml
index 1c6a581cd..19877a373 100644
--- a/lib/wasmer-types/Cargo.toml
+++ b/lib/wasmer-types/Cargo.toml
@@ -13,6 +13,7 @@ edition = "2018"
[dependencies]
serde = { version = "1.0", features = ["derive"], optional = true, default-features = false }
thiserror = "1.0"
+loupe = "0.1"
[features]
default = ["std", "enable-serde"]
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/features.rs b/lib/wasmer-types/src/features.rs
index 6cde5408e..50bc4f8a5 100644
--- a/lib/wasmer-types/src/features.rs
+++ b/lib/wasmer-types/src/features.rs
@@ -1,3 +1,4 @@
+use loupe::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..ed5f32015 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::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/initializers.rs b/lib/wasmer-types/src/initializers.rs
index 0d47554c5..3683ecf04 100644
--- a/lib/wasmer-types/src/initializers.rs
+++ b/lib/wasmer-types/src/initializers.rs
@@ -1,11 +1,12 @@
use crate::indexes::{FunctionIndex, GlobalIndex, MemoryIndex, TableIndex};
use crate::lib::std::boxed::Box;
+use loupe::MemoryUsage;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
/// A WebAssembly table initializer.
-#[derive(Clone, Debug, Hash, Serialize, Deserialize)]
+#[derive(Clone, Debug, Hash, Serialize, Deserialize, MemoryUsage)]
pub struct TableInitializer {
/// The index of a table to initialize.
pub table_index: TableIndex,
@@ -19,7 +20,7 @@ pub struct TableInitializer {
/// A memory index and offset within that memory where a data initialization
/// should be performed.
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, MemoryUsage)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct DataInitializerLocation {
/// The index of the memory to initialize.
@@ -45,7 +46,7 @@ pub struct DataInitializer<'data> {
/// As `DataInitializer` but owning the data rather than
/// holding a reference to it
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, MemoryUsage)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct OwnedDataInitializer {
/// The location where the initialization is to be performed.
diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs
index 6dd8fdf97..cf2b59a8a 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, ValueEnumType};
+use loupe::{MemoryUsage, MemoryUsageTracker};
#[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.
@@ -97,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
@@ -225,7 +232,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
@@ -310,7 +317,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
@@ -346,7 +353,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.
@@ -389,7 +396,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 +448,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 +487,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/lib/wasmer-types/src/units.rs b/lib/wasmer-types/src/units.rs
index 93e9f04d4..1d1360b60 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::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/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)]
diff --git a/tests/lib/engine-dummy/Cargo.toml b/tests/lib/engine-dummy/Cargo.toml
index 22c659d64..01a50903a 100644
--- a/tests/lib/engine-dummy/Cargo.toml
+++ b/tests/lib/engine-dummy/Cargo.toml
@@ -15,6 +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 = "0.1"
[features]
# Enable the `compiler` feature if you want the engine to compile
diff --git a/tests/lib/engine-dummy/src/artifact.rs b/tests/lib/engine-dummy/src/artifact.rs
index 235f12eb5..a5a993c40 100644
--- a/tests/lib/engine-dummy/src/artifact.rs
+++ b/tests/lib/engine-dummy/src/artifact.rs
@@ -2,6 +2,7 @@
//! done as separate steps.
use crate::engine::DummyEngine;
+use loupe::MemoryUsage;
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::sync::Arc;
@@ -21,6 +22,7 @@ use wasmer_vm::{
/// Serializable struct for the artifact
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
+#[derive(MemoryUsage)]
pub struct DummyArtifactMetadata {
pub module: Arc,
pub features: Features,
@@ -34,10 +36,11 @@ pub struct DummyArtifactMetadata {
///
/// This artifact will point to fake finished functions and trampolines
/// as no functions are really compiled.
+#[derive(MemoryUsage)]
pub struct DummyArtifact {
metadata: DummyArtifactMetadata,
-
finished_functions: BoxedSlice,
+ #[loupe(skip)]
finished_function_call_trampolines: BoxedSlice,
finished_dynamic_function_trampolines: BoxedSlice,
signatures: BoxedSlice,
diff --git a/tests/lib/engine-dummy/src/engine.rs b/tests/lib/engine-dummy/src/engine.rs
index f4c6258ba..cdc80b81b 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::MemoryUsage;
use std::sync::Arc;
use wasmer_compiler::{CompileError, Features, Target};
use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables};
@@ -20,7 +21,7 @@ extern "C" fn dummy_trampoline(
}
/// A WebAssembly `Dummy` Engine.
-#[derive(Clone)]
+#[derive(Clone, MemoryUsage)]
pub struct DummyEngine {
signatures: Arc,
func_data: Arc,