diff --git a/gc.c b/gc.c index 1f9ccebe..fe6a8d75 100644 --- a/gc.c +++ b/gc.c @@ -675,6 +675,9 @@ void gc_thread_data_init(gc_thread_data *thd, char *stack_base, long stack_size) (1 - STACK_GROWS_DOWNWARD)); exit(1); } + thd->jmp_start = malloc(sizeof(jmp_buf)); + thd->gc_ans = malloc(sizeof(object) * NUM_GC_ANS); + thd->gc_num_ans = 0; thd->moveBufLen = 0; gc_thr_grow_move_buffer(thd); // TODO: depends on collector state: thd->gc_alloc_color = ATOMIC_GET(&gc_; @@ -692,6 +695,8 @@ void gc_thread_data_init(gc_thread_data *thd, char *stack_base, long stack_size) void gc_thread_data_free(gc_thread_data *thd) { if (thd) { + if (thd->jmp_start) free(thd->jmp_start); + if (thd->gc_ans) free(thd->gc_ans); if (thd->moveBuf) free(thd->moveBuf); if (thd->mark_buffer) free(thd->mark_buffer); free(thd); diff --git a/include/cyclone/runtime-main.h b/include/cyclone/runtime-main.h index a68c721b..0bc2cc76 100644 --- a/include/cyclone/runtime-main.h +++ b/include/cyclone/runtime-main.h @@ -60,7 +60,7 @@ static void Cyc_main (stack_size,heap_size,stack_base) start = clock(); /* Start the timing clock. */ /* Tank, load the jump program... */ - setjmp(jmp_main); + setjmp(*(Cyc_thread->jmp_start)); #if DEBUG_GC printf("Done with GC\n"); #endif diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 63b98f1b..c1568c6b 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -225,7 +225,6 @@ extern long no_major_gcs; /* Count the number of GC's. */ extern object gc_cont; /* GC continuation closure. */ extern object gc_ans[NUM_GC_ANS]; /* argument for GC continuation closure. */ extern int gc_num_ans; -extern jmp_buf jmp_main; /* Where to jump to. */ /* Define Lisp constants we need. */ extern const object boolean_t; diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 54e30236..fe8522a7 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -28,7 +28,7 @@ // This is used as the first generation of the GC. #define STACK_SIZE 250000 -// Size of a "page" on the heap (the 2nd generation), in bytes. +// Size of a "page" on the heap (the second generation), in bytes. #define HEAP_SIZE 6000000 /* Define general object type. */ @@ -40,7 +40,7 @@ struct gc_thread_data_t { // Data needed for stack-based minor GC char *stack_start; char *stack_limit; -TODO: + jmp_buf *jmp_start; object gc_cont; object *gc_ans; //[NUM_GC_ANS]; short gc_num_ans; diff --git a/runtime.c b/runtime.c index 3527a3a4..25a55c89 100644 --- a/runtime.c +++ b/runtime.c @@ -82,7 +82,7 @@ void Cyc_check_bounds(void *data, const char *label, int len, int index) { gc_heap *Cyc_heap; gc_thread_data *Cyc_thread; -TODO: get rid of globals below that are not needed +//TODO: get rid of globals below that are not needed clock_t start; /* Starting time. */ char *bottom; /* Bottom of tospace. */ char *allocp; /* Cheney allocate pointer. */ @@ -98,11 +98,10 @@ char *dhalloc_end; long no_gcs = 0; /* Count the number of GC's. */ long no_major_gcs = 0; /* Count the number of GC's. */ -TODO: after previous change, move these to thread data structure +//TODO: after previous change, move these to thread data structure object gc_cont; /* GC continuation closure. */ object gc_ans[NUM_GC_ANS]; /* argument for GC continuation closure. */ int gc_num_ans; -jmp_buf jmp_main; /* Where to jump to. */ object Cyc_global_variables = nil; int _cyc_argc = 0; @@ -2746,7 +2745,12 @@ void GC(void *data, closure cont, object *args, int num_args) } /* Let it all go, Neo... */ - longjmp(jmp_main, (int)(&data)); // Return globals gc_cont, gc_ans + // TODO: apparently it is a bad idea to cast a pointer to an int on 64 bit platforms + // as a pointer may be larger than an int. so need to figure out another technique + // here to communicate back to the setjmp which data to use. need to store a data + // structure of thread buffers for heap gc, so maybe be able to use an int to index + // into that. + longjmp(*(((gc_thread_data *)data)->jmp_start), (int)(&data)); // Return globals gc_cont, gc_ans }