From 4bb24a4eddb5b6b944b5bf172adca7a376e62bc2 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 12 Nov 2015 22:33:34 -0500 Subject: [PATCH] Added mutator cooperation function --- gc.c | 32 ++++++++++++++++---------------- include/cyclone/types.h | 1 + runtime.c | 5 ++++- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/gc.c b/gc.c index 4c0925e4..a35e8554 100644 --- a/gc.c +++ b/gc.c @@ -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 //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) { - -// !!!! -// TODO: think about what else needs to be done here. for example, -// would want to reset last read/write at some point, to conserve -// amount of memory being used by the mark buffers - - - 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?? + int i, status = ATOMIC_GET(&gc_status_col); + if (thd->gc_status != status) { + if (thd->gc_status == STATUS_ASYNC) { + // Async is done, so clean up old mark data from the last collection + thd->last_write = 0; + thd->last_read = 0; } - 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; } } diff --git a/include/cyclone/types.h b/include/cyclone/types.h index a1bfc527..4f6a7c1e 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -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_free(gc_thread_data *thd); // Prototypes for mutator/collector: +void gc_mut_cooperate(gc_thread_data *thd); void gc_mark_gray(gc_thread_data *thd, object obj); void gc_collector_trace(); void gc_mark_black(object obj); diff --git a/runtime.c b/runtime.c index c5d7332b..9b2f48c8 100644 --- a/runtime.c +++ b/runtime.c @@ -2764,7 +2764,10 @@ void GC(void *data, closure cont, object *args, int num_args) //#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); }