From 3af6dd0a49aad6b0acbda0bcb6940cd2e5caa3bf Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Wed, 1 Dec 2021 16:24:09 +0800 Subject: [PATCH 1/6] Don't throw exception while malloc failed --- core/iwasm/aot/aot_runtime.c | 2 +- core/iwasm/interpreter/wasm_runtime.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index b97e952832..125f509dc0 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1774,7 +1774,7 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size, aot_set_exception(module_inst, "app heap corrupted"); } else { - aot_set_exception(module_inst, "out of memory"); + LOG_ERROR("alloc %d bytes memory failed", size); } return 0; } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 14a4286490..28490f1893 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1830,7 +1830,7 @@ wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size, wasm_set_exception(module_inst, "app heap corrupted"); } else { - wasm_set_exception(module_inst, "out of memory"); + LOG_ERROR("alloc %d bytes memory failed", size); } return 0; } From cec9a89ea4c5afa4f269031e0bd2fde72551c38b Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Wed, 1 Dec 2021 18:20:17 +0800 Subject: [PATCH 2/6] Optimize log output for hash_map_find In acquire_wait_info the key of hasn_map_find can be NULL thus there are many sesenless error log --- core/shared/utils/bh_hashmap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/shared/utils/bh_hashmap.c b/core/shared/utils/bh_hashmap.c index 70119c7709..5cb33a8423 100644 --- a/core/shared/utils/bh_hashmap.c +++ b/core/shared/utils/bh_hashmap.c @@ -127,8 +127,13 @@ bh_hash_map_find(HashMap *map, void *key) HashMapElem *elem; void *value; - if (!map || !key) { - LOG_ERROR("HashMap find elem failed: map or key is NULL.\n"); + if (!map) { + LOG_ERROR("HashMap find elem failed: map is NULL.\n"); + return NULL; + } + + if (!key) { + LOG_VERBOSE("HashMap find elem failed: key is NULL.\n"); return NULL; } From 559803d7d7672b8e63fa9444446c1643ed8f59c7 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Fri, 3 Dec 2021 09:40:57 +0800 Subject: [PATCH 3/6] Change log level --- core/iwasm/aot/aot_runtime.c | 2 +- core/iwasm/interpreter/wasm_runtime.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 125f509dc0..7c83cf998d 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1774,7 +1774,7 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size, aot_set_exception(module_inst, "app heap corrupted"); } else { - LOG_ERROR("alloc %d bytes memory failed", size); + LOG_WARNING("alloc %d bytes memory failed", size); } return 0; } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 28490f1893..32b8d58817 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1830,7 +1830,7 @@ wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size, wasm_set_exception(module_inst, "app heap corrupted"); } else { - LOG_ERROR("alloc %d bytes memory failed", size); + LOG_WARNING("alloc %d bytes memory failed", size); } return 0; } From 939c1e5826b08bb3de8ba5f09ebda4c5d5d64dfb Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Fri, 3 Dec 2021 11:30:22 +0800 Subject: [PATCH 4/6] Don't call bh_hash_map_find while address == NULL --- core/iwasm/common/wasm_shared_memory.c | 3 ++- core/shared/utils/bh_hashmap.c | 9 ++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/iwasm/common/wasm_shared_memory.c b/core/iwasm/common/wasm_shared_memory.c index 65c98d4ef3..6fc9bf2073 100644 --- a/core/iwasm/common/wasm_shared_memory.c +++ b/core/iwasm/common/wasm_shared_memory.c @@ -224,7 +224,8 @@ acquire_wait_info(void *address, bool create) AtomicWaitInfo *wait_info = NULL; bh_list_status ret; - wait_info = (AtomicWaitInfo *)bh_hash_map_find(wait_map, address); + if (address) + wait_info = (AtomicWaitInfo *)bh_hash_map_find(wait_map, address); if (!create) return wait_info; diff --git a/core/shared/utils/bh_hashmap.c b/core/shared/utils/bh_hashmap.c index 5cb33a8423..70119c7709 100644 --- a/core/shared/utils/bh_hashmap.c +++ b/core/shared/utils/bh_hashmap.c @@ -127,13 +127,8 @@ bh_hash_map_find(HashMap *map, void *key) HashMapElem *elem; void *value; - if (!map) { - LOG_ERROR("HashMap find elem failed: map is NULL.\n"); - return NULL; - } - - if (!key) { - LOG_VERBOSE("HashMap find elem failed: key is NULL.\n"); + if (!map || !key) { + LOG_ERROR("HashMap find elem failed: map or key is NULL.\n"); return NULL; } From 5d9da8d61e152b88578f03ce11a1e459f1b0ceee Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 3 Dec 2021 15:28:01 +0800 Subject: [PATCH 5/6] Update aot_runtime.c --- core/iwasm/aot/aot_runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 7c83cf998d..c769a527e1 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1774,7 +1774,7 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size, aot_set_exception(module_inst, "app heap corrupted"); } else { - LOG_WARNING("alloc %d bytes memory failed", size); + LOG_WARNING("warning: allocate %u bytes memory failed", size); } return 0; } From ede91133ab05592df4605d5ed6ae055d6a77d501 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 3 Dec 2021 15:29:03 +0800 Subject: [PATCH 6/6] Update wasm_runtime.c --- core/iwasm/interpreter/wasm_runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 32b8d58817..76b4184b17 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1830,7 +1830,7 @@ wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size, wasm_set_exception(module_inst, "app heap corrupted"); } else { - LOG_WARNING("alloc %d bytes memory failed", size); + LOG_WARNING("warning: allocate %u bytes memory failed", size); } return 0; }