Add architecture diagram for wasm globals and classic-interp stack frame (#2058)

This commit is contained in:
Wang Xin 2023-03-25 09:39:20 +08:00 committed by GitHub
parent 09a2698bba
commit b0f614d77a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 5048 additions and 3 deletions

View File

@ -70,8 +70,8 @@ The following platforms are supported, click each link below for how to build iw
### Performance and memory
- [Blog: Understand WAMR heap](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-heap/)
- [Blog: Understand WAMR stacks](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-stacks/)
- [Blog: The WAMR memory model](https://bytecodealliance.github.io/wamr.dev/blog/the-wamr-memory-model/)
- [Blog: Understand WAMR heaps](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-heaps/) and [stacks](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-stacks/)
- [Blog: Introduction to WAMR running modes](https://bytecodealliance.github.io/wamr.dev/blog/introduction-to-wamr-running-modes/)
- [Memory usage tunning](./doc/memory_tune.md): the memory model and how to tune the memory usage
- [Memory usage profiling](./doc/build_wamr.md#enable-memory-profiling-experiment): how to profile the memory usage

View File

@ -6,3 +6,9 @@
## Exports
- [Wasm export architecture](./doc/wasm_exports.MD)
## globals
- [Wasm globals architecture](./doc/wasm_globals.MD)
## classic interpreter
- [classic interpreter](./doc/classic_interpreter.MD)

View File

@ -0,0 +1,5 @@
# Classic interpreter
## stack format
![](./images/stack_format_ci.svg)

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 112 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -3,3 +3,45 @@
## Internal data structure
![](./images/wasm_function.svg)
## Module level data (function)
**WASMModule**: Data structure created for loading a module.
- `WASMImport *import_functions`: initialized from the Wasm file function section
- `WASMImport *import_functions`: initialized from the Wasm file import section. The runtime will try to solve the imports from the native API registration, refer to [Export native API to WASM application](../../../doc/export_native_api.md).
**WASMFunction**: represent a Wasm function located in Wasm file code section. Track the links to the compiled function body.
**WASMImport**: represent a imported Wasm function which can be a solved as a native function or another Wasm module exported function.
## Instance level data (function)
**WASMModuleInstance**: Data structure created for instantiating a module
- `WASMModuleInstanceExtra::functions`: combined the imported and internal functions into single array of structure `WASMFunctionInstance`
- `WASMModuleInstance::import_func_ptrs`: pointer array for solved function imports. This array is referred during calling imported native function. Note it is initialzed with the module level solved imports, but may points to different native function later due to c-api calls.
## Execution paths
**Interpreter**:
- Execute internal bytecode function:
```
WASMModuleInstance::e
-> WASMModuleInstanceExtra::functions[..]
-> WASMFunctionInstance::func
-> WASMFunction::code
```
- Execute imported function from other module:
```
WASMModuleInstance::e
-> WASMModuleInstanceExtra::functions[..]
(WASMFunctionInstance flag indicates an import)
-> WASMFunctionInstance::import_func_inst
-> WASMModuleInstance(second)::func
-> WASMFunction (second module)::code
```
- Execute imported native function:
```
WASMModuleInstance::e
-> WASMModuleInstanceExtra::functions[..]
(flag indicates imported native)
WASMModuleInstance::import_func_ptrs[..]
-> native function
```

View File

@ -0,0 +1,4 @@
# Wasm globals
![](./images/wasm_globals.svg)

View File

@ -1,7 +1,7 @@
# Memory model and memory usage tunning
References:
- [Blog: Understand WAMR heap](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-heap/)
- [Blog: Understand WAMR heap](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-heaps/)
- [Blog: Understand WAMR stacks](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-stacks/)
## The memory model