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

AOT/JIT stack frame enhancement #2506

Open
wenyongh opened this issue Aug 25, 2023 · 4 comments
Open

AOT/JIT stack frame enhancement #2506

wenyongh opened this issue Aug 25, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@wenyongh
Copy link
Contributor

AOT stack frame enhancement

Motivation

Currently LLVM AOT/JIT doesn’t use the stack frame like interpreter/fast-jit except in the feature of dumping call stack and performance profiling, since the operations of the function local variables and stack operators have been optimized to the operations of registers and native stack by the LLVM codegen. The stack frame data is very simple in dump-call-stack and perf-profiling features, only several fields are stored in the stack frame, including func_index, time_started, total_exec_time and total_exec_cnt. There may be some scenarios requiring to create the stack frame data like interpreter and commit data to it when needed:

  • GC AOT/JIT: when doing the garbage collection, the runtime needs to traverse each stack frame in each thread and add the GC objects in the stack frame to the root set. Refer to GC (Garbage Collection) AOT support #2144.
  • AOT/JIT source debugger: if the function locals and stack operands can be committed into the stack frame, it may be possible to implement the AOT source debugger like interpreter: read the local variable from stack frame, get the line number in the source file by getting the current bytecode (frame ip) from stack frame and using it to retrieve the line number in dwarf info.
  • AOT/JIT Checkpoint save and restore: we may create the snapshot with all stack frame stored, and using it to restore and continue to run. Refer to Proposed implementation of AOT stack frame #2333.

The data to commit to the stack frame

It may include:

  • The parameters and locals of current function
  • The stack operands of current function
  • The stack pointer
  • The bytecode address, or instruction pointer
  • The frame ref flags for GC

Some functionalities to support

  • Support commit data from LLVM registers/native-stack into stack frame when branch/call opcodes are met, or when the opcodes may trigger GC object allocation
  • Support commit the data from the current thread, like one thread requests to do GC
  • Support commit the data from a standalone thread (non wasm thread)

And also we should support the current dump-call-stack and perf-profiling features.

Extend the AOTFrame structure

Add some fields in it, including ip, sp, frame_ref, lp and so on. And make the offset of these fields fixed, so the compiler can easily calculate the offsets of them in the running status.

@wenyongh wenyongh added the enhancement New feature or request label Aug 25, 2023
@wenyongh
Copy link
Contributor Author

#2350

wenyongh added a commit that referenced this issue Aug 28, 2023
Implement a full LLVM AOT/JIT stack frame dump:
commit the function arguments, locals, stack operands from LLVM values to the stack frame,
which is required by the GC AOT/JIT feature, and may be required by the AOT debugger,
AOT snapshot and other features.

Refer to:
#2144
#2333
#2506
@tamaroning
Copy link

@wenyongh
Hello, what is the current status of this issue? It seems that the dev branch has not merged to main yet.
I am interested in using AOT stack frames to checkpoint/restore wasm runtimes.

@wenyongh
Copy link
Contributor Author

Hi, the AOT stack frame feature is already supported in the main branch: it was merged into branch dev/gc_refactor, and the latter was merged into main. Please refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/build_wamr.md#enable-aot-stack-frame-feature

And for checkpoint/restore feature, maybe you can refer to this PR:
#3289

@tamaroning
Copy link

Thank you for your swift response and sharing useful information:)

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

No branches or pull requests

2 participants