From ce1162ab15e69c42157aea4ecc341cc5044e2477 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 26 Feb 2014 22:55:59 +0000 Subject: [PATCH] GC: Fix printf formats for debugging; add gc_dump_alloc_table. --- py/gc.c | 33 +++++++++++++++++++-------------- py/gc.h | 1 + unix/gccollect.c | 4 ++-- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/py/gc.c b/py/gc.c index 7f2035668e..bcdfc50954 100644 --- a/py/gc.c +++ b/py/gc.c @@ -90,8 +90,8 @@ void gc_init(void *start, void *end) { } DEBUG_printf("GC layout:\n"); - DEBUG_printf(" alloc table at %p, length %u bytes\n", gc_alloc_table_start, gc_alloc_table_byte_len); - DEBUG_printf(" pool at %p, length %u blocks = %u words = %u bytes\n", gc_pool_start, gc_pool_block_len, gc_pool_word_len, gc_pool_word_len * BYTES_PER_WORD); + DEBUG_printf(" alloc table at %p, length " UINT_FMT " bytes\n", gc_alloc_table_start, gc_alloc_table_byte_len); + DEBUG_printf(" pool at %p, length " UINT_FMT " blocks = " UINT_FMT " words = " UINT_FMT " bytes\n", gc_pool_start, gc_pool_block_len, gc_pool_word_len, gc_pool_word_len * BYTES_PER_WORD); } #define VERIFY_PTR(ptr) ( \ @@ -240,7 +240,7 @@ void gc_info(gc_info_t *info) { void *gc_alloc(machine_uint_t n_bytes) { machine_uint_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK; - DEBUG_printf("gc_alloc(%u bytes -> %u blocks)\n", n_bytes, n_blocks); + DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks)\n", n_bytes, n_blocks); // check for 0 allocation if (n_blocks == 0) { @@ -350,20 +350,25 @@ void gc_dump_info() { info.num_1block, info.num_2block, info.max_block); } -#if DEBUG_PRINT -STATIC void gc_dump_at(void) { +void gc_dump_alloc_table(void) { + printf("GC memory layout:"); for (machine_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) { - printf("block %06u ", bl); - switch (ATB_GET_KIND(bl)) { - case AT_FREE: printf("FREE"); break; - case AT_HEAD: printf("HEAD"); break; - case AT_TAIL: printf("TAIL"); break; - default: printf("MARK"); break; + if (bl % 64 == 0) { + printf("\n%04x: ", (uint)bl); } - printf("\n"); + int c = ' '; + switch (ATB_GET_KIND(bl)) { + case AT_FREE: c = '.'; break; + case AT_HEAD: c = 'h'; break; + case AT_TAIL: c = 't'; break; + case AT_MARK: c = 'm'; break; + } + printf("%c", c); } + printf("\n"); } +#if DEBUG_PRINT void gc_test(void) { machine_uint_t len = 500; machine_uint_t *heap = malloc(len); @@ -389,13 +394,13 @@ void gc_test(void) { } printf("Before GC:\n"); - gc_dump_at(); + gc_dump_alloc_table(); printf("Starting GC...\n"); gc_collect_start(); gc_collect_root(ptrs, sizeof(ptrs) / sizeof(void*)); gc_collect_end(); printf("After GC:\n"); - gc_dump_at(); + gc_dump_alloc_table(); } #endif diff --git a/py/gc.h b/py/gc.h index e5286cd861..c8a1a996c3 100644 --- a/py/gc.h +++ b/py/gc.h @@ -19,3 +19,4 @@ typedef struct _gc_info_t { void gc_info(gc_info_t *info); void gc_dump_info(void); +void gc_dump_alloc_table(void); diff --git a/unix/gccollect.c b/unix/gccollect.c index 60bc99323e..5370a641ce 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -54,11 +54,11 @@ void gc_collect(void) { // this traces .data and .bss sections extern char __bss_start, _end; //printf(".bss: %p-%p\n", &__bss_start, &_end); - gc_collect_root((void**)&__bss_start, ((uint32_t)&_end - (uint32_t)&__bss_start) / sizeof(uint32_t)); + gc_collect_root((void**)&__bss_start, ((machine_uint_t)&_end - (machine_uint_t)&__bss_start) / sizeof(machine_uint_t)); regs_t regs; gc_helper_get_regs(regs); // GC stack (and regs because we captured them) - gc_collect_root((void**)®s, ((uint32_t)stack_top - (uint32_t)®s) / sizeof(uint32_t)); + gc_collect_root((void**)®s, ((machine_uint_t)stack_top - (machine_uint_t)®s) / sizeof(machine_uint_t)); gc_collect_end(); //printf("-----\n");