Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GC (Garbage Collection) feature for interpreter, AOT and LLVM-JIT #3125

Merged
merged 120 commits into from
Feb 6, 2024

Conversation

wenyongh
Copy link
Contributor

@wenyongh wenyongh commented Feb 4, 2024

No description provided.

wenyongh and others added 30 commits February 16, 2023 17:02
The latest GC spec proposal has changed a lot since we implemented the feature,
refactor it based on the main branch. Part of the spec cases were tested.
Implement GC for fast interpreter except struct/array related opcodes
And fix compile warning in wasm_c_api.c from wasm_table_get.

Signed-off-by: Huang Qi <[email protected]>
- Add cmake variable `WAMR_BUILD_GC_BINARYEN`
- Implement GC opcode array.copy
- Fix bug in wasm_type_is_supers_of
- Fix loader load import global and wasm_loader_pop_frame_ref
- Support pass/return GC ref type params/result to/from native API
Change `wasm_obj_t *gc_obj` to `wasm_obj_t gc_obj`
And add comments for the GC export APIs
Merge branch main into dev/gc_refactor
- don't mark non-ref array elements
- trace ref returned from native function
- fix calculated array element offset error in reclaim_instance_heap
The runtime instance memory layout changed when GC was enabled. With this patch
the GC is enabled for wamrc, but it keeps the compatibility with iwasm no matter GC
is enabled for it or not.

It may waste some memory for iwasm without GC support since the GC relative fields
for the table instance are always here, let's optimization it after AOT fully supports GC.
wenyongh and others added 27 commits December 12, 2023 12:12
Unify the emitting and loading logic for table/memory/global init data.
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.
- 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
For interpreter, jit and aot, the format is like:
```
#00: 0x1330 - __main_argc_argv
#1: 0x4195 - __main_void
#2: 0x11dc - _start
```
For fast-jit and multi-tier jit, the format is like:
```
#00 __main_argc_argv
#1 __main_void
#2 _start
```
Since fast-jit hasn't supported commit ip to stack frame now.
Don't commit params/locals ref flags in AOT code to improve
the performance.
- 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
- Emit SIMD/ref-types/bulk-memory flags into AOT file only when the features
  are really used in wasm file
- Remove unused tail-call flag and stringref flag
- Add memoy64 flag and dynamic-linking flag
- Change WASM_FEATURE_THREADS to WASM_FEATURE_MULTI_THREAD
Add wasm_runtime_get_cur_local_obj_ref and change API:
```C
wasm_runtime_push_local_object_ref
wasm_runtime_pop_local_object_ref
wasm_runtime_pop_local_object_refs
```
to
```C
wasm_runtime_push_local_obj_ref
wasm_runtime_pop_local_obj_ref
wasm_runtime_pop_local_obj_refs
```

Signed-off-by: zhangliangyu3 <[email protected]>
…ne info of wasm src (#3128)

Implement the tool to convert the bytecode offset (address) in call-stack dump
into to the line info in wasm source code.
Remove `JIT_STACK_FRAME` cmake variable and compilation macro, and
use `AOT_STACK_FRAME` instead, to avoid introducing too many macros.

Same as using `WASM_ENABLE_QUICK_AOT_ENTRY` macro to control code
for LLVM JIT.
@wenyongh wenyongh merged commit 16a4d71 into main Feb 6, 2024
808 checks passed
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…VM-JIT (bytecodealliance#3125)

Implement the GC (Garbage Collection) feature for interpreter mode,
AOT mode and LLVM-JIT mode, and support most features of the latest
spec proposal, and also enable the stringref feature.

Use `cmake -DWAMR_BUILD_GC=1/0` to enable/disable the feature,
and `wamrc --enable-gc` to generate the AOT file with GC supported.

And update the AOT file version from 2 to 3 since there are many AOT
ABI breaks, including the changes of AOT file format, the changes of
AOT module/memory instance layouts, the AOT runtime APIs for the
AOT code to invoke and so on.
stack_size = 48 * 1024;
#if WASM_ENABLE_TAIL_CALL == 0
if (stack_size < 128 * 1024)
stack_size = 128 * 1024;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wenyongh
why have you bumped stack size here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember it well now since it took a long time to develop the GC feature, seems that at first the tail call cases were disabled temporarily or not added to GC spec proposal, and running GC cases requires more native stack. But now the tail call is enabled when testing GC cases, maybe can restore it to 48KB now. I tested the value with some features and didn't find issue: ./test -s spec -t aot -b -P, ./test -s spec -t aot -p -b -P, ./test -s spec -t aot -M -b -P, ./test -s spec -t aot -W -b -P.

if (stack_size < 128 * 1024)
stack_size = 128 * 1024;
#else
/* Some tail-call cases require large operand stack */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wenyongh
which cases are they?
tail-call tests consuming much stack sounds like a real bug in our implementation, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cases can be found: https://github.com/WebAssembly/gc/blob/master/test/core/return_call.wast#L105-L118.

Yes, it is really an issue, due to our limited knowledge, we didn't find a better way to improve it when implementing AOT tail call feature. You also mentioned the problem in #2231, do you think we can resolve it with musttail attribute or is there other way to resolve it? Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. i commented my current thoughts in #2231.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants