Apply clang-format for core/shared and product-mini files (#785)
Apply clang-format for core/shared and product-mini files
This commit is contained in:
@ -5,15 +5,11 @@
|
||||
|
||||
#include "ems_gc_internal.h"
|
||||
|
||||
|
||||
static inline bool
|
||||
hmu_is_in_heap(void *hmu,
|
||||
gc_uint8 *heap_base_addr,
|
||||
gc_uint8 *heap_end_addr)
|
||||
hmu_is_in_heap(void *hmu, gc_uint8 *heap_base_addr, gc_uint8 *heap_end_addr)
|
||||
{
|
||||
gc_uint8 *addr = (gc_uint8 *)hmu;
|
||||
return (addr >= heap_base_addr && addr < heap_end_addr)
|
||||
? true : false;
|
||||
return (addr >= heap_base_addr && addr < heap_end_addr) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,8 +34,7 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
|
||||
parent = p->parent;
|
||||
if (!parent || p == root /* p can not be the ROOT node */
|
||||
|| !hmu_is_in_heap(p, base_addr, end_addr)
|
||||
|| (parent != root
|
||||
&& !hmu_is_in_heap(parent, base_addr, end_addr))) {
|
||||
|| (parent != root && !hmu_is_in_heap(parent, base_addr, end_addr))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -139,8 +134,8 @@ unlink_hmu(gc_heap_t *heap, hmu_t *hmu)
|
||||
gc_size_t size;
|
||||
|
||||
bh_assert(gci_is_heap_valid(heap));
|
||||
bh_assert(hmu && (gc_uint8*) hmu >= heap->base_addr
|
||||
&& (gc_uint8*) hmu < heap->base_addr + heap->current_size);
|
||||
bh_assert(hmu && (gc_uint8 *)hmu >= heap->base_addr
|
||||
&& (gc_uint8 *)hmu < heap->base_addr + heap->current_size);
|
||||
|
||||
if (hmu_get_ut(hmu) != HMU_FC) {
|
||||
heap->is_heap_corrupted = true;
|
||||
@ -162,7 +157,7 @@ unlink_hmu(gc_heap_t *heap, hmu_t *hmu)
|
||||
return false;
|
||||
}
|
||||
node_next = get_hmu_normal_node_next(node);
|
||||
if ((hmu_t*)node == hmu) {
|
||||
if ((hmu_t *)node == hmu) {
|
||||
if (!node_prev) /* list head */
|
||||
heap->kfc_normal_list[node_idx].next = node_next;
|
||||
else
|
||||
@ -191,15 +186,15 @@ hmu_set_free_size(hmu_t *hmu)
|
||||
bh_assert(hmu && hmu_get_ut(hmu) == HMU_FC);
|
||||
|
||||
size = hmu_get_size(hmu);
|
||||
*((uint32*)((char*) hmu + size) - 1) = size;
|
||||
*((uint32 *)((char *)hmu + size) - 1) = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add free chunk back to KFC
|
||||
*
|
||||
* @param heap should not be NULL and it should be a valid heap
|
||||
* @param hmu should not be NULL and it should be a HMU of length @size inside @heap
|
||||
* hmu should be 8-bytes aligned
|
||||
* @param hmu should not be NULL and it should be a HMU of length @size inside
|
||||
* @heap hmu should be 8-bytes aligned
|
||||
* @param size should be positive and multiple of 8
|
||||
* hmu with size @size will be added into KFC as a new FC.
|
||||
*/
|
||||
@ -212,11 +207,12 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size)
|
||||
uint32 node_idx;
|
||||
|
||||
bh_assert(gci_is_heap_valid(heap));
|
||||
bh_assert(hmu && (gc_uint8*)hmu >= heap->base_addr
|
||||
&& (gc_uint8*)hmu < heap->base_addr + heap->current_size);
|
||||
bh_assert(hmu && (gc_uint8 *)hmu >= heap->base_addr
|
||||
&& (gc_uint8 *)hmu < heap->base_addr + heap->current_size);
|
||||
bh_assert(((gc_uint32)(uintptr_t)hmu_to_obj(hmu) & 7) == 0);
|
||||
bh_assert(size > 0
|
||||
&& ((gc_uint8*)hmu) + size <= heap->base_addr + heap->current_size);
|
||||
&& ((gc_uint8 *)hmu) + size
|
||||
<= heap->base_addr + heap->current_size);
|
||||
bh_assert(!(size & 7));
|
||||
|
||||
base_addr = heap->base_addr;
|
||||
@ -227,7 +223,7 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size)
|
||||
hmu_set_free_size(hmu);
|
||||
|
||||
if (HMU_IS_FC_NORMAL(size)) {
|
||||
np = (hmu_normal_node_t*)hmu;
|
||||
np = (hmu_normal_node_t *)hmu;
|
||||
if (!hmu_is_in_heap(np, base_addr, end_addr)) {
|
||||
heap->is_heap_corrupted = true;
|
||||
return false;
|
||||
@ -240,7 +236,7 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size)
|
||||
}
|
||||
|
||||
/* big block*/
|
||||
node = (hmu_tree_node_t*)hmu;
|
||||
node = (hmu_tree_node_t *)hmu;
|
||||
node->size = size;
|
||||
node->left = node->right = node->parent = NULL;
|
||||
|
||||
@ -308,7 +304,7 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
|
||||
/* find a non-empty slot in normal_node_list with good size*/
|
||||
init_node_idx = (size >> 3);
|
||||
for (node_idx = init_node_idx; node_idx < HMU_NORMAL_NODE_CNT;
|
||||
node_idx++) {
|
||||
node_idx++) {
|
||||
normal_head = heap->kfc_normal_list + node_idx;
|
||||
if (normal_head->next)
|
||||
break;
|
||||
@ -333,7 +329,7 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
|
||||
if ((gc_size_t)node_idx != (uint32)init_node_idx
|
||||
/* with bigger size*/
|
||||
&& ((gc_size_t)node_idx << 3) >= size + GC_SMALLEST_SIZE) {
|
||||
rest = (hmu_t*) (((char *) p) + size);
|
||||
rest = (hmu_t *)(((char *)p) + size);
|
||||
if (!gci_add_fc(heap, rest, (node_idx << 3) - size)) {
|
||||
return NULL;
|
||||
}
|
||||
@ -341,7 +337,7 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
|
||||
}
|
||||
else {
|
||||
size = node_idx << 3;
|
||||
next = (hmu_t*) ((char*) p + size);
|
||||
next = (hmu_t *)((char *)p + size);
|
||||
if (hmu_is_in_heap(next, base_addr, end_addr))
|
||||
hmu_mark_pinuse(next);
|
||||
}
|
||||
@ -349,11 +345,11 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
|
||||
heap->total_free_size -= size;
|
||||
if ((heap->current_size - heap->total_free_size)
|
||||
> heap->highmark_size)
|
||||
heap->highmark_size = heap->current_size
|
||||
- heap->total_free_size;
|
||||
heap->highmark_size =
|
||||
heap->current_size - heap->total_free_size;
|
||||
|
||||
hmu_set_size((hmu_t* )p, size);
|
||||
return (hmu_t*)p;
|
||||
hmu_set_size((hmu_t *)p, size);
|
||||
return (hmu_t *)p;
|
||||
}
|
||||
}
|
||||
|
||||
@ -389,14 +385,14 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
|
||||
return NULL;
|
||||
|
||||
if (last_tp->size >= size + GC_SMALLEST_SIZE) {
|
||||
rest = (hmu_t*)((char*)last_tp + size);
|
||||
rest = (hmu_t *)((char *)last_tp + size);
|
||||
if (!gci_add_fc(heap, rest, last_tp->size - size))
|
||||
return NULL;
|
||||
hmu_mark_pinuse(rest);
|
||||
}
|
||||
else {
|
||||
size = last_tp->size;
|
||||
next = (hmu_t*)((char*)last_tp + size);
|
||||
next = (hmu_t *)((char *)last_tp + size);
|
||||
if (hmu_is_in_heap(next, base_addr, end_addr))
|
||||
hmu_mark_pinuse(next);
|
||||
}
|
||||
@ -405,8 +401,8 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
|
||||
if ((heap->current_size - heap->total_free_size) > heap->highmark_size)
|
||||
heap->highmark_size = heap->current_size - heap->total_free_size;
|
||||
|
||||
hmu_set_size((hmu_t*)last_tp, size);
|
||||
return (hmu_t*)last_tp;
|
||||
hmu_set_size((hmu_t *)last_tp, size);
|
||||
return (hmu_t *)last_tp;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -444,13 +440,12 @@ gc_object_t
|
||||
gc_alloc_vo(void *vheap, gc_size_t size)
|
||||
#else
|
||||
gc_object_t
|
||||
gc_alloc_vo_internal(void *vheap, gc_size_t size,
|
||||
const char *file, int line)
|
||||
gc_alloc_vo_internal(void *vheap, gc_size_t size, const char *file, int line)
|
||||
#endif
|
||||
{
|
||||
gc_heap_t* heap = (gc_heap_t*) vheap;
|
||||
gc_heap_t *heap = (gc_heap_t *)vheap;
|
||||
hmu_t *hmu = NULL;
|
||||
gc_object_t ret = (gc_object_t) NULL;
|
||||
gc_object_t ret = (gc_object_t)NULL;
|
||||
gc_size_t tot_size = 0, tot_size_unaligned;
|
||||
|
||||
/* hmu header + prefix + obj + suffix */
|
||||
@ -489,7 +484,7 @@ gc_alloc_vo_internal(void *vheap, gc_size_t size,
|
||||
ret = hmu_to_obj(hmu);
|
||||
if (tot_size > tot_size_unaligned)
|
||||
/* clear buffer appended by GC_ALIGN_8() */
|
||||
memset((uint8*)ret + size, 0, tot_size - tot_size_unaligned);
|
||||
memset((uint8 *)ret + size, 0, tot_size - tot_size_unaligned);
|
||||
|
||||
finish:
|
||||
os_mutex_unlock(&heap->lock);
|
||||
@ -501,13 +496,13 @@ gc_object_t
|
||||
gc_realloc_vo(void *vheap, void *ptr, gc_size_t size)
|
||||
#else
|
||||
gc_object_t
|
||||
gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
|
||||
const char *file, int line)
|
||||
gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file,
|
||||
int line)
|
||||
#endif
|
||||
{
|
||||
gc_heap_t* heap = (gc_heap_t*) vheap;
|
||||
gc_heap_t *heap = (gc_heap_t *)vheap;
|
||||
hmu_t *hmu = NULL, *hmu_old = NULL, *hmu_next;
|
||||
gc_object_t ret = (gc_object_t) NULL, obj_old = (gc_object_t)ptr;
|
||||
gc_object_t ret = (gc_object_t)NULL, obj_old = (gc_object_t)ptr;
|
||||
gc_size_t tot_size, tot_size_unaligned, tot_size_old = 0, tot_size_next;
|
||||
gc_size_t obj_size, obj_size_old;
|
||||
gc_uint8 *base_addr, *end_addr;
|
||||
@ -540,24 +535,24 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
|
||||
os_mutex_lock(&heap->lock);
|
||||
|
||||
if (hmu_old) {
|
||||
hmu_next = (hmu_t*)((char *)hmu_old + tot_size_old);
|
||||
hmu_next = (hmu_t *)((char *)hmu_old + tot_size_old);
|
||||
if (hmu_is_in_heap(hmu_next, base_addr, end_addr)) {
|
||||
ut = hmu_get_ut(hmu_next);
|
||||
tot_size_next = hmu_get_size(hmu_next);
|
||||
if (ut == HMU_FC
|
||||
&& tot_size <= tot_size_old + tot_size_next) {
|
||||
if (ut == HMU_FC && tot_size <= tot_size_old + tot_size_next) {
|
||||
/* current node and next node meets requirement */
|
||||
if (!unlink_hmu(heap, hmu_next)) {
|
||||
os_mutex_unlock(&heap->lock);
|
||||
return NULL;
|
||||
}
|
||||
hmu_set_size(hmu_old, tot_size);
|
||||
memset((char*)hmu_old + tot_size_old, 0, tot_size - tot_size_old);
|
||||
memset((char *)hmu_old + tot_size_old, 0,
|
||||
tot_size - tot_size_old);
|
||||
#if BH_ENABLE_GC_VERIFY != 0
|
||||
hmu_init_prefix_and_suffix(hmu_old, tot_size, file, line);
|
||||
#endif
|
||||
if (tot_size < tot_size_old + tot_size_next) {
|
||||
hmu_next = (hmu_t*)((char*)hmu_old + tot_size);
|
||||
hmu_next = (hmu_t *)((char *)hmu_old + tot_size);
|
||||
tot_size_next = tot_size_old + tot_size_next - tot_size;
|
||||
if (!gci_add_fc(heap, hmu_next, tot_size_next)) {
|
||||
os_mutex_unlock(&heap->lock);
|
||||
@ -570,7 +565,6 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hmu = alloc_hmu_ex(heap, tot_size);
|
||||
if (!hmu)
|
||||
goto finish;
|
||||
@ -596,8 +590,8 @@ finish:
|
||||
obj_size = tot_size - HMU_SIZE - OBJ_PREFIX_SIZE - OBJ_SUFFIX_SIZE;
|
||||
memset(ret, 0, obj_size);
|
||||
if (obj_old) {
|
||||
obj_size_old = tot_size_old - HMU_SIZE
|
||||
- OBJ_PREFIX_SIZE - OBJ_SUFFIX_SIZE;
|
||||
obj_size_old =
|
||||
tot_size_old - HMU_SIZE - OBJ_PREFIX_SIZE - OBJ_SUFFIX_SIZE;
|
||||
bh_memcpy_s(ret, obj_size, obj_old, obj_size_old);
|
||||
}
|
||||
}
|
||||
@ -619,7 +613,7 @@ gci_is_heap_valid(gc_heap_t *heap)
|
||||
{
|
||||
if (!heap)
|
||||
return GC_FALSE;
|
||||
if (heap->heap_id != (gc_handle_t) heap)
|
||||
if (heap->heap_id != (gc_handle_t)heap)
|
||||
return GC_FALSE;
|
||||
|
||||
return GC_TRUE;
|
||||
@ -630,11 +624,10 @@ int
|
||||
gc_free_vo(void *vheap, gc_object_t obj)
|
||||
#else
|
||||
int
|
||||
gc_free_vo_internal(void *vheap, gc_object_t obj,
|
||||
const char *file, int line)
|
||||
gc_free_vo_internal(void *vheap, gc_object_t obj, const char *file, int line)
|
||||
#endif
|
||||
{
|
||||
gc_heap_t* heap = (gc_heap_t*) vheap;
|
||||
gc_heap_t *heap = (gc_heap_t *)vheap;
|
||||
gc_uint8 *base_addr, *end_addr;
|
||||
hmu_t *hmu = NULL;
|
||||
hmu_t *prev = NULL;
|
||||
@ -678,7 +671,7 @@ gc_free_vo_internal(void *vheap, gc_object_t obj,
|
||||
heap->total_free_size += size;
|
||||
|
||||
if (!hmu_get_pinuse(hmu)) {
|
||||
prev = (hmu_t*) ((char*) hmu - *((int*) hmu - 1));
|
||||
prev = (hmu_t *)((char *)hmu - *((int *)hmu - 1));
|
||||
|
||||
if (hmu_is_in_heap(prev, base_addr, end_addr)
|
||||
&& hmu_get_ut(prev) == HMU_FC) {
|
||||
@ -691,7 +684,7 @@ gc_free_vo_internal(void *vheap, gc_object_t obj,
|
||||
}
|
||||
}
|
||||
|
||||
next = (hmu_t*) ((char*) hmu + size);
|
||||
next = (hmu_t *)((char *)hmu + size);
|
||||
if (hmu_is_in_heap(next, base_addr, end_addr)) {
|
||||
if (hmu_get_ut(next) == HMU_FC) {
|
||||
size += hmu_get_size(next);
|
||||
@ -699,7 +692,7 @@ gc_free_vo_internal(void *vheap, gc_object_t obj,
|
||||
ret = GC_ERROR;
|
||||
goto out;
|
||||
}
|
||||
next = (hmu_t*)((char*) hmu + size);
|
||||
next = (hmu_t *)((char *)hmu + size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -711,8 +704,8 @@ gc_free_vo_internal(void *vheap, gc_object_t obj,
|
||||
if (hmu_is_in_heap(next, base_addr, end_addr)) {
|
||||
hmu_unmark_pinuse(next);
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ret = GC_ERROR;
|
||||
goto out;
|
||||
}
|
||||
@ -750,14 +743,14 @@ gci_dump(gc_heap_t *heap)
|
||||
int i = 0, p, mark;
|
||||
char inuse = 'U';
|
||||
|
||||
cur = (hmu_t*)heap->base_addr;
|
||||
end = (hmu_t*)((char*)heap->base_addr + heap->current_size);
|
||||
cur = (hmu_t *)heap->base_addr;
|
||||
end = (hmu_t *)((char *)heap->base_addr + heap->current_size);
|
||||
|
||||
while(cur < end) {
|
||||
while (cur < end) {
|
||||
ut = hmu_get_ut(cur);
|
||||
size = hmu_get_size(cur);
|
||||
p = hmu_get_pinuse(cur);
|
||||
mark = hmu_is_jo_marked (cur);
|
||||
mark = hmu_is_jo_marked(cur);
|
||||
|
||||
if (ut == HMU_VO)
|
||||
inuse = 'V';
|
||||
@ -772,9 +765,9 @@ gci_dump(gc_heap_t *heap)
|
||||
return;
|
||||
}
|
||||
|
||||
os_printf("#%d %08x %x %x %d %c %d\n",
|
||||
i, (int32)((char*) cur - (char*) heap->base_addr),
|
||||
ut, p, mark, inuse, (int32)hmu_obj_size(size));
|
||||
os_printf("#%d %08x %x %x %d %c %d\n", i,
|
||||
(int32)((char *)cur - (char *)heap->base_addr), ut, p, mark,
|
||||
inuse, (int32)hmu_obj_size(size));
|
||||
#if BH_ENABLE_GC_VERIFY != 0
|
||||
if (inuse == 'V') {
|
||||
gc_object_prefix_t *prefix = (gc_object_prefix_t *)(cur + 1);
|
||||
@ -782,10 +775,9 @@ gci_dump(gc_heap_t *heap)
|
||||
}
|
||||
#endif
|
||||
|
||||
cur = (hmu_t*)((char *)cur + size);
|
||||
cur = (hmu_t *)((char *)cur + size);
|
||||
i++;
|
||||
}
|
||||
|
||||
bh_assert(cur == end);
|
||||
}
|
||||
|
||||
|
||||
@ -8,8 +8,6 @@
|
||||
* @date Wed Aug 3 10:46:38 2011
|
||||
*
|
||||
* @brief This file defines GC modules types and interfaces.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _EMS_GC_H
|
||||
@ -33,15 +31,15 @@ extern "C" {
|
||||
|
||||
#define GC_MAX_HEAP_SIZE (256 * BH_KB)
|
||||
|
||||
typedef void * gc_handle_t;
|
||||
typedef void * gc_object_t;
|
||||
typedef int64 gc_int64;
|
||||
typedef void *gc_handle_t;
|
||||
typedef void *gc_object_t;
|
||||
typedef int64 gc_int64;
|
||||
typedef uint32 gc_uint32;
|
||||
typedef int32 gc_int32;
|
||||
typedef int32 gc_int32;
|
||||
typedef uint16 gc_uint16;
|
||||
typedef int16 gc_int16;
|
||||
typedef uint8 gc_uint8;
|
||||
typedef int8 gc_int8;
|
||||
typedef int16 gc_int16;
|
||||
typedef uint8 gc_uint8;
|
||||
typedef int8 gc_int8;
|
||||
typedef uint32 gc_size_t;
|
||||
|
||||
typedef enum {
|
||||
@ -105,8 +103,7 @@ gc_get_heap_struct_size(void);
|
||||
* @return GC_SUCCESS if success, GC_ERROR otherwise
|
||||
*/
|
||||
int
|
||||
gc_migrate(gc_handle_t handle,
|
||||
char *pool_buf_new, gc_size_t pool_buf_size);
|
||||
gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size);
|
||||
|
||||
/**
|
||||
* Check whether the heap is corrupted
|
||||
@ -126,7 +123,7 @@ gc_is_heap_corrupted(gc_handle_t handle);
|
||||
* @param mmt [in] type of heap, MMT_SHARED or MMT_INSTANCE
|
||||
*/
|
||||
void *
|
||||
gc_heap_stats(void *heap, uint32* stats, int size);
|
||||
gc_heap_stats(void *heap, uint32 *stats, int size);
|
||||
|
||||
#if BH_ENABLE_GC_VERIFY == 0
|
||||
|
||||
@ -142,17 +139,16 @@ gc_free_vo(void *heap, gc_object_t obj);
|
||||
#else /* else of BH_ENABLE_GC_VERIFY */
|
||||
|
||||
gc_object_t
|
||||
gc_alloc_vo_internal(void *heap, gc_size_t size,
|
||||
const char *file, int line);
|
||||
gc_alloc_vo_internal(void *heap, gc_size_t size, const char *file, int line);
|
||||
|
||||
gc_object_t
|
||||
gc_realloc_vo_internal(void *heap, void *ptr, gc_size_t size,
|
||||
const char *file, int line);
|
||||
gc_realloc_vo_internal(void *heap, void *ptr, gc_size_t size, const char *file,
|
||||
int line);
|
||||
|
||||
int
|
||||
gc_free_vo_internal(void *heap, gc_object_t obj,
|
||||
const char *file, int line);
|
||||
gc_free_vo_internal(void *heap, gc_object_t obj, const char *file, int line);
|
||||
|
||||
/* clang-format off */
|
||||
#define gc_alloc_vo(heap, size) \
|
||||
gc_alloc_vo_internal(heap, size, __FILE__, __LINE__)
|
||||
|
||||
@ -161,6 +157,7 @@ gc_free_vo_internal(void *heap, gc_object_t obj,
|
||||
|
||||
#define gc_free_vo(heap, obj) \
|
||||
gc_free_vo_internal(heap, obj, __FILE__, __LINE__)
|
||||
/* clang-format on */
|
||||
|
||||
#endif /* end of BH_ENABLE_GC_VERIFY */
|
||||
|
||||
@ -169,4 +166,3 @@ gc_free_vo_internal(void *heap, gc_object_t obj,
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -60,8 +60,8 @@ hmu_init_prefix_and_suffix(hmu_t *hmu, gc_size_t tot_size,
|
||||
void
|
||||
hmu_verify(void *vheap, hmu_t *hmu);
|
||||
|
||||
#define SKIP_OBJ_PREFIX(p) ((void*)((gc_uint8*)(p) + OBJ_PREFIX_SIZE))
|
||||
#define SKIP_OBJ_SUFFIX(p) ((void*)((gc_uint8*)(p) + OBJ_SUFFIX_SIZE))
|
||||
#define SKIP_OBJ_PREFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_PREFIX_SIZE))
|
||||
#define SKIP_OBJ_SUFFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_SUFFIX_SIZE))
|
||||
|
||||
#define OBJ_EXTRA_SIZE (HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE)
|
||||
|
||||
@ -70,8 +70,8 @@ hmu_verify(void *vheap, hmu_t *hmu);
|
||||
#define OBJ_PREFIX_SIZE 0
|
||||
#define OBJ_SUFFIX_SIZE 0
|
||||
|
||||
#define SKIP_OBJ_PREFIX(p) ((void*)((gc_uint8*)(p) + OBJ_PREFIX_SIZE))
|
||||
#define SKIP_OBJ_SUFFIX(p) ((void*)((gc_uint8*)(p) + OBJ_SUFFIX_SIZE))
|
||||
#define SKIP_OBJ_PREFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_PREFIX_SIZE))
|
||||
#define SKIP_OBJ_SUFFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_SUFFIX_SIZE))
|
||||
|
||||
#define OBJ_EXTRA_SIZE (HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE)
|
||||
|
||||
@ -81,8 +81,11 @@ hmu_verify(void *vheap, hmu_t *hmu);
|
||||
|
||||
#define GC_ALIGN_8(s) (((uint32)(s) + 7) & (uint32)~7)
|
||||
|
||||
#define GC_SMALLEST_SIZE GC_ALIGN_8(HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE + 8)
|
||||
#define GC_GET_REAL_SIZE(x) GC_ALIGN_8(HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE + (((x) > 8) ? (x): 8))
|
||||
#define GC_SMALLEST_SIZE \
|
||||
GC_ALIGN_8(HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE + 8)
|
||||
#define GC_GET_REAL_SIZE(x) \
|
||||
GC_ALIGN_8(HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE \
|
||||
+ (((x) > 8) ? (x) : 8))
|
||||
|
||||
/**
|
||||
* hmu bit operation
|
||||
@ -92,12 +95,17 @@ hmu_verify(void *vheap, hmu_t *hmu);
|
||||
#define GETBIT(v, offset) ((v) & ((uint32)1 << (offset)) ? 1 : 0)
|
||||
#define CLRBIT(v, offset) (v) &= (~((uint32)1 << (offset)))
|
||||
|
||||
#define SETBITS(v, offset, size, value) do { \
|
||||
(v) &= ~((((uint32)1 << size) - 1) << offset); \
|
||||
(v) |= ((uint32)value << offset); \
|
||||
} while(0)
|
||||
#define CLRBITS(v, offset, size) (v) &= ~((((uint32)1 << size) - 1) << offset)
|
||||
#define GETBITS(v, offset, size) (((v) & (((((uint32)1 << size) - 1) << offset))) >> offset)
|
||||
/* clang-format off */
|
||||
#define SETBITS(v, offset, size, value) \
|
||||
do { \
|
||||
(v) &= ~((((uint32)1 << size) - 1) << offset); \
|
||||
(v) |= ((uint32)value << offset); \
|
||||
} while (0)
|
||||
#define CLRBITS(v, offset, size) \
|
||||
(v) &= ~((((uint32)1 << size) - 1) << offset)
|
||||
#define GETBITS(v, offset, size) \
|
||||
(((v) & (((((uint32)1 << size) - 1) << offset))) >> offset)
|
||||
/* clang-format on */
|
||||
|
||||
/**
|
||||
* gc object layout definition
|
||||
@ -105,30 +113,35 @@ hmu_verify(void *vheap, hmu_t *hmu);
|
||||
|
||||
#define HMU_SIZE (sizeof(hmu_t))
|
||||
|
||||
#define hmu_to_obj(hmu) (gc_object_t)(SKIP_OBJ_PREFIX((hmu_t*) (hmu) + 1))
|
||||
#define obj_to_hmu(obj) ((hmu_t *)((gc_uint8*)(obj) - OBJ_PREFIX_SIZE) - 1)
|
||||
#define hmu_to_obj(hmu) (gc_object_t)(SKIP_OBJ_PREFIX((hmu_t *)(hmu) + 1))
|
||||
#define obj_to_hmu(obj) ((hmu_t *)((gc_uint8 *)(obj)-OBJ_PREFIX_SIZE) - 1)
|
||||
|
||||
#define HMU_UT_SIZE 2
|
||||
#define HMU_UT_OFFSET 30
|
||||
#define HMU_UT_SIZE 2
|
||||
#define HMU_UT_OFFSET 30
|
||||
|
||||
#define hmu_get_ut(hmu) GETBITS ((hmu)->header, HMU_UT_OFFSET, HMU_UT_SIZE)
|
||||
#define hmu_set_ut(hmu, type) SETBITS ((hmu)->header, HMU_UT_OFFSET, HMU_UT_SIZE, type)
|
||||
#define hmu_is_ut_valid(tp) (tp >= HMU_TYPE_MIN && tp <= HMU_TYPE_MAX)
|
||||
/* clang-format off */
|
||||
#define hmu_get_ut(hmu) \
|
||||
GETBITS((hmu)->header, HMU_UT_OFFSET, HMU_UT_SIZE)
|
||||
#define hmu_set_ut(hmu, type) \
|
||||
SETBITS((hmu)->header, HMU_UT_OFFSET, HMU_UT_SIZE, type)
|
||||
#define hmu_is_ut_valid(tp) \
|
||||
(tp >= HMU_TYPE_MIN && tp <= HMU_TYPE_MAX)
|
||||
/* clang-format on */
|
||||
|
||||
/* P in use bit means the previous chunk is in use */
|
||||
#define HMU_P_OFFSET 29
|
||||
|
||||
#define hmu_mark_pinuse(hmu) SETBIT ((hmu)->header, HMU_P_OFFSET)
|
||||
#define hmu_unmark_pinuse(hmu) CLRBIT ((hmu)->header, HMU_P_OFFSET)
|
||||
#define hmu_get_pinuse(hmu) GETBIT ((hmu)->header, HMU_P_OFFSET)
|
||||
#define hmu_mark_pinuse(hmu) SETBIT((hmu)->header, HMU_P_OFFSET)
|
||||
#define hmu_unmark_pinuse(hmu) CLRBIT((hmu)->header, HMU_P_OFFSET)
|
||||
#define hmu_get_pinuse(hmu) GETBIT((hmu)->header, HMU_P_OFFSET)
|
||||
|
||||
#define HMU_JO_VT_SIZE 27
|
||||
#define HMU_JO_VT_SIZE 27
|
||||
#define HMU_JO_VT_OFFSET 0
|
||||
#define HMU_JO_MB_OFFSET 28
|
||||
|
||||
#define hmu_mark_jo(hmu) SETBIT ((hmu)->header, HMU_JO_MB_OFFSET)
|
||||
#define hmu_unmark_jo(hmu) CLRBIT ((hmu)->header, HMU_JO_MB_OFFSET)
|
||||
#define hmu_is_jo_marked(hmu) GETBIT ((hmu)->header, HMU_JO_MB_OFFSET)
|
||||
#define hmu_mark_jo(hmu) SETBIT((hmu)->header, HMU_JO_MB_OFFSET)
|
||||
#define hmu_unmark_jo(hmu) CLRBIT((hmu)->header, HMU_JO_MB_OFFSET)
|
||||
#define hmu_is_jo_marked(hmu) GETBIT((hmu)->header, HMU_JO_MB_OFFSET)
|
||||
|
||||
/**
|
||||
* The hmu size is divisible by 8, its lowest 3 bits are 0, so we only
|
||||
@ -141,11 +154,13 @@ hmu_verify(void *vheap, hmu_t *hmu);
|
||||
|
||||
#define HMU_VO_FB_OFFSET 28
|
||||
|
||||
#define hmu_is_vo_freed(hmu) GETBIT ((hmu)->header, HMU_VO_FB_OFFSET)
|
||||
#define hmu_unfree_vo(hmu) CLRBIT ((hmu)->header, HMU_VO_FB_OFFSET)
|
||||
#define hmu_is_vo_freed(hmu) GETBIT((hmu)->header, HMU_VO_FB_OFFSET)
|
||||
#define hmu_unfree_vo(hmu) CLRBIT((hmu)->header, HMU_VO_FB_OFFSET)
|
||||
|
||||
#define hmu_get_size(hmu) (GETBITS ((hmu)->header, HMU_SIZE_OFFSET, HMU_SIZE_SIZE) << 3)
|
||||
#define hmu_set_size(hmu, size) SETBITS ((hmu)->header, HMU_SIZE_OFFSET, HMU_SIZE_SIZE, ((size) >> 3))
|
||||
#define hmu_get_size(hmu) \
|
||||
(GETBITS((hmu)->header, HMU_SIZE_OFFSET, HMU_SIZE_SIZE) << 3)
|
||||
#define hmu_set_size(hmu, size) \
|
||||
SETBITS((hmu)->header, HMU_SIZE_OFFSET, HMU_SIZE_SIZE, ((size) >> 3))
|
||||
|
||||
/**
|
||||
* HMU free chunk management
|
||||
@ -173,17 +188,16 @@ static inline hmu_normal_node_t *
|
||||
get_hmu_normal_node_next(hmu_normal_node_t *node)
|
||||
{
|
||||
return node->next_offset
|
||||
? (hmu_normal_node_t *)((uint8*)node + node->next_offset)
|
||||
: NULL;
|
||||
? (hmu_normal_node_t *)((uint8 *)node + node->next_offset)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
static inline void
|
||||
set_hmu_normal_node_next(hmu_normal_node_t *node, hmu_normal_node_t *next)
|
||||
{
|
||||
if (next) {
|
||||
bh_assert((uint8*)next - (uint8*)node < INT32_MAX);
|
||||
node->next_offset = (gc_int32)(intptr_t)
|
||||
((uint8*)next - (uint8*)node);
|
||||
bh_assert((uint8 *)next - (uint8 *)node < INT32_MAX);
|
||||
node->next_offset = (gc_int32)(intptr_t)((uint8 *)next - (uint8 *)node);
|
||||
}
|
||||
else {
|
||||
node->next_offset = 0;
|
||||
@ -247,4 +261,4 @@ gci_dump(gc_heap_t *heap);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* end of _EMS_GC_INTERNAL_H */
|
||||
|
||||
@ -11,8 +11,8 @@
|
||||
* Set default value to prefix and suffix
|
||||
* @param hmu should not be NULL and should have been correctly initilized
|
||||
* (except prefix and suffix part)
|
||||
* @param tot_size is offered here because hmu_get_size can not be used till now.
|
||||
* tot_size should not be smaller than OBJ_EXTRA_SIZE.
|
||||
* @param tot_size is offered here because hmu_get_size can not be used
|
||||
* till now. tot_size should not be smaller than OBJ_EXTRA_SIZE.
|
||||
* For VO, tot_size should be equal to object total size.
|
||||
*/
|
||||
void
|
||||
@ -30,16 +30,17 @@ hmu_init_prefix_and_suffix(hmu_t *hmu, gc_size_t tot_size,
|
||||
bh_assert(hmu_get_ut(hmu) != HMU_VO || hmu_get_size(hmu) >= tot_size);
|
||||
|
||||
prefix = (gc_object_prefix_t *)(hmu + 1);
|
||||
suffix = (gc_object_suffix_t *)((gc_uint8*)hmu + tot_size - OBJ_SUFFIX_SIZE);
|
||||
suffix =
|
||||
(gc_object_suffix_t *)((gc_uint8 *)hmu + tot_size - OBJ_SUFFIX_SIZE);
|
||||
prefix->file_name = file_name;
|
||||
prefix->line_no = line_no;
|
||||
prefix->size = tot_size;
|
||||
|
||||
for(i = 0;i < GC_OBJECT_PREFIX_PADDING_CNT;i++) {
|
||||
for (i = 0; i < GC_OBJECT_PREFIX_PADDING_CNT; i++) {
|
||||
prefix->padding[i] = GC_OBJECT_PADDING_VALUE;
|
||||
}
|
||||
|
||||
for(i = 0;i < GC_OBJECT_SUFFIX_PADDING_CNT;i++) {
|
||||
for (i = 0; i < GC_OBJECT_SUFFIX_PADDING_CNT; i++) {
|
||||
suffix->padding[i] = GC_OBJECT_PADDING_VALUE;
|
||||
}
|
||||
}
|
||||
@ -61,17 +62,17 @@ hmu_verify(void *vheap, hmu_t *hmu)
|
||||
|
||||
prefix = (gc_object_prefix_t *)(hmu + 1);
|
||||
size = prefix->size;
|
||||
suffix = (gc_object_suffix_t *)((gc_uint8*)hmu + size - OBJ_SUFFIX_SIZE);
|
||||
suffix = (gc_object_suffix_t *)((gc_uint8 *)hmu + size - OBJ_SUFFIX_SIZE);
|
||||
|
||||
if (ut == HMU_VO || ut == HMU_JO) {
|
||||
/* check padding*/
|
||||
for (i = 0;i < GC_OBJECT_PREFIX_PADDING_CNT;i++) {
|
||||
for (i = 0; i < GC_OBJECT_PREFIX_PADDING_CNT; i++) {
|
||||
if (prefix->padding[i] != GC_OBJECT_PADDING_VALUE) {
|
||||
is_padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0;i < GC_OBJECT_SUFFIX_PADDING_CNT;i++) {
|
||||
for (i = 0; i < GC_OBJECT_SUFFIX_PADDING_CNT; i++) {
|
||||
if (suffix->padding[i] != GC_OBJECT_PADDING_VALUE) {
|
||||
is_padding_ok = 0;
|
||||
break;
|
||||
@ -88,4 +89,3 @@ hmu_verify(void *vheap, hmu_t *hmu)
|
||||
}
|
||||
|
||||
#endif /* end of BH_ENABLE_GC_VERIFY */
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ gc_init_internal(gc_heap_t *heap, char *base_addr, gc_size_t heap_max_size)
|
||||
|
||||
/* init all data structures*/
|
||||
heap->current_size = heap_max_size;
|
||||
heap->base_addr = (gc_uint8*)base_addr;
|
||||
heap->base_addr = (gc_uint8 *)base_addr;
|
||||
heap->heap_id = (gc_handle_t)heap;
|
||||
|
||||
heap->total_free_size = heap->current_size;
|
||||
@ -34,7 +34,7 @@ gc_init_internal(gc_heap_t *heap, char *base_addr, gc_size_t heap_max_size)
|
||||
hmu_set_ut(&root->hmu_header, HMU_FC);
|
||||
hmu_set_size(&root->hmu_header, sizeof *root);
|
||||
|
||||
q = (hmu_tree_node_t *) heap->base_addr;
|
||||
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);
|
||||
@ -53,18 +53,19 @@ 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 *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_heap_t *heap = (gc_heap_t *)buf_aligned;
|
||||
gc_size_t heap_max_size;
|
||||
|
||||
if (buf_size < APP_HEAP_SIZE_MIN) {
|
||||
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n",
|
||||
buf_size, APP_HEAP_SIZE_MIN);
|
||||
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", buf_size,
|
||||
APP_HEAP_SIZE_MIN);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
base_addr = (char*) (((uintptr_t) base_addr + 7) & (uintptr_t)~7) + GC_HEAD_PADDING;
|
||||
base_addr =
|
||||
(char *)(((uintptr_t)base_addr + 7) & (uintptr_t)~7) + GC_HEAD_PADDING;
|
||||
heap_max_size = (uint32)(buf_end - base_addr) & (uint32)~7;
|
||||
|
||||
#if WASM_ENABLE_MEMORY_TRACING != 0
|
||||
@ -81,7 +82,7 @@ gc_handle_t
|
||||
gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
|
||||
char *pool_buf, gc_size_t pool_buf_size)
|
||||
{
|
||||
gc_heap_t *heap = (gc_heap_t*)struct_buf;
|
||||
gc_heap_t *heap = (gc_heap_t *)struct_buf;
|
||||
char *base_addr = pool_buf + GC_HEAD_PADDING;
|
||||
char *pool_buf_end = pool_buf + pool_buf_size;
|
||||
gc_size_t heap_max_size;
|
||||
@ -103,8 +104,8 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
|
||||
}
|
||||
|
||||
if (pool_buf_size < APP_HEAP_SIZE_MIN) {
|
||||
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n",
|
||||
pool_buf_size, APP_HEAP_SIZE_MIN);
|
||||
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", pool_buf_size,
|
||||
APP_HEAP_SIZE_MIN);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -115,8 +116,7 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
|
||||
struct_buf_size + pool_buf_size);
|
||||
os_printf(" heap struct size: %u\n", sizeof(gc_heap_t));
|
||||
os_printf(" actual heap size: %u\n", heap_max_size);
|
||||
os_printf(" padding bytes: %u\n",
|
||||
pool_buf_size - heap_max_size);
|
||||
os_printf(" padding bytes: %u\n", pool_buf_size - heap_max_size);
|
||||
#endif
|
||||
return gc_init_internal(heap, base_addr, heap_max_size);
|
||||
}
|
||||
@ -124,16 +124,17 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
|
||||
int
|
||||
gc_destroy_with_pool(gc_handle_t handle)
|
||||
{
|
||||
gc_heap_t *heap = (gc_heap_t *) handle;
|
||||
gc_heap_t *heap = (gc_heap_t *)handle;
|
||||
#if BH_ENABLE_GC_VERIFY != 0
|
||||
hmu_t *cur = (hmu_t*)heap->base_addr;
|
||||
hmu_t *end = (hmu_t*)((char*)heap->base_addr + heap->current_size);
|
||||
hmu_t *cur = (hmu_t *)heap->base_addr;
|
||||
hmu_t *end = (hmu_t *)((char *)heap->base_addr + heap->current_size);
|
||||
if (!heap->is_heap_corrupted
|
||||
&& (hmu_t*)((char *)cur + hmu_get_size(cur)) != end) {
|
||||
&& (hmu_t *)((char *)cur + hmu_get_size(cur)) != end) {
|
||||
os_printf("Memory leak detected:\n");
|
||||
gci_dump(heap);
|
||||
#if WASM_ENABLE_SPEC_TEST != 0
|
||||
while (1);
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -157,13 +158,12 @@ adjust_ptr(uint8 **p_ptr, intptr_t offset)
|
||||
}
|
||||
|
||||
int
|
||||
gc_migrate(gc_handle_t handle,
|
||||
char *pool_buf_new, gc_size_t pool_buf_size)
|
||||
gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
|
||||
{
|
||||
gc_heap_t *heap = (gc_heap_t *)handle;
|
||||
char *base_addr_new = pool_buf_new + GC_HEAD_PADDING;
|
||||
char *pool_buf_end = pool_buf_new + pool_buf_size;
|
||||
intptr_t offset = (uint8*)base_addr_new - (uint8*)heap->base_addr;
|
||||
intptr_t offset = (uint8 *)base_addr_new - (uint8 *)heap->base_addr;
|
||||
hmu_t *cur = NULL, *end = NULL;
|
||||
hmu_tree_node_t *tree_node;
|
||||
gc_size_t heap_max_size, size;
|
||||
@ -175,8 +175,7 @@ gc_migrate(gc_handle_t handle,
|
||||
|
||||
heap_max_size = (uint32)(pool_buf_end - base_addr_new) & (uint32)~7;
|
||||
|
||||
if (pool_buf_end < base_addr_new
|
||||
|| heap_max_size < heap->current_size) {
|
||||
if (pool_buf_end < base_addr_new || heap_max_size < heap->current_size) {
|
||||
os_printf("[GC_ERROR]heap migrate invlaid pool buf size\n");
|
||||
return GC_ERROR;
|
||||
}
|
||||
@ -184,13 +183,13 @@ gc_migrate(gc_handle_t handle,
|
||||
if (offset == 0)
|
||||
return 0;
|
||||
|
||||
heap->base_addr = (uint8*)base_addr_new;
|
||||
adjust_ptr((uint8**)&heap->kfc_tree_root.left, offset);
|
||||
adjust_ptr((uint8**)&heap->kfc_tree_root.right, offset);
|
||||
adjust_ptr((uint8**)&heap->kfc_tree_root.parent, offset);
|
||||
heap->base_addr = (uint8 *)base_addr_new;
|
||||
adjust_ptr((uint8 **)&heap->kfc_tree_root.left, offset);
|
||||
adjust_ptr((uint8 **)&heap->kfc_tree_root.right, offset);
|
||||
adjust_ptr((uint8 **)&heap->kfc_tree_root.parent, offset);
|
||||
|
||||
cur = (hmu_t*)heap->base_addr;
|
||||
end = (hmu_t*)((char*)heap->base_addr + heap->current_size);
|
||||
cur = (hmu_t *)heap->base_addr;
|
||||
end = (hmu_t *)((char *)heap->base_addr + heap->current_size);
|
||||
|
||||
while (cur < end) {
|
||||
size = hmu_get_size(cur);
|
||||
@ -198,14 +197,14 @@ gc_migrate(gc_handle_t handle,
|
||||
|
||||
if (hmu_get_ut(cur) == HMU_FC && !HMU_IS_FC_NORMAL(size)) {
|
||||
tree_node = (hmu_tree_node_t *)cur;
|
||||
adjust_ptr((uint8**)&tree_node->left, offset);
|
||||
adjust_ptr((uint8**)&tree_node->right, offset);
|
||||
adjust_ptr((uint8 **)&tree_node->left, offset);
|
||||
adjust_ptr((uint8 **)&tree_node->right, offset);
|
||||
if (tree_node->parent != &heap->kfc_tree_root)
|
||||
/* The root node belongs to heap structure,
|
||||
it is fixed part and isn't changed. */
|
||||
adjust_ptr((uint8**)&tree_node->parent, offset);
|
||||
adjust_ptr((uint8 **)&tree_node->parent, offset);
|
||||
}
|
||||
cur = (hmu_t*)((char *)cur + size);
|
||||
cur = (hmu_t *)((char *)cur + size);
|
||||
}
|
||||
|
||||
bh_assert(cur == end);
|
||||
@ -229,35 +228,34 @@ gci_verify_heap(gc_heap_t *heap)
|
||||
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) {
|
||||
while (cur < end) {
|
||||
hmu_verify(heap, cur);
|
||||
cur = (hmu_t *)((gc_uint8*)cur + hmu_get_size(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_heap_stats(void *heap_arg, uint32 *stats, int size)
|
||||
{
|
||||
int i;
|
||||
gc_heap_t *heap = (gc_heap_t *) heap_arg;
|
||||
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;
|
||||
default:
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return heap;
|
||||
}
|
||||
|
||||
|
||||
@ -9,9 +9,10 @@
|
||||
|
||||
#include "ems/ems_gc.h"
|
||||
|
||||
mem_allocator_t mem_allocator_create(void *mem, uint32_t size)
|
||||
mem_allocator_t
|
||||
mem_allocator_create(void *mem, uint32_t size)
|
||||
{
|
||||
return gc_init_with_pool((char *) mem, size);
|
||||
return gc_init_with_pool((char *)mem, size);
|
||||
}
|
||||
|
||||
mem_allocator_t
|
||||
@ -20,15 +21,14 @@ mem_allocator_create_with_struct_and_pool(void *struct_buf,
|
||||
void *pool_buf,
|
||||
uint32_t pool_buf_size)
|
||||
{
|
||||
return gc_init_with_struct_and_pool((char *)struct_buf,
|
||||
struct_buf_size,
|
||||
pool_buf,
|
||||
pool_buf_size);
|
||||
return gc_init_with_struct_and_pool((char *)struct_buf, struct_buf_size,
|
||||
pool_buf, pool_buf_size);
|
||||
}
|
||||
|
||||
void mem_allocator_destroy(mem_allocator_t allocator)
|
||||
void
|
||||
mem_allocator_destroy(mem_allocator_t allocator)
|
||||
{
|
||||
gc_destroy_with_pool((gc_handle_t) allocator);
|
||||
gc_destroy_with_pool((gc_handle_t)allocator);
|
||||
}
|
||||
|
||||
uint32
|
||||
@ -40,33 +40,33 @@ mem_allocator_get_heap_struct_size()
|
||||
void *
|
||||
mem_allocator_malloc(mem_allocator_t allocator, uint32_t size)
|
||||
{
|
||||
return gc_alloc_vo((gc_handle_t) allocator, size);
|
||||
return gc_alloc_vo((gc_handle_t)allocator, size);
|
||||
}
|
||||
|
||||
void *
|
||||
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size)
|
||||
{
|
||||
return gc_realloc_vo((gc_handle_t) allocator, ptr, size);
|
||||
return gc_realloc_vo((gc_handle_t)allocator, ptr, size);
|
||||
}
|
||||
|
||||
void mem_allocator_free(mem_allocator_t allocator, void *ptr)
|
||||
void
|
||||
mem_allocator_free(mem_allocator_t allocator, void *ptr)
|
||||
{
|
||||
if (ptr)
|
||||
gc_free_vo((gc_handle_t) allocator, ptr);
|
||||
gc_free_vo((gc_handle_t)allocator, ptr);
|
||||
}
|
||||
|
||||
int
|
||||
mem_allocator_migrate(mem_allocator_t allocator,
|
||||
char *pool_buf_new, uint32 pool_buf_size)
|
||||
mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
|
||||
uint32 pool_buf_size)
|
||||
{
|
||||
return gc_migrate((gc_handle_t) allocator,
|
||||
pool_buf_new, pool_buf_size);
|
||||
return gc_migrate((gc_handle_t)allocator, pool_buf_new, pool_buf_size);
|
||||
}
|
||||
|
||||
bool
|
||||
mem_allocator_is_heap_corrupted(mem_allocator_t allocator)
|
||||
{
|
||||
return gc_is_heap_corrupted((gc_handle_t) allocator);
|
||||
return gc_is_heap_corrupted((gc_handle_t)allocator);
|
||||
}
|
||||
|
||||
#else /* else of DEFAULT_MEM_ALLOCATOR */
|
||||
@ -76,23 +76,23 @@ mem_allocator_is_heap_corrupted(mem_allocator_t allocator)
|
||||
typedef struct mem_allocator_tlsf {
|
||||
tlsf_t tlsf;
|
||||
korp_mutex lock;
|
||||
}mem_allocator_tlsf;
|
||||
} mem_allocator_tlsf;
|
||||
|
||||
mem_allocator_t
|
||||
mem_allocator_create(void *mem, uint32_t size)
|
||||
{
|
||||
mem_allocator_tlsf *allocator_tlsf;
|
||||
tlsf_t tlsf;
|
||||
char *mem_aligned = (char*)(((uintptr_t)mem + 3) & ~3);
|
||||
char *mem_aligned = (char *)(((uintptr_t)mem + 3) & ~3);
|
||||
|
||||
if (size < 1024) {
|
||||
printf("Create mem allocator failed: pool size must be "
|
||||
"at least 1024 bytes.\n");
|
||||
"at least 1024 bytes.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size -= mem_aligned - (char*)mem;
|
||||
mem = (void*)mem_aligned;
|
||||
size -= mem_aligned - (char *)mem;
|
||||
mem = (void *)mem_aligned;
|
||||
|
||||
tlsf = tlsf_create_with_pool(mem, size);
|
||||
if (!tlsf) {
|
||||
@ -174,12 +174,10 @@ mem_allocator_free(mem_allocator_t allocator, void *ptr)
|
||||
}
|
||||
|
||||
int
|
||||
mem_allocator_migrate(mem_allocator_t allocator,
|
||||
mem_allocator_t allocator_old)
|
||||
mem_allocator_migrate(mem_allocator_t allocator, mem_allocator_t allocator_old)
|
||||
{
|
||||
return tlsf_migrate((mem_allocator_tlsf *) allocator,
|
||||
(mem_allocator_tlsf *) allocator_old);
|
||||
return tlsf_migrate((mem_allocator_tlsf *)allocator,
|
||||
(mem_allocator_tlsf *)allocator_old);
|
||||
}
|
||||
|
||||
#endif /* end of DEFAULT_MEM_ALLOCATOR */
|
||||
|
||||
|
||||
@ -39,8 +39,8 @@ void
|
||||
mem_allocator_free(mem_allocator_t allocator, void *ptr);
|
||||
|
||||
int
|
||||
mem_allocator_migrate(mem_allocator_t allocator,
|
||||
char *pool_buf_new, uint32 pool_buf_size);
|
||||
mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
|
||||
uint32 pool_buf_size);
|
||||
|
||||
bool
|
||||
mem_allocator_is_heap_corrupted(mem_allocator_t allocator);
|
||||
@ -50,4 +50,3 @@ mem_allocator_is_heap_corrupted(mem_allocator_t allocator);
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef __MEM_ALLOC_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user