Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ samples/workload/include/**

tests/unit/runtime-common/wasm-apps/main.aot
tests/unit/aot-stack-frame/wasm-apps/test_aot.h
.worktrees/
20 changes: 20 additions & 0 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ memories_deinstantiate(AOTModuleInstance *module_inst)
}
}
wasm_runtime_free(module_inst->memories);
module_inst->memories = NULL;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth setting NULL here? Given the fact that the module instance will be destroyed later anyway?

}

static AOTMemoryInstance *
Expand Down Expand Up @@ -3795,13 +3796,32 @@ aot_get_module_mem_consumption(const AOTModule *module,
mem_conspn->total_size += mem_conspn->aot_code_size;
}

/**
* Calculate memory consumption of an AOT module instance.
*
* @param module_inst pointer to a fully initialized AOT module instance
* @param mem_conspn output structure to store memory consumption details
*
* @pre module_inst != NULL
* @pre module_inst->module != NULL
* @pre module_inst->e != NULL
* @pre (module_inst->memory_count == 0) || (module_inst->memories != NULL)
*
* In debug builds, these preconditions are validated with bh_assert.
* In release builds, violating preconditions results in undefined behavior.
*/
void
aot_get_module_inst_mem_consumption(const AOTModuleInstance *module_inst,
WASMModuleInstMemConsumption *mem_conspn)
{
AOTTableInstance *tbl_inst;
uint32 i;

bh_assert(module_inst);
bh_assert(module_inst->module);
bh_assert(module_inst->e);
bh_assert(!module_inst->memory_count || module_inst->memories);

memset(mem_conspn, 0, sizeof(*mem_conspn));

mem_conspn->module_inst_struct_size = sizeof(AOTModuleInstance);
Expand Down
23 changes: 22 additions & 1 deletion core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -3445,9 +3445,11 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
(WASMModuleInstanceCommon *)module_inst);
#endif

if (module_inst->memory_count > 0)
if (module_inst->memory_count > 0) {
memories_deinstantiate(module_inst, module_inst->memories,
module_inst->memory_count);
module_inst->memories = NULL;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth setting NULL here? Given the fact that this module inst is about to be destroyed anyway? It will create an inconsistency with other data members, like L3455

}

if (module_inst->import_func_ptrs) {
wasm_runtime_free(module_inst->import_func_ptrs);
Expand Down Expand Up @@ -4227,13 +4229,32 @@ wasm_get_module_mem_consumption(const WASMModule *module,
mem_conspn->total_size += mem_conspn->const_strs_size;
}

/**
* Calculate memory consumption of a WASM module instance.
*
* @param module_inst pointer to a fully initialized WASM module instance
* @param mem_conspn output structure to store memory consumption details
*
* @pre module_inst != NULL
* @pre module_inst->module != NULL
* @pre module_inst->e != NULL
* @pre (module_inst->memory_count == 0) || (module_inst->memories != NULL)
*
* In debug builds, these preconditions are validated with bh_assert.
* In release builds, violating preconditions results in undefined behavior.
*/
void
wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst,
WASMModuleInstMemConsumption *mem_conspn)
{
uint32 i;
uint64 size;

bh_assert(module_inst);
bh_assert(module_inst->module);
bh_assert(module_inst->e);
bh_assert(!module_inst->memory_count || module_inst->memories);

memset(mem_conspn, 0, sizeof(*mem_conspn));

mem_conspn->module_inst_struct_size = (uint8 *)module_inst->e
Expand Down
Loading