GC: Fix printf formats for debugging; add gc_dump_alloc_table.
This commit is contained in:
parent
41eb6086b7
commit
ce1162ab15
33
py/gc.c
33
py/gc.c
@ -90,8 +90,8 @@ void gc_init(void *start, void *end) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_printf("GC layout:\n");
|
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(" alloc table at %p, length " UINT_FMT " 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(" 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) ( \
|
#define VERIFY_PTR(ptr) ( \
|
||||||
@ -240,7 +240,7 @@ void gc_info(gc_info_t *info) {
|
|||||||
|
|
||||||
void *gc_alloc(machine_uint_t n_bytes) {
|
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;
|
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
|
// check for 0 allocation
|
||||||
if (n_blocks == 0) {
|
if (n_blocks == 0) {
|
||||||
@ -350,20 +350,25 @@ void gc_dump_info() {
|
|||||||
info.num_1block, info.num_2block, info.max_block);
|
info.num_1block, info.num_2block, info.max_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_PRINT
|
void gc_dump_alloc_table(void) {
|
||||||
STATIC void gc_dump_at(void) {
|
printf("GC memory layout:");
|
||||||
for (machine_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) {
|
for (machine_uint_t bl = 0; bl < gc_alloc_table_byte_len * BLOCKS_PER_ATB; bl++) {
|
||||||
printf("block %06u ", bl);
|
if (bl % 64 == 0) {
|
||||||
switch (ATB_GET_KIND(bl)) {
|
printf("\n%04x: ", (uint)bl);
|
||||||
case AT_FREE: printf("FREE"); break;
|
|
||||||
case AT_HEAD: printf("HEAD"); break;
|
|
||||||
case AT_TAIL: printf("TAIL"); break;
|
|
||||||
default: printf("MARK"); break;
|
|
||||||
}
|
}
|
||||||
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) {
|
void gc_test(void) {
|
||||||
machine_uint_t len = 500;
|
machine_uint_t len = 500;
|
||||||
machine_uint_t *heap = malloc(len);
|
machine_uint_t *heap = malloc(len);
|
||||||
@ -389,13 +394,13 @@ void gc_test(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Before GC:\n");
|
printf("Before GC:\n");
|
||||||
gc_dump_at();
|
gc_dump_alloc_table();
|
||||||
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_at();
|
gc_dump_alloc_table();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
1
py/gc.h
1
py/gc.h
@ -19,3 +19,4 @@ typedef struct _gc_info_t {
|
|||||||
|
|
||||||
void gc_info(gc_info_t *info);
|
void gc_info(gc_info_t *info);
|
||||||
void gc_dump_info(void);
|
void gc_dump_info(void);
|
||||||
|
void gc_dump_alloc_table(void);
|
||||||
|
@ -54,11 +54,11 @@ void gc_collect(void) {
|
|||||||
// this traces .data and .bss sections
|
// this traces .data and .bss sections
|
||||||
extern char __bss_start, _end;
|
extern char __bss_start, _end;
|
||||||
//printf(".bss: %p-%p\n", &__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;
|
regs_t regs;
|
||||||
gc_helper_get_regs(regs);
|
gc_helper_get_regs(regs);
|
||||||
// GC stack (and regs because we captured them)
|
// 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();
|
gc_collect_end();
|
||||||
|
|
||||||
//printf("-----\n");
|
//printf("-----\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user