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

@ -0,0 +1,121 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _STRING_OBJECT_H_
#define _STRING_OBJECT_H_
#include "wasm.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum EncodingFlag {
UTF8,
WTF8,
WTF16,
LOSSY_UTF8,
} EncodingFlag;
typedef enum StringViewType {
STRING_VIEW_WTF8,
STRING_VIEW_WTF16,
STRING_VIEW_ITER,
} StringViewType;
typedef enum ErrorCode {
Insufficient_Space = -3,
Encode_Fail = -2,
Isolated_Surrogate = -1,
} ErrorCode;
/******************* gc finalizer *****************/
void
wasm_string_destroy(WASMString str_obj);
/******************* opcode functions *****************/
/* string.const */
WASMString
wasm_string_new_const(const char *content, uint32 length);
/* string.new_xx8/new_wtf16 */
/* string.new_xx8_array */
/* string.new_wtf16_array */
WASMString
wasm_string_new_with_encoding(void *addr, uint32 count, EncodingFlag flag);
/* string.measure */
int32
wasm_string_measure(WASMString str_obj, EncodingFlag flag);
/* stringview_wtf16.length */
int32
wasm_string_wtf16_get_length(WASMString str_obj);
/* string.encode_xx8 */
/* string.encode_wtf16 */
/* stringview_wtf8.encode_xx */
/* stringview_wtf16.encode */
/* string.encode_xx8_array */
/* string.encode_wtf16_array */
int32
wasm_string_encode(WASMString str_obj, uint32 pos, uint32 count, void *addr,
uint32 *next_pos, EncodingFlag flag);
/* string.concat */
WASMString
wasm_string_concat(WASMString str_obj1, WASMString str_obj2);
/* string.eq */
int32
wasm_string_eq(WASMString str_obj1, WASMString str_obj2);
/* string.is_usv_sequence */
int32
wasm_string_is_usv_sequence(WASMString str_obj);
/* string.as_wtf8 */
/* string.as_wtf16 */
/* string.as_iter */
WASMString
wasm_string_create_view(WASMString str_obj, StringViewType type);
/* stringview_wtf8.advance */
/* stringview_iter.advance */
int32
wasm_string_advance(WASMString str_obj, uint32 pos, uint32 count,
uint32 *target_pos);
/* stringview_wtf8.slice */
/* stringview_wtf16.slice */
/* stringview_iter.slice */
WASMString
wasm_string_slice(WASMString str_obj, uint32 start, uint32 end,
StringViewType type);
/* stringview_wtf16.get_codeunit */
int16
wasm_string_get_wtf16_codeunit(WASMString str_obj, int32 pos);
/* stringview_iter.next */
uint32
wasm_string_next_codepoint(WASMString str_obj, uint32 pos);
/* stringview_iter.rewind */
uint32
wasm_string_rewind(WASMString str_obj, uint32 pos, uint32 count,
uint32 *target_pos);
/******************* application functions *****************/
void
wasm_string_dump(WASMString str_obj);
#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif /* end of _STRING_OBJECT_H_ */

View File

@ -0,0 +1,136 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
/* This file is the stub for stringref implementation, only used for wamrc
* compiler. The runtime embedder SHOULD NOT use this file */
#include "string_object.h"
/******************* gc finalizer *****************/
void
wasm_string_destroy(WASMString str_obj)
{}
/******************* opcode functions *****************/
/* string.const */
WASMString
wasm_string_new_const(const char *str, uint32 length)
{
return NULL;
}
/* string.new_xx8 */
/* string.new_wtf16 */
/* string.new_xx8_array */
/* string.new_wtf16_array */
WASMString
wasm_string_new_with_encoding(void *addr, uint32 count, EncodingFlag flag)
{
return NULL;
}
/* string.measure */
/* stringview_wtf16.length */
int32
wasm_string_measure(WASMString str_obj, EncodingFlag flag)
{
return 0;
}
/* stringview_wtf16.length */
int32
wasm_string_wtf16_get_length(WASMString str_obj)
{
return 0;
}
/* string.encode_xx8 */
/* string.encode_wtf16 */
/* stringview_wtf8.encode_xx */
/* stringview_wtf16.encode */
/* string.encode_xx8_array */
/* string.encode_wtf16_array */
int32
wasm_string_encode(WASMString str_obj, uint32 pos, uint32 count, void *addr,
uint32 *next_pos, EncodingFlag flag)
{
return 0;
}
/* string.concat */
WASMString
wasm_string_concat(WASMString str_obj1, WASMString str_obj2)
{
return NULL;
}
/* string.eq */
int32
wasm_string_eq(WASMString str_obj1, WASMString str_obj2)
{
return 0;
}
/* string.is_usv_sequence */
int32
wasm_string_is_usv_sequence(WASMString str_obj)
{
return 0;
}
/* string.as_wtf8 */
/* string.as_wtf16 */
/* string.as_iter */
WASMString
wasm_string_create_view(WASMString str_obj, StringViewType type)
{
return NULL;
}
/* stringview_wtf8.advance */
/* stringview_iter.advance */
int32
wasm_string_advance(WASMString str_obj, uint32 pos, uint32 count,
uint32 *consumed)
{
return 0;
}
/* stringview_wtf8.slice */
/* stringview_wtf16.slice */
/* stringview_iter.slice */
WASMString
wasm_string_slice(WASMString str_obj, uint32 start, uint32 end,
StringViewType type)
{
return NULL;
}
/* stringview_wtf16.get_codeunit */
int16
wasm_string_get_wtf16_codeunit(WASMString str_obj, int32 pos)
{
return 0;
}
/* stringview_iter.next */
uint32
wasm_string_next_codepoint(WASMString str_obj, uint32 pos)
{
return 0;
}
/* stringview_iter.rewind */
uint32
wasm_string_rewind(WASMString str_obj, uint32 pos, uint32 count,
uint32 *consumed)
{
return 0;
}
void
wasm_string_dump(WASMString str_obj)
{}