enable pthread for AoT && update AOT current version to 2 (#311)

This commit is contained in:
Xu Jun
2020-07-16 20:35:04 +08:00
committed by GitHub
parent ca938f3634
commit 32b2943369
32 changed files with 1549 additions and 584 deletions

View File

@ -933,8 +933,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
#if WASM_ENABLE_THREAD_MGR != 0
#define CHECK_SUSPEND_FLAGS() do { \
if (exec_env->suspend_flags != 0) { \
if (exec_env->suspend_flags & 0x01) { \
if (exec_env->suspend_flags.flags != 0) { \
if (exec_env->suspend_flags.flags & 0x01) { \
/* terminate current thread */ \
return; \
} \

View File

@ -979,8 +979,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
#if WASM_ENABLE_THREAD_MGR != 0
#define CHECK_SUSPEND_FLAGS() do { \
if (exec_env->suspend_flags != 0) { \
if (exec_env->suspend_flags & 0x01) { \
if (exec_env->suspend_flags.flags != 0) { \
if (exec_env->suspend_flags.flags & 0x01) { \
/* terminate current thread */ \
return; \
} \

View File

@ -2538,10 +2538,10 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& global->is_mutable
&& global->init_expr.init_expr_type ==
INIT_EXPR_TYPE_I32_CONST
&& (global->init_expr.u.i32 ==
&& (global->init_expr.u.i32 <=
llvm_heap_base_global->init_expr.u.i32
|| global->init_expr.u.i32 ==
llvm_data_end_global->init_expr.u.i32)) {
&& llvm_data_end_global->init_expr.u.i32 <=
llvm_heap_base_global->init_expr.u.i32)) {
llvm_stack_top_global = global;
llvm_stack_top = global->init_expr.u.i32;
stack_top_global_index = global_index;
@ -2592,7 +2592,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
if (module->memory_count) {
memory = &module->memories[0];
init_memory_size = (uint64)memory->num_bytes_per_page *
memory->init_page_count;
memory->init_page_count;
if (llvm_heap_base <= init_memory_size
&& llvm_data_end <= init_memory_size) {
/* Reset memory info to decrease memory usage */

View File

@ -1440,8 +1440,6 @@ load_from_sections(WASMModule *module, WASMSection *sections,
WASMGlobal *llvm_stack_top_global = NULL, *global;
uint32 llvm_data_end = UINT32_MAX, llvm_heap_base = UINT32_MAX;
uint32 llvm_stack_top = UINT32_MAX, global_index, i;
uint32 data_end_global_index = UINT32_MAX;
uint32 heap_base_global_index = UINT32_MAX;
uint32 stack_top_global_index = UINT32_MAX;
BlockAddr *block_addr_cache;
uint64 total_size;
@ -1563,7 +1561,6 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& !global->is_mutable
&& global->init_expr.init_expr_type ==
INIT_EXPR_TYPE_I32_CONST) {
heap_base_global_index = global_index;
llvm_heap_base_global = global;
llvm_heap_base = global->init_expr.u.i32;
LOG_VERBOSE("found llvm __heap_base global, value: %d\n",
@ -1577,7 +1574,6 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& !global->is_mutable
&& global->init_expr.init_expr_type ==
INIT_EXPR_TYPE_I32_CONST) {
data_end_global_index = global_index;
llvm_data_end_global = global;
llvm_data_end = global->init_expr.u.i32;
LOG_VERBOSE("found llvm __data_end global, value: %d\n",
@ -1588,26 +1584,29 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}
if (llvm_data_end_global && llvm_heap_base_global) {
if ((data_end_global_index == heap_base_global_index + 1
&& (int32)data_end_global_index > 1)
|| (heap_base_global_index == data_end_global_index + 1
&& (int32)heap_base_global_index > 1)) {
global_index =
data_end_global_index < heap_base_global_index
? data_end_global_index - 1 : heap_base_global_index - 1;
/* Resolve aux stack top global */
for (global_index = 0; global_index < module->global_count; global_index++) {
global = module->globals + global_index;
if (global->type == VALUE_TYPE_I32
if (global != llvm_data_end_global
&& global != llvm_heap_base_global
&& global->type == VALUE_TYPE_I32
&& global->is_mutable
&& global->init_expr.init_expr_type ==
INIT_EXPR_TYPE_I32_CONST) {
INIT_EXPR_TYPE_I32_CONST
&& (global->init_expr.u.i32 <=
llvm_heap_base_global->init_expr.u.i32
&& llvm_data_end_global->init_expr.u.i32 <=
llvm_heap_base_global->init_expr.u.i32)) {
llvm_stack_top_global = global;
llvm_stack_top = global->init_expr.u.i32;
stack_top_global_index = global_index;
LOG_VERBOSE("found llvm stack top global, "
"value: %d, global index: %d\n",
llvm_stack_top, global_index);
break;
}
}
module->llvm_aux_data_end = llvm_data_end;
module->llvm_aux_stack_bottom = llvm_stack_top;
module->llvm_aux_stack_size = llvm_stack_top > llvm_data_end

View File

@ -142,7 +142,7 @@ memory_instantiate(WASMModuleInstance *module_inst,
ref_count = shared_memory_inc_reference(
(WASMModuleCommon *)module_inst->module);
bh_assert(ref_count > 0);
memory = shared_memory_get_memory_inst(node);
memory = (WASMMemoryInstance *)shared_memory_get_memory_inst(node);
bh_assert(memory);
(void)ref_count;
@ -160,6 +160,7 @@ memory_instantiate(WASMModuleInstance *module_inst,
return NULL;
}
memory->module_type = Wasm_Module_Bytecode;
memory->num_bytes_per_page = num_bytes_per_page;
memory->cur_page_count = init_page_count;
memory->max_page_count = max_page_count;
@ -194,7 +195,8 @@ memory_instantiate(WASMModuleInstance *module_inst,
if (is_shared_memory) {
memory->is_shared = true;
if (!shared_memory_set_memory_inst(
(WASMModuleCommon *)module_inst->module, memory)) {
(WASMModuleCommon *)module_inst->module,
(WASMMemoryInstanceCommon *)memory)) {
set_error_buf(error_buf, error_buf_size,
"Instantiate memory failed:"
"allocate memory failed.");
@ -1765,7 +1767,7 @@ wasm_set_aux_stack(WASMExecEnv *exec_env,
|| ((!is_stack_before_data) && (start_offset - data_end < size)))
return false;
if (stack_bottom) {
if ((stack_bottom != (uint32)-1) && (stack_top_idx != (uint32)-1)) {
/* The aux stack top is a wasm global,
set the initial value for the global */
uint8 *global_addr =

View File

@ -22,10 +22,10 @@ typedef struct WASMTableInstance WASMTableInstance;
typedef struct WASMGlobalInstance WASMGlobalInstance;
typedef struct WASMMemoryInstance {
#if WASM_ENABLE_SHARED_MEMORY != 0
/* shared memory flag */
/* Module type */
uint32 module_type;
/* Shared memory flag */
bool is_shared;
#endif
/* Number bytes per page */
uint32 num_bytes_per_page;
/* Current page count */