Comments (5)
Hi, if the whole wasm file is loaded by wasm_runtime_load or wasm_runtime_load_ex, it is not easy to free the buffer of wasm file since some fields in the WASMModule may be referring to it. But if the wasm file is read section by section into a wasm_section_list_t and the host embedder allocates different buffers for each section, and the sections are loaded by wasm_runtime_load_from_sections, then after loading, some of the sections may be freed. You can also refer to the code in wamr-app-framework rep:
https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-mgr/app-manager/module_wasm_app.c#L787-L788
Note that it only frees SECTION_TYPE_DATA section, but for fast-interp, maybe you can try to free SECTION_TYPE_FUNC also.
from wasm-micro-runtime.
Thanks, I just had a go with this suggestion and it works nicely, however some of the code linked is using wamr internals (E.g. os_mmap, many compiler definitions etc) and my implementation involved a lot of copy/paste.
Would you be OK with a PR which added:
destroy_all_wasm_sections destroy_part_wasm_sections destroy_all_aot_sections destroy_part_aot_sections
and then another API something like:
struct load_section_result { wasm_section_list_t sections; bool is_aot; }; read_to_section_result read_to_sections(uint8_t* data, size_t size)
exported from the wamr library?
How about:
typedef struct load_section_result_t {
wasm_section_list_t sections;
bool is_aot;
} load_section_result_t;
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_read_to_sections(uint8_t *buf, size_t size, load_section_result_t *p_section_result);
// return true/false to indicate success or fail
// put result in p_section_result when success
WASM_RUNTIME_API_EXTERN void
wasm_runtime_destroy_sections(load_section_result_t *section_result, bool destroy_all_sections);
// destroy_all_sections: true to destroy all sections, false to destroy part sections
// and aot or wasm can be found in section_result->is_aot
from wasm-micro-runtime.
Thanks, I just had a go with this suggestion and it works nicely, however some of the code linked is using wamr internals (E.g. os_mmap, many compiler definitions etc) and my implementation involved a lot of copy/paste.
Would you be OK with a PR which added:
destroy_all_wasm_sections
destroy_part_wasm_sections
destroy_all_aot_sections
destroy_part_aot_sections
and then another API something like:
struct load_section_result {
wasm_section_list_t sections;
bool is_aot;
};
read_to_section_result read_to_sections(uint8_t* data, size_t size)
exported from the wamr library?
from wasm-micro-runtime.
Note that it only frees SECTION_TYPE_DATA section, but for fast-interp, maybe you can try to free SECTION_TYPE_FUNC also
Is there any guidance on which sections I must keep after module instantiation - if I only ever instantiate the module once.
from wasm-micro-runtime.
Note that it only frees SECTION_TYPE_DATA section, but for fast-interp, maybe you can try to free SECTION_TYPE_FUNC also
Is there any guidance on which sections I must keep after module instantiation - if I only ever instantiate the module once.
Maybe you can refer to:
https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-mgr/app-manager/module_wasm_app.c#L728-L746
https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-mgr/app-manager/module_wasm_app.c#L728-L746
Sorry that my understanding in the above post is invalid, the sections in sections1 should be abled to be freed after loading and sections in section2 can be freed after instantiation. But I am not sure for the bytecode for interpreter and machine code for AOT, maybe you can investigate the source code for more details.
from wasm-micro-runtime.
Related Issues (20)
- Unexpected behavior in fast-JIT mode and interpreter mode HOT 1
- There is an issue using sockets in wasm. HOT 11
- Empty `fd_pread` fails when it should succeed HOT 2
- wasm_is_reftype_supers_of_extern seems unused HOT 2
- Unexpected exception on fast interpreter mode HOT 2
- Unexpected behavior on fast interpreter mode HOT 2
- Wrong execution reuslt on fast interpreter mode HOT 2
- aot_load_const_from_table is inefficient
- "duplicate export name" check is O(n^2) HOT 3
- Compilation errors when build iwasm with GC and EH support
- iwasm: WASM module load failed: struct or array as field is not supported in constant expr HOT 6
- iwasm: WASM module load failed: type mismatch: expect (ref null ht) but got other1 unknown type HOT 13
- exception handler intercepts c++ exceptions in the host on windows HOT 4
- WASM module instantiate failed on Mac HOT 1
- aot: xtensa xip triggers llvm assertion failure
- BH_DEBUG not set in multi-configuration cmake (eg. visual studio)
- printf_wrapper (libc builtin) makes multiple calls to os_printf with individual characters HOT 6
- Can AOT file built on windows run directly on other platforms? HOT 5
- How to load and run another wasm in a running wasm? HOT 12
- Exception Handling Support in Fast Interpreter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasm-micro-runtime.