Commit Graph

142 Commits

Author SHA1 Message Date
Wenyong Huang
e70c5219c0 Merge branch main into dev/gc_refactor 2024-01-26 16:43:51 +08:00
Wenyong Huang
313ce8cb61
Fix memory/table segment checks in memory.init/table.init (#3081)
According to the wasm core spec, the checks for the table segments in
`table.init` opcode are similar to the checks for `memory.init` opcode:
- The size of a passive segment is shrunk to zero after `data.drop`
  (or `elem.drop`) opcode is executed, and the segment can be used to do
  `memory.init` (or `table.init`) again
- The `memory.init` only traps when `s+n > len(data.data)` or `d+n > len(mem.data)`
  and `table.init` only traps when `s+n > len(elem.elem)` or `d+n > len(tab.elem)`
- The active segment can also be used to do `memory.init` (or `table.init`),
  while it behaves like a dropped passive segment

https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
```
Segments can also be shrunk to size zero by using the following new instructions:
- data.drop: discard the data in an data segment
- elem.drop: discard the data in an element segment

An active segment is equivalent to a passive segment, but with an implicit
memory.init followed by a data.drop (or table.init followed by a elem.drop)
that is prepended to the module's start function.
```
ps.
https://webassembly.github.io/spec/core/bikeshed/#-hrefsyntax-instr-memorymathsfmemoryinitx%E2%91%A0
https://webassembly.github.io/spec/core/bikeshed/#-hrefsyntax-instr-tablemathsftableinitxy%E2%91%A0
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3020
2024-01-26 09:45:59 +08:00
Wenyong Huang
a7545df5d0
classic-interp: Handle SIMD opcode when JIT is enabled (#3046)
Though SIMD isn't supported by interpreter, when JIT is enabled,
developer may run `iwasm --interp <wasm_file>` to trigger the SIMD
opcode in interpreter, which isn't handled before this PR.
2024-01-19 12:31:18 +08:00
Wenyong Huang
9bcf6b4dd3
Enable quick aot entry when hw bound check is disabled (#3044)
- Enable quick aot entry when hw bound check is disabled
- Remove unnecessary ret_type argument in the quick aot entries
- Declare detailed prototype of aot function to call in each quick aot entry
2024-01-19 08:55:35 +08:00
Wenyong Huang
4f0551ac25
Enable quick aot entry when GC is enabled (#3015)
- Set gc func type's quick_aot_entry
- Call quick_aot_entry when hw bound check is disabled
- Declare detailed aot func's prototype inside the quick aot entry
- Remove ret_type in the quick aot entry
- Update docker image
2024-01-18 18:28:17 +08:00
liang.he
5c8b8a17a6
Enhancements on wasm function execution time statistic (#2985)
Enhance the statistic of wasm function execution time, or the performance
profiling feature:
- Add os_time_thread_cputime_us() to get the cputime of a thread,
  and use it to calculate the execution time of a wasm function
- Support the statistic of the children execution time of a function,
  and dump it in wasm_runtime_dump_perf_profiling
- Expose two APIs:
  wasm_runtime_sum_wasm_exec_time
  wasm_runtime_get_wasm_func_exec_time

And rename os_time_get_boot_microsecond to os_time_get_boot_us.
2024-01-17 09:51:54 +08:00
Wenyong Huang
644044522c Merge branch main into dev/gc_refactor 2024-01-12 18:40:47 +08:00
Wenyong Huang
7c7684819d
Register quick call entries to speedup the aot/jit func call process (#2978)
In some scenarios there may be lots of callings to AOT/JIT functions from the
host embedder, which expects good performance for the calling process, while
in the current implementation, runtime calls the wasm_runtime_invoke_native
to prepare the array of registers and stacks for the invokeNative assemble code,
and the latter then puts the elements in the array to physical registers and
native stacks and calls the AOT/JIT function, there may be many data copying
and handlings which impact the performance.

This PR registers some quick AOT/JIT entries for some simple wasm signatures,
and let runtime call the entry to directly invoke the AOT/JIT function instead of
calling wasm_runtime_invoke_native, which speedups the calling process.

We may extend the mechanism next to allow the developer to register his quick
AOT/JIT entries to speedup the calling process of invoking the AOT/JIT functions
for some specific signatures.
2024-01-10 16:44:09 +08:00
Wenyong Huang
d31455fc4e
Refactor aot stack frame commit (#2976)
- Commit locals, stacks and stack pointer to aot frame only when gc is enabled
- Commit instruction pointer to aot frame when stack frame is enabled
- Refine alloc/free aot frame when gc isn't enabled: use fixed frame size
- Support dump call stack with bytecode offset
2024-01-08 11:18:49 +08:00
Wenyong Huang
cc23a09d5e
Fix test script error and related wamrc and GC issues (#2975)
The wamrc execution errors were skipped in the runtest.py due to `sys.exit(1)`
was caught by upper try-catch sentence and ignored with ret_code 0 returned.

This PR fixed this script issue and fixed the related wamrc/GC issues found.
2024-01-08 09:41:56 +08:00
Wenyong Huang
e6d210a67f Merge branch main into dev/gc_refactor 2024-01-03 12:11:57 +08:00
Wenyong Huang
3637f2df79
Refine LLVM JIT function call process (#2925)
- Don't allocate the implicit/unused frame when calling the LLVM JIT function
- Don't set exec_env's thread handle and stack boundary in the recursive
  calling from host, since they have been set in the first time calling
- Fix frame not freed in llvm_jit_call_func_bytecode
2024-01-02 18:46:02 +08:00
YAMAMOTO Takashi
18529253d8
interpreter: Simplify memory.grow a bit (#2899) 2023-12-12 20:24:51 +08:00
Wenyong Huang
eab09a2af5 Merge branch main into dev/gc_refactor 2023-12-12 12:50:20 +08:00
Wenyong Huang
cf7350f069
Implement aot_alloc_frame/aot_free_frame with LLVM IRs (#2830) 2023-12-12 12:12:02 +08:00
Xu Jun
92176be7d6
Sync up with the latest GC MVP spec proposal (#2836) 2023-12-12 11:49:44 +08:00
Yage Hu
ef0cd22119
Fix memory size not updating after growing in interpreter (#2898)
This commit fixes linear memory size not updating after growing.
This causes `memory.fill` to throw an exception after `memory.grow`.
2023-12-12 08:36:59 +08:00
Enrico Loparco
0455071fc1
Access linear memory size atomically (#2834)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2804
2023-11-29 20:27:17 +08:00
Wenyong Huang
9c71ca6c46 Merge branch main into dev/gc_refactor 2023-11-29 09:23:00 +08:00
Xu Jun
77d27c9ff6
Enable stringref aot (#2816) 2023-11-27 10:50:12 +08:00
Wenyong Huang
5d9cbfe109
Implement GC AOT object reclaim process (#2762) 2023-11-22 14:39:07 +08:00
Huang Qi
0b29904f26
Fix configurable bounds checks typo (#2809) 2023-11-21 17:32:45 +08:00
YAMAMOTO Takashi
562a5dd1b6
Fix data/elem drop (#2747)
Currently, `data.drop` instruction is implemented by directly modifying the
underlying module. It breaks use cases where you have multiple instances
sharing a single loaded module. `elem.drop` has the same problem too.

This PR  fixes the issue by keeping track of which data/elem segments have
been dropped by using bitmaps for each module instances separately, and
add a sample to demonstrate the issue and make the CI run it.

Also add a missing check of dropped elements to the fast-jit `table.init`.

Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2735
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2772
2023-11-18 08:50:16 +08:00
YAMAMOTO Takashi
24c4d256b3
Grab cluster->lock when modifying exec_env->module_inst (#2685)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2680

And when switching back to the original module_inst, propagate exception if any.

cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2512
2023-11-09 18:56:02 +08:00
Wenyong Huang
348d82b923 Merge branch main into dev/gc_refactor 2023-11-03 15:39:28 +08:00
Wenyong Huang
52328f0565
Fix GC AOT struct/array/i31/exception issues (#2664)
Refactor the exception IDs for GC feature.
2023-10-25 21:42:55 +08:00
Wenyong Huang
4f5ad4dc12
Apply no_sanitize_address for clang compiler in several places (#2663)
Apply `no_sanitize_address` for clang compiler in several places in which
it has been applied to gcc compiler.

And refine the comment.
2023-10-25 08:05:26 +08:00
Su Yihan
2f45f12cd7
Support stringref proposal (#2651)
This PR implements the WebAssembly stringref proposal:
  https://github.com/WebAssembly/stringref

It adds cmake variable `WAMR_BUILD_STRINGREF` to build the feature,
which will enable GC automatically.

The stringref contains two parts:
- `part 1`: add new ref types in WasmGC, add opcode processing in loader and interpreter
- `part 2`: add a library for string representation/encoding/decoding and so on

To reduce the code size introduced to WAMR, this PR only includes `part 1`,
`part 2` can be provided by embedder, they may use their own implementation,
e.g., Wasmnizer-ts uses JSString from QuickJS to implement stringref:
https://github.com/intel/Wasmnizer-ts/blob/main/runtime-library/stringref/stringref_qjs.c

We will submit another PR of `part 2` and make it as a sample rather than WAMR core part.

Signed-off-by: Su Yihan <yihan.su@intel.com>
Co-authored-by: Xu Jun <jun1.xu@intel.com>
2023-10-23 12:45:37 +08:00
Xu Jun
995817e463
Init frame->sp and frame->ip at entry of call func in interpreter (#2636) 2023-10-12 15:12:54 +08:00
Wenyong Huang
ae508e25fa Merge branch dev/aot_stack_frame into dev/gc_refactor 2023-10-09 14:21:39 +08:00
Wenyong Huang
85869ed604 Merge branch main into dev/gc_refactor 2023-10-08 10:53:13 +08:00
Wenyong Huang
7a9ed07411 Merge branch main into dev/aot_stack_frame 2023-10-08 10:01:45 +08:00
funera1
64baf54d88
Fix label index out-of-range references in op_br_table_cache (#2615)
Fixed a bug in the processing of the br_table_cache opcode that caused out-of-range
references when the label index was greater than the length of the label.
2023-10-03 10:33:00 +08:00
Enrico Loparco
00539620e9
Improve stack trace dump and fix coding guideline CI (#2599)
Avoid the stack traces getting mixed up together when multi-threading is enabled
by using exception_lock/unlock in dumping the call stacks.

And remove duplicated call stack dump in wasm_application.c.

Also update coding guideline CI to fix the clang-format-12 not found issue.
2023-09-29 10:52:54 +08:00
Wenyong Huang
4b09e283ef
Add option for JIT stack frame and update documents (#2565)
Allow `cmake -DWAMR_BUILD_JIT_STACK_FRAME=1` to enable stack frame
for JIT mode.

And fix some issues in doc/build_wamr.md.
2023-09-19 16:07:38 +08:00
Wenyong Huang
03155cf22b Merge branch main into dev/gc_refactor 2023-08-23 16:40:13 +08:00
YAMAMOTO Takashi
51714c41c0
Introduce WASMModuleInstanceExtraCommon (#2429)
Move the common parts of WASMModuleInstanceExtra and
AOTModuleInstanceExtra into the new structure.
2023-08-08 09:35:29 +08:00
Wenyong Huang
803597dc55 Merge branch main into dev/gc_refactor 2023-08-07 09:35:10 +08:00
YAMAMOTO Takashi
91592429f4
Fix memory sharing (#2415)
- Inherit shared memory from the parent instance, instead of
  trying to look it up by the underlying module. The old method
  works correctly only when every cluster uses different module.
- Use reference count in WASMMemoryInstance/AOTMemoryInstance
  to mark whether the memory is shared or not
- Retire WASMSharedMemNode
- For atomic opcode implementations in the interpreters, use
  a global lock for now
- Update the internal API users
  (wasi-threads, lib-pthread, wasm_runtime_spawn_thread)

Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/1962
2023-08-04 10:18:13 +08:00
Wenyong Huang
59b2099b68
Fix some check issues on table operations (#2392)
Fix some check issues on table.init, table.fill and table.copy, and unify the check method
for all running modes.
Fix issue #2390 and #2096.
2023-07-27 21:53:48 +08:00
Marcin Kolny
0f4edf9735
Implement suspend flags as atomic variable (#2361)
We have observed a significant performance degradation after merging
https://github.com/bytecodealliance/wasm-micro-runtime/pull/1991
Instead of protecting suspend flags with a mutex, we implement the flags
as atomic variable and only use mutex when atomics are not available
on a given platform.
2023-07-21 08:27:09 +08:00
Xu Jun
f906585b56
Fix drop opcode not clear frame ref issue (#2360) 2023-07-18 15:54:47 +08:00
YAMAMOTO Takashi
228a3bed53
Fix unused warnings on disable_bounds_checks (#2347) 2023-07-06 15:31:22 +08:00
Huang Qi
18092f86cc
Make memory access boundary check behavior configurable (#2289)
Allow to use `cmake -DWAMR_CONFIGURABLE_BOUNDS_CHECKS=1` to
build iwasm, and then run `iwasm --disable-bounds-checks` to disable the
memory access boundary checks.

And add two APIs:
`wasm_runtime_set_bounds_checks` and `wasm_runtime_is_bounds_checks_enabled`
2023-07-04 16:21:30 +08:00
Wenyong Huang
366b3b7683 Merge branch main into dev/gc_refactor 2023-06-05 14:13:45 +08:00
Xu Jun
9fd8480107
[GC] Fix frame ref not cleared issue in classic and fast interpreter (#2206) 2023-05-30 17:28:48 +08:00
Wenyong Huang
76be848ec3
Implement the segue optimization for LLVM AOT/JIT (#2230)
Segue is an optimization technology which uses x86 segment register to store
the WebAssembly linear memory base address, so as to remove most of the cost
of SFI (Software-based Fault Isolation) base addition and free up a general
purpose register, by this way it may:
- Improve the performance of JIT/AOT
- Reduce the footprint of JIT/AOT, the JIT/AOT code generated is smaller
- Reduce the compilation time of JIT/AOT

This PR uses the x86-64 GS segment register to apply the optimization, currently
it supports linux and linux-sgx platforms on x86-64 target. By default it is disabled,
developer can use the option below to enable it for wamrc and iwasm(with LLVM
JIT enabled):
```bash
wamrc --enable-segue=[<flags>] -o output_file wasm_file
iwasm --enable-segue=[<flags>] wasm_file [args...]
```
`flags` can be:
    i32.load, i64.load, f32.load, f64.load, v128.load,
    i32.store, i64.store, f32.store, f64.store, v128.store
Use comma to separate them, e.g. `--enable-segue=i32.load,i64.store`,
and `--enable-segue` means all flags are added.

Acknowledgement:
Many thanks to Intel Labs, UC San Diego and UT Austin teams for introducing this
technology and the great support and guidance!

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
Co-authored-by: Vahldiek-oberwagner, Anjo Lucas <anjo.lucas.vahldiek-oberwagner@intel.com>
2023-05-26 10:13:33 +08:00
Zzzabiyaka
27239723a9
Add asan and ubsan to WAMR CI (#2161)
Add nightly (UTC time) checks with asan and ubsan, and also put gcc-4.8 build
to nightly run since we don't need to run it with every PR.

Co-authored-by: Maksim Litskevich <makslit@amazon.co.uk>
2023-05-26 09:45:37 +08:00
Wenyong Huang
1e5f206464
Fix compile warnings on windows platform (#2208) 2023-05-15 13:48:48 +08:00
Xu Jun
8021df9894
Fix GC issues (#2204)
- don't mark non-ref array elements
- trace ref returned from native function
- fix calculated array element offset error in reclaim_instance_heap
2023-05-12 12:30:24 +08:00