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

@ -39,7 +39,12 @@ extern const char *aot_stack_sizes_alias_name;
extern const char *aot_stack_sizes_section_name;
typedef InitializerExpression AOTInitExpr;
typedef WASMType AOTFuncType;
typedef WASMType AOTType;
typedef WASMFuncType AOTFuncType;
#if WASM_ENABLE_GC != 0
typedef WASMStructType AOTStructType;
typedef WASMArrayType AOTArrayType;
#endif
typedef WASMExport AOTExport;
#if WASM_ENABLE_DEBUG_AOT != 0
@ -117,22 +122,30 @@ typedef struct AOTMemInitData {
typedef struct AOTImportTable {
char *module_name;
char *table_name;
uint32 elem_type;
uint32 table_flags;
uint8 elem_type;
uint8 table_flags;
bool possible_grow;
uint32 table_init_size;
uint32 table_max_size;
bool possible_grow;
#if WASM_ENABLE_GC != 0
WASMRefType *elem_ref_type;
#endif
} AOTImportTable;
/**
* Table
*/
typedef struct AOTTable {
uint32 elem_type;
uint32 table_flags;
uint8 elem_type;
uint8 table_flags;
bool possible_grow;
uint32 table_init_size;
uint32 table_max_size;
bool possible_grow;
#if WASM_ENABLE_GC != 0
WASMRefType *elem_ref_type;
/* init expr for the whole table */
InitializerExpression init_expr;
#endif
} AOTTable;
/**
@ -143,14 +156,17 @@ typedef struct AOTTableInitData {
uint32 mode;
/* funcref or externref, elemkind will be considered as funcref */
uint32 elem_type;
#if WASM_ENABLE_GC != 0
WASMRefType *elem_ref_type;
#endif
/* optional, only for active */
uint32 table_index;
/* Start address of init data */
AOTInitExpr offset;
/* Function index count */
uint32 func_index_count;
uint32 value_count;
/* Function index array */
uint32 func_indexes[1];
InitializerExpression init_values[1];
} AOTTableInitData;
/**
@ -165,6 +181,19 @@ typedef struct AOTImportGlobal {
uint32 size;
/* The data offset of current global in global data */
uint32 data_offset;
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
/*
* The data size and data offset of a wasm global may vary
* in 32-bit target and 64-bit target, e.g., the size of a
* GC obj is 4 bytes in the former and 8 bytes in the
* latter, the AOT compiler needs to use the correct data
* offset according to the target info.
*/
uint32 size_64bit;
uint32 size_32bit;
uint32 data_offset_64bit;
uint32 data_offset_32bit;
#endif
/* global data after linked */
WASMValue global_data_linked;
bool is_linked;
@ -180,6 +209,13 @@ typedef struct AOTGlobal {
uint32 size;
/* The data offset of current global in global data */
uint32 data_offset;
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
/* See comments in AOTImportGlobal */
uint32 size_64bit;
uint32 size_32bit;
uint32 data_offset_64bit;
uint32 data_offset_32bit;
#endif
AOTInitExpr init_expr;
} AOTGlobal;
@ -209,11 +245,15 @@ typedef struct AOTFunc {
AOTFuncType *func_type;
uint32 func_type_index;
uint32 local_count;
uint8 *local_types;
uint8 *local_types_wp;
uint16 param_cell_num;
uint16 local_cell_num;
uint32 max_stack_cell_num;
uint32 code_size;
uint8 *code;
/* offset of each local, including function parameters
and local variables */
uint16 *local_offsets;
} AOTFunc;
typedef struct AOTCompData {
@ -250,8 +290,8 @@ typedef struct AOTCompData {
AOTGlobal *globals;
/* Function types */
uint32 func_type_count;
AOTFuncType **func_types;
uint32 type_count;
AOTType **types;
/* Import functions */
uint32 import_func_count;
@ -267,7 +307,8 @@ typedef struct AOTCompData {
uint8 *aot_name_section_buf;
uint32 aot_name_section_size;
uint32 global_data_size;
uint32 global_data_size_64bit;
uint32 global_data_size_32bit;
uint32 start_func_index;
uint32 malloc_func_index;
@ -282,6 +323,12 @@ typedef struct AOTCompData {
uint32 aux_stack_bottom;
uint32 aux_stack_size;
#if WASM_ENABLE_STRINGREF != 0
uint32 string_literal_count;
uint32 *string_literal_lengths_wp;
const uint8 **string_literal_ptrs_wp;
#endif
WASMModule *wasm_module;
#if WASM_ENABLE_DEBUG_AOT != 0
dwarf_extractor_handle_t extractor;
@ -295,7 +342,8 @@ typedef struct AOTNativeSymbol {
} AOTNativeSymbol;
AOTCompData *
aot_create_comp_data(WASMModule *module);
aot_create_comp_data(WASMModule *module, const char *target_arch,
bool gc_enabled);
void
aot_destroy_comp_data(AOTCompData *comp_data);