|
@ -726,7 +726,7 @@ found: |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
gc_dump_alloc_table(); |
|
|
gc_dump_alloc_table(&mp_plat_print); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
return ret_ptr; |
|
|
return ret_ptr; |
|
@ -806,7 +806,7 @@ void gc_free(void *ptr) { |
|
|
GC_EXIT(); |
|
|
GC_EXIT(); |
|
|
|
|
|
|
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
gc_dump_alloc_table(); |
|
|
gc_dump_alloc_table(&mp_plat_print); |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -960,7 +960,7 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) { |
|
|
GC_EXIT(); |
|
|
GC_EXIT(); |
|
|
|
|
|
|
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
gc_dump_alloc_table(); |
|
|
gc_dump_alloc_table(&mp_plat_print); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
return ptr_in; |
|
|
return ptr_in; |
|
@ -985,7 +985,7 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) { |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
#if EXTENSIVE_HEAP_PROFILING |
|
|
gc_dump_alloc_table(); |
|
|
gc_dump_alloc_table(&mp_plat_print); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
return ptr_in; |
|
|
return ptr_in; |
|
@ -1019,23 +1019,23 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) { |
|
|
} |
|
|
} |
|
|
#endif // Alternative gc_realloc impl
|
|
|
#endif // Alternative gc_realloc impl
|
|
|
|
|
|
|
|
|
void gc_dump_info(void) { |
|
|
void gc_dump_info(const mp_print_t *print) { |
|
|
gc_info_t info; |
|
|
gc_info_t info; |
|
|
gc_info(&info); |
|
|
gc_info(&info); |
|
|
mp_printf(&mp_plat_print, "GC: total: %u, used: %u, free: %u\n", |
|
|
mp_printf(print, "GC: total: %u, used: %u, free: %u\n", |
|
|
(uint)info.total, (uint)info.used, (uint)info.free); |
|
|
(uint)info.total, (uint)info.used, (uint)info.free); |
|
|
mp_printf(&mp_plat_print, " No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u, max free sz: %u\n", |
|
|
mp_printf(print, " No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u, max free sz: %u\n", |
|
|
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block, (uint)info.max_free); |
|
|
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block, (uint)info.max_free); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void gc_dump_alloc_table(void) { |
|
|
void gc_dump_alloc_table(const mp_print_t *print) { |
|
|
GC_ENTER(); |
|
|
GC_ENTER(); |
|
|
static const size_t DUMP_BYTES_PER_LINE = 64; |
|
|
static const size_t DUMP_BYTES_PER_LINE = 64; |
|
|
for (mp_state_mem_area_t *area = &MP_STATE_MEM(area); area != NULL; area = NEXT_AREA(area)) { |
|
|
for (mp_state_mem_area_t *area = &MP_STATE_MEM(area); area != NULL; area = NEXT_AREA(area)) { |
|
|
#if !EXTENSIVE_HEAP_PROFILING |
|
|
#if !EXTENSIVE_HEAP_PROFILING |
|
|
// When comparing heap output we don't want to print the starting
|
|
|
// When comparing heap output we don't want to print the starting
|
|
|
// pointer of the heap because it changes from run to run.
|
|
|
// pointer of the heap because it changes from run to run.
|
|
|
mp_printf(&mp_plat_print, "GC memory layout; from %p:", area->gc_pool_start); |
|
|
mp_printf(print, "GC memory layout; from %p:", area->gc_pool_start); |
|
|
#endif |
|
|
#endif |
|
|
for (size_t bl = 0; bl < area->gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) { |
|
|
for (size_t bl = 0; bl < area->gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) { |
|
|
if (bl % DUMP_BYTES_PER_LINE == 0) { |
|
|
if (bl % DUMP_BYTES_PER_LINE == 0) { |
|
@ -1048,7 +1048,7 @@ void gc_dump_alloc_table(void) { |
|
|
} |
|
|
} |
|
|
if (bl2 - bl >= 2 * DUMP_BYTES_PER_LINE) { |
|
|
if (bl2 - bl >= 2 * DUMP_BYTES_PER_LINE) { |
|
|
// there are at least 2 lines containing only free blocks, so abbreviate their printing
|
|
|
// there are at least 2 lines containing only free blocks, so abbreviate their printing
|
|
|
mp_printf(&mp_plat_print, "\n (%u lines all free)", (uint)(bl2 - bl) / DUMP_BYTES_PER_LINE); |
|
|
mp_printf(print, "\n (%u lines all free)", (uint)(bl2 - bl) / DUMP_BYTES_PER_LINE); |
|
|
bl = bl2 & (~(DUMP_BYTES_PER_LINE - 1)); |
|
|
bl = bl2 & (~(DUMP_BYTES_PER_LINE - 1)); |
|
|
if (bl >= area->gc_alloc_table_byte_len * BLOCKS_PER_ATB) { |
|
|
if (bl >= area->gc_alloc_table_byte_len * BLOCKS_PER_ATB) { |
|
|
// got to end of heap
|
|
|
// got to end of heap
|
|
@ -1058,7 +1058,7 @@ void gc_dump_alloc_table(void) { |
|
|
} |
|
|
} |
|
|
// print header for new line of blocks
|
|
|
// print header for new line of blocks
|
|
|
// (the cast to uint32_t is for 16-bit ports)
|
|
|
// (the cast to uint32_t is for 16-bit ports)
|
|
|
mp_printf(&mp_plat_print, "\n%08x: ", (uint)(bl * BYTES_PER_BLOCK)); |
|
|
mp_printf(print, "\n%08x: ", (uint)(bl * BYTES_PER_BLOCK)); |
|
|
} |
|
|
} |
|
|
int c = ' '; |
|
|
int c = ' '; |
|
|
switch (ATB_GET_KIND(area, bl)) { |
|
|
switch (ATB_GET_KIND(area, bl)) { |
|
@ -1151,9 +1151,9 @@ void gc_dump_alloc_table(void) { |
|
|
c = 'm'; |
|
|
c = 'm'; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
mp_printf(&mp_plat_print, "%c", c); |
|
|
mp_printf(print, "%c", c); |
|
|
} |
|
|
} |
|
|
mp_print_str(&mp_plat_print, "\n"); |
|
|
mp_print_str(print, "\n"); |
|
|
} |
|
|
} |
|
|
GC_EXIT(); |
|
|
GC_EXIT(); |
|
|
} |
|
|
} |
|
@ -1185,13 +1185,13 @@ void gc_test(void) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
printf("Before GC:\n"); |
|
|
printf("Before GC:\n"); |
|
|
gc_dump_alloc_table(); |
|
|
gc_dump_alloc_table(&mp_plat_print); |
|
|
printf("Starting GC...\n"); |
|
|
printf("Starting GC...\n"); |
|
|
gc_collect_start(); |
|
|
gc_collect_start(); |
|
|
gc_collect_root(ptrs, sizeof(ptrs) / sizeof(void *)); |
|
|
gc_collect_root(ptrs, sizeof(ptrs) / sizeof(void *)); |
|
|
gc_collect_end(); |
|
|
gc_collect_end(); |
|
|
printf("After GC:\n"); |
|
|
printf("After GC:\n"); |
|
|
gc_dump_alloc_table(); |
|
|
gc_dump_alloc_table(&mp_plat_print); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|