diff --git a/gc.c b/gc.c index fd657823..d11a33d4 100644 --- a/gc.c +++ b/gc.c @@ -161,7 +161,7 @@ size_t gc_heap_total_size(gc_heap *h) void gc_mark(gc_heap *h, object obj) { - if (!obj || is_marked(obj)) + if (nullp(obj) || is_value_type(obj) || mark(obj)) return; #if GC_DEBUG_PRINTFS @@ -232,7 +232,7 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr) // END DEBUG #endif - if (!is_marked(p)) { + if (!mark(p)) { #if GC_DEBUG_PRINTFS fprintf(stdout, "sweep: object is not marked %p\n", p); #endif diff --git a/include/cyclone/types.h b/include/cyclone/types.h index f773535a..841ce5a0 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -51,7 +51,6 @@ struct gc_header_type_t { unsigned int mark; // mark bits (only need 2) // TODO: forwarding address (probably not needed for mark/sweep), anything else??? }; -#define is_marked(x) (is_object_type(x) && ((list)x)->hdr.mark) #define mark(x) (((list) x)->hdr.mark) /* HEAP definitions */ @@ -76,13 +75,13 @@ gc_heap *gc_heap_last(gc_heap *h); size_t gc_heap_total_size(gc_heap *h); void gc_mark(gc_heap *h, object obj); size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr); -void gc_collect(gc_heap *h, size_t *sum_freed); +size_t gc_collect(gc_heap *h, size_t *sum_freed); void gc_thr_grow_move_buffer(gc_thread_data *d); void gc_thr_add_to_move_buffer(gc_thread_data *d, int *alloci, object obj); /* GC debugging flags */ //#define DEBUG_GC 0 -#define GC_DEBUG_PRINTFS 0 +#define GC_DEBUG_PRINTFS 1 /* Show diagnostic information for the GC when program terminates */ #define DEBUG_SHOW_DIAG 0 diff --git a/runtime.c b/runtime.c index 04060d72..dac32078 100644 --- a/runtime.c +++ b/runtime.c @@ -2353,7 +2353,7 @@ void Cyc_apply_from_buf(int argc, object prim, object *buf) { // if the heap was expanded during alloc, and after all the allocs are done // after a minor GC (or during the minor GC), call into this function to // free up unused space -void gc_collect(gc_heap *h, size_t *sum_freed) +size_t gc_collect(gc_heap *h, size_t *sum_freed) { printf("(heap: %p size: %d)\n", h, (unsigned int)gc_heap_total_size(h)); // Mark global variables @@ -2369,7 +2369,7 @@ void gc_collect(gc_heap *h, size_t *sum_freed) // conservative mark? // weak refs? // finalize? - gc_sweep(h, sum_freed); + return gc_sweep(h, sum_freed); // debug print free stats // return value from sweep?? } @@ -2594,7 +2594,7 @@ void GC(cont, args, num_args) closure cont; object *args; int num_args; int scani = 0, alloci = 0; // TODO: not quite sure how to do this yet, want to user pointers but realloc can move them... need to think about how this will work int heap_grown = 0; -fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG +//fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG // Prevent overrunning buffer if (num_args > NUM_GC_ANS) { printf("Fatal error - too many arguments (%d) to GC\n", num_args); @@ -2707,16 +2707,18 @@ fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG // Check if we need to do a major GC if (heap_grown) { - size_t freed = 0; + size_t freed = 0, max_freed = 0; fprintf(stdout, "DEBUG, starting major mark/sweep GC\n"); // JAE DEBUG gc_mark(Cyc_heap, cont); for (i = 0; i < num_args; i++){ gc_mark(Cyc_heap, args[i]); } - gc_collect(Cyc_heap, &freed); + max_freed = gc_collect(Cyc_heap, &freed); +printf("done, freed = %d, max_freed = %d\n", freed, max_freed); +exit(1); // JAE DEBUG } -fprintf(stdout, "DEBUG, finished minor GC\n"); // JAE DEBUG +//fprintf(stdout, "DEBUG, finished minor GC\n"); // JAE DEBUG longjmp(jmp_main,1); // Return globals gc_cont, gc_ans }