Skip to content

Commit 788cbf2

Browse files
authored
Refine aot call_indirect opcode translation (#492)
Re-implement aot call_indirect opcode translation: when calling non-import function, translate it by LLVM call IR to call the function in AOTed code, so as to avoid calling runtime aot_call_indirect API which is much slower. For import function, keep calling aot_call_indirect API due to the possible pointer/string argument conversion. And add prompt info while app heap is corrupted, change emit_leb to emit_uint32 inter fast-interp to refine footprint. Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
1 parent f2a63d8 commit 788cbf2

15 files changed

Lines changed: 529 additions & 191 deletions

File tree

core/iwasm/aot/aot_runtime.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,17 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
13811381
}
13821382

13831383
if (!addr) {
1384-
aot_set_exception(module_inst, "out of memory");
1384+
if (memory_inst->heap_handle.ptr
1385+
&& mem_allocator_is_heap_corrupted(memory_inst->heap_handle.ptr)) {
1386+
LOG_ERROR("Error: app heap is corrupted, if the wasm file "
1387+
"is compiled by wasi-sdk-12.0 or larger version, "
1388+
"please add -Wl,--export=malloc -Wl,--export=free "
1389+
" to export malloc and free functions.");
1390+
aot_set_exception(module_inst, "app heap corrupted");
1391+
}
1392+
else {
1393+
aot_set_exception(module_inst, "out of memory");
1394+
}
13851395
return 0;
13861396
}
13871397
if (p_native_addr)
@@ -1804,7 +1814,6 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
18041814

18051815
bool
18061816
aot_call_indirect(WASMExecEnv *exec_env,
1807-
bool check_func_type, uint32 func_type_idx,
18081817
uint32 table_elem_idx,
18091818
uint32 argc, uint32 *argv)
18101819
{
@@ -1816,8 +1825,7 @@ aot_call_indirect(WASMExecEnv *exec_env,
18161825
AOTFuncType *func_type;
18171826
void **func_ptrs = (void**)module_inst->func_ptrs.ptr, *func_ptr;
18181827
uint32 table_size = module_inst->table_size;
1819-
uint32 func_idx, func_type_idx1;
1820-
uint32 ext_ret_count;
1828+
uint32 func_type_idx, func_idx, ext_ret_count;
18211829
AOTImportFunc *import_func;
18221830
const char *signature = NULL;
18231831
void *attachment = NULL;
@@ -1844,15 +1852,8 @@ aot_call_indirect(WASMExecEnv *exec_env,
18441852
return false;
18451853
}
18461854

1847-
func_type_idx1 = func_type_indexes[func_idx];
1848-
if (check_func_type
1849-
&& !aot_is_wasm_type_equal(module_inst, func_type_idx,
1850-
func_type_idx1)) {
1851-
aot_set_exception_with_id(module_inst,
1852-
EXCE_INVALID_FUNCTION_TYPE_INDEX);
1853-
return false;
1854-
}
1855-
func_type = aot_module->func_types[func_type_idx1];
1855+
func_type_idx = func_type_indexes[func_idx];
1856+
func_type = aot_module->func_types[func_type_idx];
18561857

18571858
if (!(func_ptr = func_ptrs[func_idx])) {
18581859
bh_assert(func_idx < aot_module->import_func_count);

core/iwasm/aot/aot_runtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
521521

522522
bool
523523
aot_call_indirect(WASMExecEnv *exec_env,
524-
bool check_func_type, uint32 func_type_idx,
525524
uint32 table_elem_idx,
526525
uint32 argc, uint32 *argv);
527526

core/iwasm/common/wasm_runtime_common.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,14 +3327,11 @@ wasm_runtime_call_indirect(WASMExecEnv *exec_env,
33273327

33283328
#if WASM_ENABLE_INTERP != 0
33293329
if (exec_env->module_inst->module_type == Wasm_Module_Bytecode)
3330-
return wasm_call_indirect(exec_env,
3331-
element_indices,
3332-
argc, argv);
3330+
return wasm_call_indirect(exec_env, element_indices, argc, argv);
33333331
#endif
33343332
#if WASM_ENABLE_AOT != 0
33353333
if (exec_env->module_inst->module_type == Wasm_Module_AoT)
3336-
return aot_call_indirect(exec_env, false, 0,
3337-
element_indices, argc, argv);
3334+
return aot_call_indirect(exec_env, element_indices, argc, argv);
33383335
#endif
33393336
return false;
33403337
}

0 commit comments

Comments
 (0)