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:
Wenyong Huang
2024-02-06 20:47:11 +08:00
committed by GitHub
parent 5931aaacbe
commit 16a4d71b34
98 changed files with 33469 additions and 3159 deletions

View File

@ -4,6 +4,7 @@
*/
#include "mem_alloc.h"
#include <stdbool.h>
#if DEFAULT_MEM_ALLOCATOR == MEM_ALLOCATOR_EMS
@ -56,6 +57,43 @@ mem_allocator_free(mem_allocator_t allocator, void *ptr)
gc_free_vo((gc_handle_t)allocator, ptr);
}
#if WASM_ENABLE_GC != 0
void *
mem_allocator_malloc_with_gc(mem_allocator_t allocator, uint32_t size)
{
return gc_alloc_wo((gc_handle_t)allocator, size);
}
#if WASM_GC_MANUALLY != 0
void
mem_allocator_free_with_gc(mem_allocator_t allocator, void *ptr)
{
if (ptr)
gc_free_wo((gc_handle_t)allocator, ptr);
}
#endif
#if WASM_ENABLE_THREAD_MGR == 0
void
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *exec_env)
{
return gc_enable_gc_reclaim((gc_handle_t)allocator, exec_env);
}
#else
void
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *cluster)
{
return gc_enable_gc_reclaim((gc_handle_t)allocator, cluster);
}
#endif
int
mem_allocator_add_root(mem_allocator_t allocator, WASMObjectRef obj)
{
return gc_add_root((gc_handle_t)allocator, (gc_object_t)obj);
}
#endif
int
mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
uint32 pool_buf_size)
@ -76,6 +114,30 @@ mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info)
return true;
}
#if WASM_ENABLE_GC != 0
bool
mem_allocator_set_gc_finalizer(mem_allocator_t allocator, void *obj,
gc_finalizer_t cb, void *data)
{
return gc_set_finalizer((gc_handle_t)allocator, (gc_object_t)obj, cb, data);
}
void
mem_allocator_unset_gc_finalizer(mem_allocator_t allocator, void *obj)
{
gc_unset_finalizer((gc_handle_t)allocator, (gc_object_t)obj);
}
#if WASM_ENABLE_GC_PERF_PROFILING != 0
void
mem_allocator_dump_perf_profiling(mem_allocator_t allocator)
{
gc_dump_perf_profiling((gc_handle_t)allocator);
}
#endif
#endif
#else /* else of DEFAULT_MEM_ALLOCATOR */
#include "tlsf/tlsf.h"