diff --git a/gc.c b/gc.c index 793ab4a8..28192de2 100644 --- a/gc.c +++ b/gc.c @@ -786,6 +786,18 @@ void gc_stack_mark_refs_gray(gc_thread_data *thd, object obj, int depth) } } +/** + * Determine if object lives on the thread's stack + */ +int gc_is_stack_obj(gc_thread_data *thd, object obj) +{ + char tmp; + object low_limit = &tmp; + object high_limit = thd->stack_start; + return (check_overflow(low_limit, obj) && + check_overflow(obj, high_limit)); +} + /** Write barrier for updates to heap-allocated objects Plans: @@ -804,8 +816,15 @@ void gc_mut_update(gc_thread_data *thd, object old_obj, object value) ////fprintf(stderr, " for heap object "); //fprintf(stderr, "\n"); gc_mark_gray(thd, old_obj); - // TODO: need this too??? - gc_stack_mark_gray(thd, value); +// TODO: check if value is on the heap, +// if so, mark gray right now +// otherwise set it to be marked after moved to heap during next GC + //gc_stack_mark_gray(thd, value); + if (gc_is_stack_obj(thd, value)) { + grayed(value) = 1; + } else { + gc_mark_gray(thd, value); + } } else if (stage == STAGE_TRACING) { //fprintf(stderr, "DEBUG - GC async tracing marking heap obj %p ", old_obj); //Cyc_display(old_obj, stderr); diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 7b74f290..3b6c85b6 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -95,11 +95,11 @@ struct gc_heap_t { typedef struct gc_header_type_t gc_header_type; struct gc_header_type_t { - //unsigned char mark; // mark bits (only need 2) unsigned int mark; // mark bits (only need 2) - // TODO: forwarding address (probably not needed for mark/sweep), anything else??? + unsigned char grayed; // stack object to be grayed when moved to heap }; #define mark(x) (((list) x)->hdr.mark) +#define grayed(x) (((list) x)->hdr.grayed) /* HEAP definitions */ // experimenting with a heap based off of the one in Chibi scheme @@ -158,6 +158,7 @@ void gc_thr_add_to_move_buffer(gc_thread_data *d, int *alloci, object obj); void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, long stack_size); void gc_thread_data_free(gc_thread_data *thd); // Prototypes for mutator/collector: +int gc_is_stack_obj(gc_thread_data *thd, object obj); void gc_mut_update(gc_thread_data *thd, object old_obj, object value); void gc_mut_cooperate(gc_thread_data *thd, int buf_len); void gc_stack_mark_refs_gray(gc_thread_data *thd, object obj, int depth);