Added mutator cooperation function

This commit is contained in:
Justin Ethier 2015-11-12 22:33:34 -05:00
parent cb7274526c
commit 4bb24a4edd
3 changed files with 21 additions and 17 deletions

32
gc.c
View file

@ -514,25 +514,25 @@ void gc_mut_update()
// ideally want to do this without needing sync. we need to sync to get markColor in coop, though // ideally want to do this without needing sync. we need to sync to get markColor in coop, though
//void gc_mut_create() //void gc_mut_create()
// TODO: when is this called, is this good enough, etc?? // 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 i, status = ATOMIC_GET(&gc_status_col);
// !!!! if (thd->gc_status != status) {
// TODO: think about what else needs to be done here. for example, if (thd->gc_status == STATUS_ASYNC) {
// would want to reset last read/write at some point, to conserve // Async is done, so clean up old mark data from the last collection
// amount of memory being used by the mark buffers thd->last_write = 0;
thd->last_read = 0;
if (thd->gc_status == gc_status_col) { // TODO: synchronization of var access
if (thd->gc_status == STATUS_SYNC2) { // TODO: more sync??
// Since everything is on the stack, at this point probably only need
// to worry about anything on the stack that is referencing a heap object
// For each x in roots:
// MarkGray(x)
thd->gc_alloc_color = ATOMIC_GET(&gc_color_mark); // TODO: synchronization for global??
} }
thd->gc_status = gc_status_col; // TODO: syncronization?? else if (thd->gc_status == STATUS_SYNC2) {
// Mark thread "roots"
gc_mark_gray(thd, thd->gc_cont);
for (i = 0; i < thd->gc_num_args; i++) {
gc_mark_gray(thd, thd->gc_args[i]);
}
thd->gc_alloc_color = ATOMIC_GET(&gc_color_mark);
}
thd->gc_status = status;
} }
} }

View file

@ -142,6 +142,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_init(gc_thread_data *thd, int mut_num, 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_mut_cooperate(gc_thread_data *thd);
void gc_mark_gray(gc_thread_data *thd, object obj); void gc_mark_gray(gc_thread_data *thd, object obj);
void gc_collector_trace(); void gc_collector_trace();
void gc_mark_black(object obj); void gc_mark_black(object obj);

View file

@ -2764,7 +2764,10 @@ void GC(void *data, closure cont, object *args, int num_args)
//#endif //#endif
// } // }
/* Let it all go, Neo... */ // Cooperate with the collector thread
gc_mut_cooperate((gc_thread_data *)data);
// Let it all go, Neo...
longjmp(*(((gc_thread_data *)data)->jmp_start), 1); longjmp(*(((gc_thread_data *)data)->jmp_start), 1);
} }