Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent * Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default * Add a new extension library: connection * Fix bug of reading magic number and version in big endian platform * Re-org platform APIs: move most platform APIs from iwasm to shared-lib * Enhance wasm loader to fix some security issues * Fix issue about illegal load of EXC_RETURN into PC on stm32 board * Updates that let a restricted version of the interpreter run in SGX * Enable native/app address validation and conversion for wasm app * Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused * Refine binary size and fix several minor issues Optimize interpreter LOAD/STORE opcodes to decrease the binary size Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper Add macros of global heap size, stack size, heap size for Zephyr main.c Clear compile warning of wasm_application.c * Add more strict security checks for libc wrapper API's * Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files * Enhance security of libc strcpy/sprintf wrapper function * Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions * Remove get_module_inst() and fix issue of call native * Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate * Refine interpreter call native process, refine memory boudary check * Fix issues of invokeNative function of arm/mips/general version * Add a switch to build simple sample without gui support * Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code * Re-org shared lib header files, remove unused info; fix compile issues of vxworks * Add build target general * Remove unused files * Update license header * test push * Restore file * Sync up with internal/feature * Sync up with internal/feature * Rename build_wamr_app to build_wasm_app * Fix small issues of README * Enhance malformed wasm file checking Fix issue of print hex int and implement utf8 string check Fix wasi file read/write right issue Fix minor issue of build wasm app doc * Sync up with internal/feature * Sync up with internal/feature: fix interpreter arm issue, fix read leb issue * Sync up with internal/feature * Fix bug of config.h and rename wasi config.h to ssp_config.h * Sync up with internal/feature * Import wamr aot * update document * update document * Update document, disable WASI in 32bit * update document * remove files * update document * Update document * update document * update document * update samples * Sync up with internal repo
This commit is contained in:
182
core/shared/mem-alloc/ems/ems_kfc.c
Normal file
182
core/shared/mem-alloc/ems/ems_kfc.c
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "ems_gc_internal.h"
|
||||
|
||||
|
||||
#define HEAP_INC_FACTOR 1
|
||||
|
||||
/* Check if current platform is compatible with current GC design*/
|
||||
|
||||
/* Return GC_ERROR if not;*/
|
||||
/* Return GC_SUCCESS otherwise.*/
|
||||
int gci_check_platform()
|
||||
{
|
||||
#define CHECK(x, y) do { \
|
||||
if((x) != (y)) { \
|
||||
bh_printf("Platform checking failed on LINE %d at FILE %s.",\
|
||||
__LINE__, __FILE__); \
|
||||
return GC_ERROR; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
CHECK(8, sizeof(gc_int64));
|
||||
CHECK(4, sizeof(gc_uint32));
|
||||
CHECK(4, sizeof(gc_int32));
|
||||
CHECK(2, sizeof(gc_uint16));
|
||||
CHECK(2, sizeof(gc_int16));
|
||||
CHECK(1, sizeof(gc_int8));
|
||||
CHECK(1, sizeof(gc_uint8));
|
||||
CHECK(4, sizeof(gc_size_t));
|
||||
/*CHECK(4, sizeof(void *));*/
|
||||
|
||||
return GC_SUCCESS;
|
||||
}
|
||||
|
||||
gc_handle_t gc_init_with_pool(char *buf, gc_size_t buf_size)
|
||||
{
|
||||
char *buf_end = buf + buf_size;
|
||||
char *buf_aligned = (char*) (((uintptr_t) buf + 7) & (uintptr_t)~7);
|
||||
char *base_addr = buf_aligned + sizeof(gc_heap_t);
|
||||
gc_heap_t *heap = (gc_heap_t*) buf_aligned;
|
||||
gc_size_t heap_max_size;
|
||||
hmu_normal_node_t *p = NULL;
|
||||
hmu_tree_node_t *root = NULL, *q = NULL;
|
||||
int i = 0, ret;
|
||||
|
||||
/* check system compatibility*/
|
||||
if (gci_check_platform() == GC_ERROR) {
|
||||
bh_printf("Check platform compatibility failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buf_size < 1024) {
|
||||
bh_printf("[GC_ERROR]heap_init_size(%d) < 1024", buf_size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
base_addr = (char*) (((uintptr_t) base_addr + 7) & (uintptr_t)~7) + GC_HEAD_PADDING;
|
||||
heap_max_size = (uint32)(buf_end - base_addr) & (uint32)~7;
|
||||
|
||||
memset(heap, 0, sizeof *heap);
|
||||
memset(base_addr, 0, heap_max_size);
|
||||
|
||||
ret = gct_vm_mutex_init(&heap->lock);
|
||||
if (ret != BHT_OK) {
|
||||
bh_printf("[GC_ERROR]failed to init lock ");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef BH_FOOTPRINT
|
||||
bh_printf("\nINIT HEAP 0x%08x %d\n", base_addr, heap_max_size);
|
||||
#endif
|
||||
|
||||
/* init all data structures*/
|
||||
heap->max_size = heap_max_size;
|
||||
heap->current_size = heap_max_size;
|
||||
heap->base_addr = (gc_uint8*) base_addr;
|
||||
heap->heap_id = (gc_handle_t) heap;
|
||||
|
||||
#if GC_STAT_DATA != 0
|
||||
heap->total_free_size = heap->current_size;
|
||||
heap->highmark_size = 0;
|
||||
heap->total_gc_count = 0;
|
||||
heap->total_gc_time = 0;
|
||||
heap->gc_threshold_factor = GC_DEFAULT_THRESHOLD_FACTOR;
|
||||
gc_update_threshold(heap);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < HMU_NORMAL_NODE_CNT; i++) {
|
||||
/* make normal node look like a FC*/
|
||||
p = &heap->kfc_normal_list[i];
|
||||
memset(p, 0, sizeof *p);
|
||||
hmu_set_ut(&p->hmu_header, HMU_FC);
|
||||
hmu_set_size(&p->hmu_header, sizeof *p);
|
||||
}
|
||||
|
||||
root = &heap->kfc_tree_root;
|
||||
memset(root, 0, sizeof *root);
|
||||
root->size = sizeof *root;
|
||||
hmu_set_ut(&root->hmu_header, HMU_FC);
|
||||
hmu_set_size(&root->hmu_header, sizeof *root);
|
||||
|
||||
q = (hmu_tree_node_t *) heap->base_addr;
|
||||
memset(q, 0, sizeof *q);
|
||||
hmu_set_ut(&q->hmu_header, HMU_FC);
|
||||
hmu_set_size(&q->hmu_header, heap->current_size);
|
||||
|
||||
hmu_mark_pinuse(&q->hmu_header);
|
||||
root->right = q;
|
||||
q->parent = root;
|
||||
q->size = heap->current_size;
|
||||
|
||||
bh_assert(
|
||||
root->size <= HMU_FC_NORMAL_MAX_SIZE
|
||||
&& HMU_FC_NORMAL_MAX_SIZE < q->size); /*@NOTIFY*/
|
||||
|
||||
#if BH_ENABLE_MEMORY_PROFILING != 0
|
||||
bh_printf("heap is successfully initialized with max_size=%u.",
|
||||
heap_max_size);
|
||||
#endif
|
||||
return heap;
|
||||
}
|
||||
|
||||
int gc_destroy_with_pool(gc_handle_t handle)
|
||||
{
|
||||
gc_heap_t *heap = (gc_heap_t *) handle;
|
||||
gct_vm_mutex_destroy(&heap->lock);
|
||||
memset(heap->base_addr, 0, heap->max_size);
|
||||
memset(heap, 0, sizeof(gc_heap_t));
|
||||
return GC_SUCCESS;
|
||||
}
|
||||
|
||||
#if defined(GC_VERIFY)
|
||||
/* Verify heap integrity*/
|
||||
/* @heap should not be NULL and it should be a valid heap*/
|
||||
void gci_verify_heap(gc_heap_t *heap)
|
||||
{
|
||||
hmu_t *cur = NULL, *end = NULL;
|
||||
|
||||
bh_assert(heap && gci_is_heap_valid(heap));
|
||||
cur = (hmu_t *)heap->base_addr;
|
||||
end = (hmu_t *)(heap->base_addr + heap->current_size);
|
||||
while(cur < end)
|
||||
{
|
||||
hmu_verify(cur);
|
||||
cur = (hmu_t *)((gc_uint8*)cur + hmu_get_size(cur));
|
||||
}
|
||||
bh_assert(cur == end);
|
||||
}
|
||||
#endif
|
||||
|
||||
void* gc_heap_stats(void *heap_arg, uint32* stats, int size, gc_mm_t mmt)
|
||||
{
|
||||
(void) mmt;
|
||||
int i;
|
||||
gc_heap_t *heap = (gc_heap_t *) heap_arg;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
switch (i) {
|
||||
case GC_STAT_TOTAL:
|
||||
stats[i] = heap->current_size;
|
||||
break;
|
||||
case GC_STAT_FREE:
|
||||
stats[i] = heap->total_free_size;
|
||||
break;
|
||||
case GC_STAT_HIGHMARK:
|
||||
stats[i] = heap->highmark_size;
|
||||
break;
|
||||
case GC_STAT_COUNT:
|
||||
stats[i] = heap->total_gc_count;
|
||||
break;
|
||||
case GC_STAT_TIME:
|
||||
stats[i] = (uint32)heap->total_gc_time;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return heap;
|
||||
}
|
||||
Reference in New Issue
Block a user