Implement GC (Garbage Collection) feature for interpreter, AOT and LLVM-JIT (#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.
This commit is contained in:
@ -5,6 +5,9 @@
|
||||
|
||||
#include "wasm_exec_env.h"
|
||||
#include "wasm_runtime_common.h"
|
||||
#if WASM_ENABLE_GC != 0
|
||||
#include "mem_alloc.h"
|
||||
#endif
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
#include "../interpreter/wasm_runtime.h"
|
||||
#endif
|
||||
@ -28,7 +31,7 @@ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst,
|
||||
uint32 stack_size)
|
||||
{
|
||||
uint64 total_size =
|
||||
offsetof(WASMExecEnv, wasm_stack.s.bottom) + (uint64)stack_size;
|
||||
offsetof(WASMExecEnv, wasm_stack_u.bottom) + (uint64)stack_size;
|
||||
WASMExecEnv *exec_env;
|
||||
|
||||
if (total_size >= UINT32_MAX
|
||||
@ -65,9 +68,10 @@ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst,
|
||||
|
||||
exec_env->module_inst = module_inst;
|
||||
exec_env->wasm_stack_size = stack_size;
|
||||
exec_env->wasm_stack.s.top_boundary =
|
||||
exec_env->wasm_stack.s.bottom + stack_size;
|
||||
exec_env->wasm_stack.s.top = exec_env->wasm_stack.s.bottom;
|
||||
exec_env->wasm_stack.bottom = exec_env->wasm_stack_u.bottom;
|
||||
exec_env->wasm_stack.top_boundary =
|
||||
exec_env->wasm_stack.bottom + stack_size;
|
||||
exec_env->wasm_stack.top = exec_env->wasm_stack.bottom;
|
||||
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||
@ -134,6 +138,9 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
||||
#endif
|
||||
WASMExecEnv *exec_env =
|
||||
wasm_exec_env_create_internal(module_inst, stack_size);
|
||||
#if WASM_ENABLE_GC != 0
|
||||
void *gc_heap_handle = NULL;
|
||||
#endif
|
||||
|
||||
if (!exec_env)
|
||||
return NULL;
|
||||
@ -145,6 +152,10 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
||||
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
|
||||
exec_env->aux_stack_boundary.boundary =
|
||||
module->aux_stack_bottom - module->aux_stack_size;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
gc_heap_handle =
|
||||
((WASMModuleInstance *)module_inst)->e->common.gc_heap_pool;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
@ -155,6 +166,11 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
||||
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
|
||||
exec_env->aux_stack_boundary.boundary =
|
||||
module->aux_stack_bottom - module->aux_stack_size;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
gc_heap_handle =
|
||||
((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e)
|
||||
->common.gc_heap_handle;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -164,6 +180,13 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
||||
wasm_exec_env_destroy_internal(exec_env);
|
||||
return NULL;
|
||||
}
|
||||
#if WASM_ENABLE_GC != 0
|
||||
mem_allocator_enable_gc_reclaim(gc_heap_handle, cluster);
|
||||
#endif
|
||||
#else
|
||||
#if WASM_ENABLE_GC != 0
|
||||
mem_allocator_enable_gc_reclaim(gc_heap_handle, exec_env);
|
||||
#endif
|
||||
#endif /* end of WASM_ENABLE_THREAD_MGR */
|
||||
|
||||
return exec_env;
|
||||
|
||||
Reference in New Issue
Block a user