Commit Graph

224 Commits

Author SHA1 Message Date
Val Packett
99c057bcb5 compiler: add munmap finalizer on cache hits to avoid memory leak (#1815)
Signed-off-by: Val Packett <val@packett.cool>
2023-10-25 16:01:01 +08:00
Edoardo Vacchi
4d208309cf wazevo: passes simd_lane spectests (#1739)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-10-05 09:29:32 +02:00
Takeshi Yoneda
756ecc58e2 Simplifies wasm.ElementInstance struct (#1754)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-10-05 08:11:21 +09:00
Takeshi Yoneda
57b44b653f experimental: removes Parameters API from StackIterator (#1716)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-09-18 15:14:34 +09:00
Takeshi Yoneda
6515656e5f Completes migration of enginetest to integration_tests (#1707)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-09-14 10:02:18 +09:00
Takeshi Yoneda
5250820c1c Migrates enginetest into integration tests (#1705)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-09-13 13:56:25 +09:00
Takeshi Yoneda
c9019e6406 wazevo: supports for LookupFunction API (#1704)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-09-13 12:36:56 +09:00
Takeshi Yoneda
b8262fe4fb Lifts LookupFunction into ModuleInstance from ModuleEngine (#1636)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-08-18 10:46:50 +09:00
Takeshi Yoneda
a9c5a44690 wazevo: adds support for imported memory (#1628)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-08-14 15:47:18 +09:00
Takeshi Yoneda
7c88d2a9d4 wazevo: adds support for load instructions (#1624)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-08-11 11:22:24 +09:00
Nuno Cruces
1bd9a3c17b Use atomic.Uint64. (#1620)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-08-09 14:09:54 +01:00
Nuno Cruces
90f58bce75 compiler: fix compiledModule leak (#1608)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
2023-08-02 09:14:49 +08:00
Anuraag Agrawal
6b4328c66e Return err instead of nil in amd64 store impl (#1594)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-07-24 16:03:00 +09:00
Anuraag Agrawal
6c6a2848ab Fix grammar in comment about peeking (#1593)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-07-24 12:46:33 +09:00
inkeliz
451a1b63a0 engine: mitigates memory leak (#1535)
Signed-off-by: inkeliz <inkeliz@inkeliz.com>
2023-06-26 12:41:51 +08:00
Nuno Cruces
c43a169a25 compiler(amd64): avoid emitting useless trap code (#1527)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-19 19:53:13 +10:00
Edoardo Vacchi
ea63499005 compiler(arm64): avoid conditional jumps to the trap handler (#1524)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-06-19 19:18:18 +10:00
Edoardo Vacchi
f385873239 compiler(arm64): generate trap exit code once (#1516)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-06-15 08:35:51 +10:00
Nuno Cruces
26eae5756c compiler(amd64): generate exit code once (#1515)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-14 16:19:13 +10:00
Nuno Cruces
e3755ce4af compiler(amd64): avoid unnecessary jump in signed remainder (#1514)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-13 10:01:34 +10:00
Nuno Cruces
b4d97e5e69 compiler(amd64): emit smaller instructions (#1513)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-13 06:50:56 +10:00
Nuno Cruces
8c7f97d39d compiler(amd64): eliminate a bounds check in memory copy (#1509)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-09 10:58:53 +10:00
Nuno Cruces
83ac0f6b87 compiler(amd64): generate trap exit code once (#1508)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-09 10:54:25 +10:00
Nuno Cruces
8d8e452dc0 compiler(amd64): generate trap exit code once (#1505)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-06 09:41:27 +10:00
Anuraag Agrawal
62f8109101 compiler: fix compileMemoryAccessOffsetSetup comment (#1504)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-06-05 16:16:23 +10:00
Chris O'Hara
50394cc1fa engine: call FunctionListener.Abort in correct order (#1501) 2023-06-01 19:53:04 -07:00
Achille
9780f0f4a0 compiler: zero-copy code assembly (#1481)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-05-19 07:06:30 +02:00
Edoardo Vacchi
a8b4642ce4 compiler: fix benchmarks in compiler, engine; add to Makefile, update API calls (#1480)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-18 09:30:58 +02:00
Achille
9bbb9c871e compiler: compress code offsets (#1467)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-15 18:41:52 -07:00
Achille
719f11861d compiler: optimize allocation of asm.Node slice (#1468)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-15 18:12:04 +10:00
Achille
d3efad1fc4 compiler: remove intermediary copy of compiled functions code (#1466)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-05-14 23:22:16 -07:00
Achille
ab116e9c21 compiler: reuse asm.Node slice collecting NOP instructions for source mapping (#1465)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-14 15:20:17 -07:00
Nuno Cruces
52b32e4872 compiler: avoid some unsafe.Pointers (#1456)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-05-12 08:04:36 +10:00
Takeshi Yoneda
80452a94c3 Bulk lazy initialization of FunctionDefinitions (#1425)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-12 08:02:40 +10:00
Achille
78c35acd6e experimental: remove return value of FunctionListener.Before (#1453)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-05-11 11:52:10 +08:00
Achille
a105c43629 experimental: remove error parameter from FunctionListener.After (#1452)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-11 06:48:26 +08:00
Crypt Keeper
745f2c9d8a Adds IsNonblock SetNonblock PollRead to platform.File (#1447)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-10 08:43:54 +08:00
Thomas Pelletier
ef3d671195 experimental: split program counter and source offset resolution (#1448)
Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
2023-05-09 13:34:01 -07:00
Achille
509827a23f experimental: optimize function listener context stack (#1445) 2023-05-09 08:10:12 -07:00
Thomas Pelletier
ed17e523ba experimental: expose source offset to Listener (#1433)
Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-09 08:18:27 +08:00
Nuno Cruces
2bf8abe1fe Cleanup scattered documentation TODOs. (#1442)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-05-08 18:04:02 +01:00
Edoardo Vacchi
a912ea844e compiler: update RATIONALE.md for native check (#1432)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-04 07:37:13 +08:00
Takeshi Yoneda
f47b0d3362 Reduces FunctionDefinition usages (#1419)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-05-01 10:37:43 +08:00
Nuno Cruces
77e8d72d67 api: adds CallWithStack to avoid allocations (#1407)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-05-01 08:52:40 +09:00
Thomas Pelletier
0bfb4b52eb Give Listener a read-only view of globals (#1404)
* experimental: give listener r/o view of globals

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* experimental: add global support to interpreter

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* exp: replace globals proxy with module interface

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* exp: trim down experimental.InternalModule

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Replace globals view slice with constantGlobal

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Fix tests after merge

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Address PR feedback

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Rename methods of experimental.Module

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Run make check

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Add WazeroOnlyType to constantGlobal

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

---------

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
2023-04-29 00:07:28 -07:00
Nuno Cruces
197facf7a9 Close certain api interfaces for external implementation (#1396)
This adds a new type `internalapi.WazeroOnly` which should be embedded on types users are likely to accidentally implement despite docs saying otherwise.

Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-04-28 15:32:32 +08:00
Takeshi Yoneda
867459d7d5 compiler: mmap per module instead of per function (#1377)
This changes the mmap strategy used in the compiler backend.
Previously, we used mmap syscall once per function and allocated the 
executable pages each time. Basically, mmap can only allocate the 
boundary of the page size of the underlying os. Even if the requested 
executable is smaller than the page size, the entire page is marked as 
executable and won't be reused by Go runtime. Therefore, we wasted 
roughly `(len(body)%osPageSize)*function`.

Even though we still need to align each function on 16 bytes boundary
when mmaping per module, the wasted space is much smaller than before.

The following benchmark results shows that this improves the overall 
compilation performance while showing the heap usage increased. 
However, the increased heap usage is totally offset by the hidden wasted
memory page which is not measured by Go's -benchmem.
Actually, when I did the experiments, I observed that roughly 20~30mb are
wasted on arm64 previously which is larger than the increased heap usage
in this result. More importantly, this increased heap usage is a target of GC
and should be ignorable in the long-running program vs the wasted page 
is persistent until the CompiledModule is closed.

Not only the actual compilation time, the result indicates that this could 
improve the overall Go runtime's performance maybe thanks to not abusing
runtime.Finalizer since you can see this improves the subsequent interpreter 
benchmark results.

```
goos: darwin
goarch: arm64
pkg: github.com/tetratelabs/wazero/internal/integration_test/bench
                                   │   old.txt   │              new.txt              │
                                   │   sec/op    │   sec/op     vs base              │
Compilation_sqlite3/compiler-10      183.4m ± 0%   175.9m ± 2%  -4.10% (p=0.001 n=7)
Compilation_sqlite3/interpreter-10   61.59m ± 0%   59.57m ± 0%  -3.29% (p=0.001 n=7)
geomean                              106.3m        102.4m       -3.69%

                                   │   old.txt    │               new.txt               │
                                   │     B/op     │     B/op      vs base               │
Compilation_sqlite3/compiler-10      42.93Mi ± 0%   54.33Mi ± 0%  +26.56% (p=0.001 n=7)
Compilation_sqlite3/interpreter-10   51.75Mi ± 0%   51.75Mi ± 0%   -0.01% (p=0.001 n=7)
geomean                              47.13Mi        53.02Mi       +12.49%

                                   │   old.txt   │              new.txt              │
                                   │  allocs/op  │  allocs/op   vs base              │
Compilation_sqlite3/compiler-10      26.07k ± 0%   26.06k ± 0%       ~ (p=0.149 n=7)
Compilation_sqlite3/interpreter-10   13.90k ± 0%   13.90k ± 0%       ~ (p=0.421 n=7)
geomean                              19.03k        19.03k       -0.02%


goos: linux
goarch: amd64
pkg: github.com/tetratelabs/wazero/internal/integration_test/bench
cpu: AMD Ryzen 9 3950X 16-Core Processor
                                   │   old.txt   │              new.txt               │
                                   │   sec/op    │   sec/op     vs base               │
Compilation_sqlite3/compiler-32      384.4m ± 2%   373.0m ± 4%   -2.97% (p=0.001 n=7)
Compilation_sqlite3/interpreter-32   86.09m ± 4%   65.05m ± 2%  -24.44% (p=0.001 n=7)
geomean                              181.9m        155.8m       -14.38%

                                   │   old.txt    │               new.txt               │
                                   │     B/op     │     B/op      vs base               │
Compilation_sqlite3/compiler-32      49.40Mi ± 0%   59.91Mi ± 0%  +21.29% (p=0.001 n=7)
Compilation_sqlite3/interpreter-32   51.77Mi ± 0%   51.76Mi ± 0%   -0.02% (p=0.001 n=7)
geomean                              50.57Mi        55.69Mi       +10.12%

                                   │   old.txt   │              new.txt              │
                                   │  allocs/op  │  allocs/op   vs base              │
Compilation_sqlite3/compiler-32      28.70k ± 0%   28.70k ± 0%       ~ (p=0.925 n=7)
Compilation_sqlite3/interpreter-32   14.00k ± 0%   14.00k ± 0%  -0.04% (p=0.010 n=7)
geomean                              20.05k        20.04k       -0.02%
```

resolves #1060 

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-26 14:11:37 +09:00
Takeshi Yoneda
3c1c76e2a1 debug: includes Go stack trace in the face of Go runtime errors (#1401)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-25 10:45:20 +09:00
Takeshi Yoneda
70c5e03836 compiler(amd64): reuses static consts properly (#1382)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-19 16:18:01 +09:00
Takeshi Yoneda
d33ecd0e3a cache: fixes consistency with CloseOnContextDone and listeners (#1381)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-19 15:00:46 +09:00