GC: Fix printf formats for debugging; add gc_dump_alloc_table.

This commit is contained in:
Damien George 2014-02-26 22:55:59 +00:00
parent 41eb6086b7
commit ce1162ab15
3 changed files with 22 additions and 16 deletions

33
py/gc.c
View File

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

View File

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

View File

@ -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**)&regs, ((uint32_t)stack_top - (uint32_t)&regs) / sizeof(uint32_t));
gc_collect_root((void**)&regs, ((machine_uint_t)stack_top - (machine_uint_t)&regs) / sizeof(machine_uint_t));
gc_collect_end();
//printf("-----\n");