Moving stack limits away from global vars

This commit is contained in:
Justin Ethier 2015-11-05 22:17:42 -05:00
parent c49044fce6
commit 287f660851
4 changed files with 27 additions and 14 deletions

19
gc.c
View file

@ -657,9 +657,24 @@ void gc_empty_collector_stack()
///////////////////////////////////////////// /////////////////////////////////////////////
// Initialize a thread from scratch // Initialize runtime data structures for a thread.
void gc_thread_data_init(gc_thread_data *thd) // Must be called on the target thread itself during startup,
// to verify stack limits are setup correctly.
void gc_thread_data_init(gc_thread_data *thd, char *stack_base, long stack_size)
{ {
char stack_ref;
thd->stack_start = stack_base;
#if STACK_GROWS_DOWNWARD
thd->stack_limit = stack_base - stack_size;
#else
thd->stack_limit = stack_base + stack_size;
#endif
if (check_overflow(stack_base, &stack_ref)){
fprintf(stderr,
"Error: recompile with STACK_GROWS_DOWNWARD set to %d\n",
(1 - STACK_GROWS_DOWNWARD));
exit(1);
}
thd->moveBufLen = 0; thd->moveBufLen = 0;
gc_thr_grow_move_buffer(thd); gc_thr_grow_move_buffer(thd);
// TODO: depends on collector state: thd->gc_alloc_color = ATOMIC_GET(&gc_; // TODO: depends on collector state: thd->gc_alloc_color = ATOMIC_GET(&gc_;

View file

@ -60,7 +60,7 @@ static void Cyc_main (stack_size,heap_size,stack_base)
Cyc_heap = gc_heap_create(heap_size / 2, 0, 0); Cyc_heap = gc_heap_create(heap_size / 2, 0, 0);
//Cyc_heap = gc_heap_create(1024, 0, 0); //Cyc_heap = gc_heap_create(1024, 0, 0);
Cyc_thread = malloc(sizeof(gc_thread_data)); Cyc_thread = malloc(sizeof(gc_thread_data));
gc_thread_data_init(Cyc_thread); gc_thread_data_init(Cyc_thread, stack_base, stack_size);
// JAE TODO: clean up below (and all of this old code, really) // JAE TODO: clean up below (and all of this old code, really)

View file

@ -22,17 +22,15 @@
typedef void *object; typedef void *object;
/* Thread data structures */ /* Thread data structures */
typedef struct gc_thread_stack_t gc_thread_stack;
struct gc_thread_stack {
char *begin;
// TODO: move moveBuf stuff over here?
};
typedef struct gc_thread_data_t gc_thread_data; typedef struct gc_thread_data_t gc_thread_data;
struct gc_thread_data_t { struct gc_thread_data_t {
void **moveBuf; /* list of objects moved to heap during GC */ // Data needed for stack-based minor GC
char *stack_start;
char *stack_limit;
// List of objects moved to heap during minor GC
void **moveBuf;
int moveBufLen; int moveBufLen;
// Data needed for tri-color marking // Data needed for heap GC
int gc_alloc_color; int gc_alloc_color;
int gc_mut_status; int gc_mut_status;
int last_write; int last_write;
@ -118,7 +116,7 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr);
size_t 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_grow_move_buffer(gc_thread_data *d);
void gc_thr_add_to_move_buffer(gc_thread_data *d, int *alloci, object obj); void gc_thr_add_to_move_buffer(gc_thread_data *d, int *alloci, object obj);
void gc_thread_data_init(gc_thread_data *thd); void gc_thread_data_init(gc_thread_data *thd, char *stack_base, long stack_size);
void gc_thread_data_free(gc_thread_data *thd); void gc_thread_data_free(gc_thread_data *thd);
// Prototypes for mutator/collector: // Prototypes for mutator/collector:
void gc_mark_gray(gc_thread_data *thd, object obj); void gc_mark_gray(gc_thread_data *thd, object obj);

View file

@ -2594,7 +2594,7 @@ char *gc_move(char *obj, gc_thread_data *thd, int *alloci, int *heap_grown) {
temp = obj; \ temp = obj; \
if (check_overflow(low_limit, temp) && \ if (check_overflow(low_limit, temp) && \
check_overflow(temp, high_limit)){ \ check_overflow(temp, high_limit)){ \
(obj) = (object) gc_move(temp, Cyc_thread, &alloci, &heap_grown); \ (obj) = (object) gc_move(temp, (gc_thread_data *)data, &alloci, &heap_grown); \
} \ } \
} }
@ -2660,7 +2660,7 @@ void GC(void *data, closure cont, object *args, int num_args)
// Check allocated objects, moving additional objects as needed // Check allocated objects, moving additional objects as needed
while (scani < alloci) { while (scani < alloci) {
object obj = Cyc_thread->moveBuf[scani]; object obj = ((gc_thread_data *)data)->moveBuf[scani];
switch(type_of(obj)) { switch(type_of(obj)) {
case cons_tag: { case cons_tag: {
gc_move2heap(car(obj)); gc_move2heap(car(obj));