add debug prints at GC

This commit is contained in:
Yuichi Nishiwaki 2013-10-14 18:22:14 +09:00
parent 276e139ec6
commit 8c73ded2c4
1 changed files with 36 additions and 0 deletions

View File

@ -186,6 +186,10 @@ gc_unmark(union header *p)
static void static void
gc_finalize_object(pic_state *pic, struct pic_object *obj) gc_finalize_object(pic_state *pic, struct pic_object *obj)
{ {
#if GC_DEBUG
printf("finalizing object type %d\n", obj->tt);
#endif
switch (obj->tt) { switch (obj->tt) {
case PIC_TT_SYMBOL: { case PIC_TT_SYMBOL: {
char *name; char *name;
@ -216,15 +220,41 @@ gc_sweep_phase(pic_state *pic)
{ {
union header *base, *bp, *p; union header *base, *bp, *p;
#if GC_DEBUG
puts("sweep started");
#endif
base = pic->heap->base; base = pic->heap->base;
for (p = base->s.ptr; p != base; p = p->s.ptr) { for (p = base->s.ptr; p != base; p = p->s.ptr) {
#if GC_DEBUG
puts("sweeping block");
#endif
for (bp = p + p->s.size; bp != p->s.ptr; bp += bp->s.size) { for (bp = p + p->s.size; bp != p->s.ptr; bp += bp->s.size) {
#if GC_DEBUG
printf(" bp = %p\n p = %p\n p->s.ptr = %p\n endp = %p\n",bp, p, p->s.ptr, pic->heap->endp);
#endif
if (p >= p->s.ptr && bp == pic->heap->endp) if (p >= p->s.ptr && bp == pic->heap->endp)
break; break;
if (is_marked(bp)) { if (is_marked(bp)) {
#if GC_DEBUG
printf("marked:\t\t\t");
pic_debug(pic, pic_obj_value((struct pic_object *)(bp + 1)));
printf("\n");
#endif
gc_unmark(bp); gc_unmark(bp);
continue; continue;
} }
#if GC_DEBUG
puts("unmarked");
#endif
/* free! */ /* free! */
gc_finalize_object(pic, (struct pic_object *)(bp + 1)); gc_finalize_object(pic, (struct pic_object *)(bp + 1));
if (bp + bp->s.size == p->s.ptr) { if (bp + bp->s.size == p->s.ptr) {
@ -249,7 +279,9 @@ gc_sweep_phase(pic_state *pic)
void void
pic_gc_run(pic_state *pic) pic_gc_run(pic_state *pic)
{ {
#if GC_DEBUG
puts("gc run!"); puts("gc run!");
#endif
gc_mark_phase(pic); gc_mark_phase(pic);
gc_sweep_phase(pic); gc_sweep_phase(pic);
} }
@ -268,6 +300,10 @@ pic_obj_alloc(pic_state *pic, size_t size, enum pic_tt tt)
} }
obj->tt = tt; obj->tt = tt;
#if GC_DEBUG
printf("* alloced object type %d\n", tt);
#endif
gc_protect(pic, obj); gc_protect(pic, obj);
return obj; return obj;
} }