diff --git a/gc.c b/gc.c index d5062a56..7716ea8c 100644 --- a/gc.c +++ b/gc.c @@ -262,6 +262,19 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr) return max_freed; } +void gc_thr_grow_move_buffer(gc_thread_data *d){ + if (!d) return; + + if (d->moveBufLen == 0) { // Special case + d->moveBufLen = 128; + d->moveBuf = NULL; + } else { + d->moveBufLen *= 2; + } + + d->moveBuf = realloc(d->moveBuf, d->moveBufLen); +} + // void gc_init() // { // } diff --git a/include/cyclone/runtime-main.h b/include/cyclone/runtime-main.h index a07e1535..012ece81 100644 --- a/include/cyclone/runtime-main.h +++ b/include/cyclone/runtime-main.h @@ -13,7 +13,6 @@ long global_stack_size = 0; long global_heap_size = 0; -gc_heap *Cyc_heap; static void c_entry_pt(int,closure,closure); static void Cyc_main(long stack_size,long heap_size,char *stack_base); @@ -59,6 +58,10 @@ static void Cyc_main (stack_size,heap_size,stack_base) #endif Cyc_heap = gc_heap_create(heap_size, 0); + Cyc_thread = (gc_thread_data *)malloc(sizeof(gc_thread_data)); + Cyc_thread->moveBufLen = 0; + gc_thr_grow_move_buffer(Cyc_thread); // Initialize the buffer + // JAE TODO: clean up below (and all of this old code, really) bottom = calloc(1,heap_size); diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 92ff5ae7..29352735 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -20,6 +20,13 @@ /* Define general object type. */ typedef void *object; +/* Thread data structures */ +typedef struct gc_thread_data_t gc_thread_data; +struct gc_thread_data_t { + char *moveBuf; /* list of objects moved to heap during GC */ + int moveBufLen; +}; + /* GC data structures */ typedef struct gc_free_list_t gc_free_list; @@ -69,6 +76,7 @@ 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); +void gc_thr_grow_move_buffer(gc_thread_data *d); /* GC debugging flags */ //#define DEBUG_GC 0 diff --git a/runtime.c b/runtime.c index 65afe17d..88ed51a0 100644 --- a/runtime.c +++ b/runtime.c @@ -9,6 +9,9 @@ #include "cyclone/types.h" #include "cyclone/runtime.h" +gc_heap *Cyc_heap; +gc_thread_data *Cyc_thread; + /* Error checking section - type mismatch, num args, etc */ /* Type names to use for error messages */ const char *tag_names[21] = { \ @@ -2405,7 +2408,7 @@ char *gc_move(char *obj) { } \ } -void GC(cont,ans,num_ans) closure cont; object *args; int num_args; +void GC(cont, args, num_args) closure cont; object *args; int num_args; { char tmp; object temp;