From 5823b37b5df32c545c1a187d6c0a506bd9dad760 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 11 Jan 2017 18:45:28 +0000 Subject: [PATCH] WIP --- gc.c | 20 +++----------- include/cyclone/types.h | 58 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/gc.c b/gc.c index b04a8aef..3b24f81c 100644 --- a/gc.c +++ b/gc.c @@ -1183,18 +1183,6 @@ void gc_collector_trace() } } -// "Color" objects gray by adding them to the mark stack for further processing. -// -// Note that stack objects are always colored red during creation, so -// they should never be added to the mark stack. Which would be bad because it -// could lead to stack corruption. -// -// Attempt to speed this up by forcing an inline -// -#define gc_collector_mark_gray(parent, gobj) \ - if (is_object_type(gobj) && mark(gobj) == gc_color_clear) { \ - mark_stack = vpbuffer_add(mark_stack, &mark_stack_len, mark_stack_i++, gobj); \ - } //static void gc_collector_mark_gray(object parent, object obj) //{ // if (is_object_type(obj) && mark(obj) == gc_color_clear) { @@ -1206,10 +1194,7 @@ void gc_collector_trace() // } //} -// TODO: seriously consider changing the mark() macro to color(), -// and sync up the header variable. that would make all of this code -// bit clearer... - +/* void gc_mark_black(object obj) { // TODO: is sync required to get colors? probably not on the collector @@ -1267,6 +1252,7 @@ void gc_mark_black(object obj) #endif } } +*/ void gc_empty_collector_stack() { @@ -1412,6 +1398,8 @@ void gc_collector() #if GC_DEBUG_TRACE fprintf(stderr, "DEBUG - after post_handshake async\n"); #endif + +TODO: call into shim in runtime, that will call back into gc_mark_globals in this module, but with global objs as parameters. this should allow us to explicitly inline all instances of gc_mark_black since they would now be in this module. and of course, none of the changes on this branch matter if they don't actually speed anything up, so need to measure that once it compiles! gc_mark_globals(); gc_wait_handshake(); #if GC_DEBUG_TRACE diff --git a/include/cyclone/types.h b/include/cyclone/types.h index c16db957..2dd946c7 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -684,7 +684,6 @@ void gc_mut_cooperate(gc_thread_data * thd, int buf_len); void gc_mark_gray(gc_thread_data * thd, object obj); void gc_mark_gray2(gc_thread_data * thd, object obj); void gc_collector_trace(); -void gc_mark_black(object obj); void gc_empty_collector_stack(); void gc_handshake(gc_status_type s); void gc_post_handshake(gc_status_type s); @@ -709,4 +708,61 @@ int gc_minor(void *data, object low_limit, object high_limit, closure cont, void add_mutation(void *data, object var, int index, object value); void clear_mutations(void *data); +// "Color" objects gray by adding them to the mark stack for further processing. +// +// Note that stack objects are always colored red during creation, so +// they should never be added to the mark stack. Which would be bad because it +// could lead to stack corruption. +// +// Attempt to speed this up by forcing an inline +// +#define gc_collector_mark_gray(parent, gobj) \ + if (is_object_type(gobj) && mark(gobj) == gc_color_clear) { \ + mark_stack = vpbuffer_add(mark_stack, &mark_stack_len, mark_stack_i++, gobj); \ + } + +#define gc_mark_black(obj) \ +{ \ + int markColor = ck_pr_load_int(&gc_color_mark); \ + if (is_object_type(obj) && mark(obj) != markColor) { \ + switch (type_of(obj)) { \ + case pair_tag:{ \ + gc_collector_mark_gray(obj, car(obj)); \ + gc_collector_mark_gray(obj, cdr(obj)); \ + break; \ + } \ + case closure1_tag: \ + gc_collector_mark_gray(obj, ((closure1) obj)->element); \ + break; \ + case closureN_tag:{ \ + int i, n = ((closureN) obj)->num_elements; \ + for (i = 0; i < n; i++) { \ + gc_collector_mark_gray(obj, ((closureN) obj)->elements[i]); \ + } \ + break; \ + } \ + case vector_tag:{ \ + int i, n = ((vector) obj)->num_elements; \ + for (i = 0; i < n; i++) { \ + gc_collector_mark_gray(obj, ((vector) obj)->elements[i]); \ + } \ + break; \ + } \ + case cvar_tag:{ \ + cvar_type *c = (cvar_type *) obj; \ + object pvar = *(c->pvar); \ + if (pvar) { \ + gc_collector_mark_gray(obj, pvar); \ + } \ + break; \ + } \ + default: \ + break; \ + } \ + if (mark(obj) != gc_color_red) { \ + mark(obj) = markColor; \ + } \ + } \ +} + #endif /* CYCLONE_TYPES_H */