Changed GC cooperation

Mark all objects moved to the heap, instead of just the typical roots.
This commit is contained in:
Justin Ethier 2015-12-05 22:44:06 -05:00
parent 0946d56aaa
commit 3d0d966e6d
3 changed files with 18 additions and 13 deletions

25
gc.c
View file

@ -850,7 +850,7 @@ void gc_mut_update(gc_thread_data *thd, object old_obj, object value)
} }
// TODO: still need to handle case where a mutator is blocked // TODO: still need to handle case where a mutator is blocked
void gc_mut_cooperate(gc_thread_data *thd) void gc_mut_cooperate(gc_thread_data *thd, int buf_len)
{ {
int i, status = ATOMIC_GET(&gc_status_col); int i, status = ATOMIC_GET(&gc_status_col);
if (thd->gc_status != status) { if (thd->gc_status != status) {
@ -863,18 +863,23 @@ void gc_mut_cooperate(gc_thread_data *thd)
} }
else if (thd->gc_status == STATUS_SYNC2) { else if (thd->gc_status == STATUS_SYNC2) {
// Mark thread "roots" // Mark thread "roots"
// TODO: below is efficient, but is there a chance we are missing anything by // In this case, mark everything the collector moved to the heap
// doing this instead of marking the objects in moveBuf?? for (i = 0; i < buf_len; i++) {
gc_mark_gray(thd, thd->moveBuf[i]);
#if GC_DEBUG_VERBOSE #if GC_DEBUG_VERBOSE
fprintf(stderr, "gc_cont %p\n", thd->gc_cont); fprintf(stderr, "mark from move buf %i %p\n", i, thd->moveBuf[i]);
#endif #endif
gc_mark_gray(thd, thd->gc_cont);
for (i = 0; i < thd->gc_num_args; i++) {
#if GC_DEBUG_VERBOSE
fprintf(stderr, "gc_args[%d] %p\n", i, thd->gc_args[i]);
#endif
gc_mark_gray(thd, thd->gc_args[i]);
} }
//#if GC_DEBUG_VERBOSE
//fprintf(stderr, "gc_cont %p\n", thd->gc_cont);
//#endif
// gc_mark_gray(thd, thd->gc_cont);
// for (i = 0; i < thd->gc_num_args; i++) {
//#if GC_DEBUG_VERBOSE
//fprintf(stderr, "gc_args[%d] %p\n", i, thd->gc_args[i]);
//#endif
// gc_mark_gray(thd, thd->gc_args[i]);
// }
thd->gc_alloc_color = ATOMIC_GET(&gc_color_mark); thd->gc_alloc_color = ATOMIC_GET(&gc_color_mark);
} }
thd->gc_status = status; thd->gc_status = status;

View file

@ -159,7 +159,7 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon
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_mut_update(gc_thread_data *thd, object old_obj, object value); void gc_mut_update(gc_thread_data *thd, object old_obj, object value);
void gc_mut_cooperate(gc_thread_data *thd); 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); void gc_stack_mark_refs_gray(gc_thread_data *thd, object obj, int depth);
void gc_stack_mark_gray(gc_thread_data *thd, object obj); void gc_stack_mark_gray(gc_thread_data *thd, object obj);
void gc_mark_gray(gc_thread_data *thd, object obj); void gc_mark_gray(gc_thread_data *thd, object obj);

View file

@ -2582,7 +2582,7 @@ void GC(void *data, closure cont, object *args, int num_args)
object low_limit = &tmp; // This is one end of the stack... object low_limit = &tmp; // This is one end of the stack...
object high_limit = ((gc_thread_data *)data)->stack_start; object high_limit = ((gc_thread_data *)data)->stack_start;
int i; int i;
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 scani = 0, alloci = 0;
int heap_grown = 0; int heap_grown = 0;
//fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG //fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG
@ -2697,7 +2697,7 @@ void GC(void *data, closure cont, object *args, int num_args)
} }
// Cooperate with the collector thread // Cooperate with the collector thread
gc_mut_cooperate((gc_thread_data *)data); gc_mut_cooperate((gc_thread_data *)data, alloci);
#if GC_DEBUG_TRACE #if GC_DEBUG_TRACE
fprintf(stderr, "done with minor GC\n"); fprintf(stderr, "done with minor GC\n");