-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[instantiation linking] Optimize aot func inst list #4018
base: dev/instantiate_linking
Are you sure you want to change the base?
[instantiation linking] Optimize aot func inst list #4018
Conversation
…pawned' for clarity in deinstantiation functions
…ecks and improving error handling
…nagement functions
…conv_wasm_c_api and call_conv_raw in WASM function structures
… for function instantiation
…pport and improve error logging
…pport and improve error handling
… support and improve clarity
…structure and improving function import handling
… support and clarity
…prove function instance lookup
core/iwasm/aot/aot_runtime.c
Outdated
WASM_IMPORT_EXPORT_KIND_FUNC, i); | ||
if (!extern_inst) { | ||
LOG_DEBUG("no import function(%s, %s) from imports list, might " | ||
"provied by wasm_native", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provided
const char *module_name = module->import_funcs[i].module_name; | ||
const char *field_name = module->import_funcs[i].func_name; | ||
LOG_WARNING("warning: failed to link import function (%s, %s)", | ||
module_name, field_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an intentional warning, it may be important to developer, could we keep it in the new code if link failed?
core/iwasm/aot/aot_runtime.c
Outdated
import_func->module_name, import_func->func_name); | ||
|
||
*func_ptrs = import_func->func_ptr_linked; | ||
bh_assert(*func_ptrs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my understanding, the import function doesn't have to be linked and runtime can print warning here, and during execution, the aot code or runtime throws exception "failed to call unlinked import function". The original behavior is like that, we had better not change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding that matter, I am inclined to align with the specification requirements, specifically Step #3 and Step #4. If I understand correctly, the linking error should be reported during the installation phase rather than at execution time.
Our current implementation deviates from this, and I intend to correct it.
In this PR, the wasm_runtime implementation is also incorrect and needs to be addressed. I plan to fix both issues in subsequent pull requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That brings convenience to developers and is a common handle in many VMs like jvm. In many cases the unlinked import function isn't called and developer can still call other functions. No developer reports it a problem, I strongly suggest to keep this. If you want to fix this, had better open another PR to let others to review/discuss and not fix it in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In many cases the unlinked import function isn't called and developer can still call other functions.
However, this does not align with the specification definition. I believed the purpose of creating the "instantiation linking" series of pull requests was to align with the specification requirements. Otherwise, our main branch code is functioning quite well.
core/iwasm/aot/aot_runtime.c
Outdated
extra->function_count = module->import_func_count + module->func_count; | ||
if (extra->function_count > 0) { | ||
extra->import_functions = | ||
functions_instantiate(module_inst, module, imports, import_count, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about renaming it to import_functions_instantiate
?
core/iwasm/common/wasm_extern_inst.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this file isn't needed, had better remove it?
core/iwasm/common/wasm_extern_inst.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
core/iwasm/common/wasm_c_api.c
Outdated
} | ||
|
||
*imports_dst = | ||
malloc_internal(sizeof(WASMExternInstance) * imports_src->num_elems); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about (uint64)sizeof(WASMExternInstance)
?
@@ -225,7 +238,7 @@ typedef struct AOTModule { | |||
|
|||
/* function info */ | |||
uint32 func_count; | |||
/* func pointers of AOTed (un-imported) functions */ | |||
/* func pointers of AOTed (imported + local) functions */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about also changing comment of L243?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func_type_indexes
still only stores local(un-imported) functions.
{ | ||
AOTFunctionInstance *function = runtime_malloc( | ||
sizeof(AOTFunctionInstance) + sizeof(AOTImportFunc), NULL, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little confused why need to plus sizeof(AOTImportFunc)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am considering that this would enable host APIs (defined in wasm_export.h) to create an AOTFunctionInstance
from scratch and pass it to the runtime for execution. The runtime would then use the u.func_import
field to retrieve some information. However, there might be room for optimization in subsequent pull requests.
wasm_create_function_empty(const WASMModule *module) | ||
{ | ||
WASMFunctionInstance *function = runtime_malloc( | ||
sizeof(WASMFunctionInstance) + sizeof(WASMFunctionImport), NULL, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to allocate extra memory (+ sizeof(WASMFunctionImport)
)?
core/iwasm/aot/aot_runtime.c
Outdated
import_func->module_name, import_func->func_name); | ||
|
||
*func_ptrs = import_func->func_ptr_linked; | ||
bh_assert(*func_ptrs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That brings convenience to developers and is a common handle in many VMs like jvm. In many cases the unlinked import function isn't called and developer can still call other functions. No developer reports it a problem, I strongly suggest to keep this. If you want to fix this, had better open another PR to let others to review/discuss and not fix it in this PR.
However, this does not align with the specification definition. I believed the purpose of creating the "instantiation linking" series of pull requests was to align with the specification requirements. Otherwise, our main branch code is functioning quite well. |
It reports the error during the execution time but not instantiation time, it doesn't strictly obey the spec. But sometimes the user experience is more important, in fact, we also do some special handlings in other places. I still think it is good to keep it, it also reports error and it is more friendly to developers. |
…nce memory allocation consistency
#3947 (comment)