diff --git a/gc.c b/gc.c index f7bc528f..1cfc1759 100644 --- a/gc.c +++ b/gc.c @@ -793,6 +793,11 @@ void gc_wait_handshake() ///////////////////////////////////////////// // GC Collection cycle +//TODO: create function to print globals, ideally want names and the mark flag. +//then call before/after tracing to see if we can catch a global not being marked. +//want to rule out an issue here, since we have seen globals that were corrupted (IE, appears they were collected) +void debug_dump_globals(); + // Main collector function void gc_collector() { @@ -812,19 +817,20 @@ void gc_collector() while(!ATOMIC_SET_IF_EQ(&gc_color_mark, old_mark, old_clear)){} printf("DEBUG - swap clear %d / mark %d\n", gc_color_clear, gc_color_mark); gc_handshake(STATUS_SYNC1); -printf("DEBUG - after handshake sync 1\n"); +//printf("DEBUG - after handshake sync 1\n"); //mark : gc_handshake(STATUS_SYNC2); -printf("DEBUG - after handshake sync 2\n"); +//printf("DEBUG - after handshake sync 2\n"); gc_stage = STAGE_TRACING; gc_post_handshake(STATUS_ASYNC); -printf("DEBUG - after post_handshake aync\n"); +//printf("DEBUG - after post_handshake aync\n"); gc_mark_globals(); gc_wait_handshake(); -printf("DEBUG - after wait_handshake aync\n"); +//printf("DEBUG - after wait_handshake aync\n"); //trace : gc_collector_trace(); -printf("DEBUG - after trace\n"); +//printf("DEBUG - after trace\n"); +debug_dump_globals(); gc_stage = STAGE_SWEEPING; // //sweep : diff --git a/runtime.c b/runtime.c index 4804d8b2..4f7c18d5 100644 --- a/runtime.c +++ b/runtime.c @@ -206,6 +206,27 @@ void add_global(object *glo) { // this is more expedient global_table = mcons(mcvar(glo), global_table); } + +void debug_dump_globals() +{ + list l = global_table; + for(; !nullp(l); l = cdr(l)){ + cvar_type *c = (cvar_type *)car(l); + //gc_mark(h, *(c->pvar)); // Mark actual object the global points to + printf("DEBUG %p ", c->pvar); + if (*c->pvar){ + printf("mark = %d ", mark(*c->pvar)); + if (mark(*c->pvar) == gc_color_red) { + printf("obj = "); + Cyc_display(*c->pvar, stdout); + } + printf("\n"); + } else { + printf(" is NULL\n"); + } + } +} + /* END Global table */ /* Mutation table @@ -2417,7 +2438,10 @@ void gc_mark_globals() list l = global_table; for(; !nullp(l); l = cdr(l)){ cvar_type *c = (cvar_type *)car(l); - gc_mark_black(*(c->pvar)); // Mark actual object the global points to + object glo = *(c->pvar); + if (!nullp(glo)) { + gc_mark_black(glo); // Mark actual object the global points to + } } } }