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:
wenyongh
2019-05-31 01:21:39 -05:00
committed by GitHub
parent ff7cbdd2fb
commit 504268b297
11 changed files with 237 additions and 140 deletions

View File

@ -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) {