Implement memory.grow and limit heap space base offset to 1G (#36)
* 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
This commit is contained in:
@ -52,6 +52,12 @@ int bh_memory_init_with_allocator(void *malloc_func, void *free_func);
|
||||
*/
|
||||
void bh_memory_destroy();
|
||||
|
||||
/**
|
||||
* Get the pool size of memory, if memory is initialized with allocator,
|
||||
* return 1GB by default.
|
||||
*/
|
||||
int bh_memory_pool_size();
|
||||
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING == 0
|
||||
|
||||
/**
|
||||
|
||||
@ -80,6 +80,15 @@
|
||||
#define WORKING_FLOW_HEAP_SIZE 0
|
||||
*/
|
||||
|
||||
/* Support memory.grow opcode and enlargeMemory function */
|
||||
#define WASM_ENABLE_MEMORY_GROW 1
|
||||
|
||||
/* The max percentage of global heap that app memory space can grow */
|
||||
#define APP_MEMORY_MAX_GLOBAL_HEAP_PERCENT 1 / 3
|
||||
|
||||
/* Default base offset of app heap space */
|
||||
#define DEFAULT_APP_HEAP_BASE_OFFSET (1 * BH_GB)
|
||||
|
||||
/* Default min/max heap size of each app */
|
||||
#define APP_HEAP_SIZE_DEFAULT (8 * 1024)
|
||||
#define APP_HEAP_SIZE_MIN (2 * 1024)
|
||||
|
||||
@ -49,7 +49,9 @@ static korp_mutex profile_lock;
|
||||
#ifndef MALLOC_MEMORY_FROM_SYSTEM
|
||||
|
||||
typedef enum Memory_Mode {
|
||||
MEMORY_MODE_UNKNOWN = 0, MEMORY_MODE_POOL, MEMORY_MODE_ALLOCATOR
|
||||
MEMORY_MODE_UNKNOWN = 0,
|
||||
MEMORY_MODE_POOL,
|
||||
MEMORY_MODE_ALLOCATOR
|
||||
} Memory_Mode;
|
||||
|
||||
static Memory_Mode memory_mode = MEMORY_MODE_UNKNOWN;
|
||||
@ -59,6 +61,8 @@ static mem_allocator_t pool_allocator = NULL;
|
||||
static void *(*malloc_func)(unsigned int size) = NULL;
|
||||
static void (*free_func)(void *ptr) = NULL;
|
||||
|
||||
static unsigned int global_pool_size;
|
||||
|
||||
int bh_memory_init_with_pool(void *mem, unsigned int bytes)
|
||||
{
|
||||
mem_allocator_t _allocator = mem_allocator_create(mem, bytes);
|
||||
@ -69,6 +73,7 @@ int bh_memory_init_with_pool(void *mem, unsigned int bytes)
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING != 0
|
||||
vm_mutex_init(&profile_lock);
|
||||
#endif
|
||||
global_pool_size = bytes;
|
||||
return 0;
|
||||
}
|
||||
printf("Init memory with pool (%p, %u) failed.\n", mem, bytes);
|
||||
@ -101,6 +106,14 @@ void bh_memory_destroy()
|
||||
memory_mode = MEMORY_MODE_UNKNOWN;
|
||||
}
|
||||
|
||||
int bh_memory_pool_size()
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_POOL)
|
||||
return global_pool_size;
|
||||
else
|
||||
return 1 * BH_GB;
|
||||
}
|
||||
|
||||
void* bh_malloc_internal(unsigned int size)
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_UNKNOWN) {
|
||||
|
||||
@ -75,7 +75,7 @@ static void *vm_thread_wrapper(void *arg)
|
||||
{
|
||||
thread_wrapper_arg * targ = arg;
|
||||
LOG_VERBOSE("THREAD CREATE 0x%08x\n", &targ);
|
||||
targ->stack = (void *) ((unsigned int) (&arg) & ~0xfff);
|
||||
targ->stack = (void *)((uintptr_t)(&arg) & ~0xfff);
|
||||
_vm_tls_put(1, targ);
|
||||
targ->start(targ->arg);
|
||||
bh_free(targ);
|
||||
|
||||
Reference in New Issue
Block a user