Move the mutation table into thread data.

This commit is contained in:
Justin Ethier 2016-01-04 22:54:23 -05:00
parent c32cbdad9a
commit e28951a8d5
4 changed files with 24 additions and 17 deletions

4
gc.c
View file

@ -1199,6 +1199,7 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon
thd->stack_traces = calloc(MAX_STACK_TRACES, sizeof(char *)); thd->stack_traces = calloc(MAX_STACK_TRACES, sizeof(char *));
thd->stack_trace_idx = 0; thd->stack_trace_idx = 0;
thd->stack_prev_frame = NULL; thd->stack_prev_frame = NULL;
thd->mutations = NULL;
// thd->thread = NULL; // thd->thread = NULL;
thd->thread_state = CYC_THREAD_STATE_NEW; thd->thread_state = CYC_THREAD_STATE_NEW;
//thd->mutator_num = mut_num; //thd->mutator_num = mut_num;
@ -1234,6 +1235,9 @@ void gc_thread_data_free(gc_thread_data *thd)
if (thd->moveBuf) free(thd->moveBuf); if (thd->moveBuf) free(thd->moveBuf);
if (thd->mark_buffer) free(thd->mark_buffer); if (thd->mark_buffer) free(thd->mark_buffer);
if (thd->stack_traces) free(thd->stack_traces); if (thd->stack_traces) free(thd->stack_traces);
if (thd->mutations) {
clear_mutations(thd);
}
free(thd); free(thd);
} }
} }

View file

@ -211,10 +211,6 @@ object find_or_add_symbol(const char *name);
extern list global_table; extern list global_table;
void add_global(object *glo); void add_global(object *glo);
void add_mutation(object var, object value);
void clear_mutations();
extern list mutation_table;
void dispatch(void *data, int argc, function_type func, object clo, object cont, object args); void dispatch(void *data, int argc, function_type func, object clo, object cont, object args);
void dispatch_va(void *data, int argc, function_type_va func, object clo, object cont, object args); void dispatch_va(void *data, int argc, function_type_va func, object clo, object cont, object args);
void do_dispatch(void *data, int argc, function_type func, object clo, object *buffer); void do_dispatch(void *data, int argc, function_type func, object clo, object *buffer);

View file

@ -66,7 +66,8 @@ struct gc_thread_data_t {
// Data needed to initiate stack-based minor GC // Data needed to initiate stack-based minor GC
char *stack_start; char *stack_start;
char *stack_limit; char *stack_limit;
//TODO: store stack traces per thread // Minor GC write barrier
void *mutations;
// List of objects moved to heap during minor GC // List of objects moved to heap during minor GC
void **moveBuf; void **moveBuf;
int moveBufLen; int moveBufLen;
@ -452,4 +453,7 @@ void gc_mutator_thread_runnable(gc_thread_data *thd, object result);
gc_heap *gc_get_heap(); gc_heap *gc_get_heap();
int gc_minor(void *data, object low_limit, object high_limit, closure cont, object *args, int num_args); int gc_minor(void *data, object low_limit, object high_limit, closure cont, object *args, int num_args);
void add_mutation(void *data, object var, object value);
void clear_mutations(void *data);
#endif /* CYCLONE_TYPES_H */ #endif /* CYCLONE_TYPES_H */

View file

@ -312,30 +312,33 @@ void debug_dump_globals()
/* END Global table */ /* END Global table */
/* Mutation table /* Mutation table functions
* *
* Keep track of mutations (EG: set-car!) so that new * Keep track of mutations (EG: set-car!) so that new
* values are transported to the heap during GC. * values are transported to the heap during GC.
* Note these functions and underlying data structure are only used by
* the calling thread, so locking is not required.
*/ */
list mutation_table = nil;
void add_mutation(object var, object value){ void add_mutation(void *data, object var, object value){
gc_thread_data *thd = (gc_thread_data *)data;
if (is_object_type(value)) { if (is_object_type(value)) {
mutation_table = mcons(var, mutation_table); thd->mutations = mcons(var, thd->mutations);
} }
} }
/* TODO: consider a more efficient implementation, such as reusing old nodes /* TODO: consider a more efficient implementation, such as reusing old nodes
instead of reclaiming them each time instead of reclaiming them each time
*/ */
void clear_mutations() { void clear_mutations(void *data) {
list l = mutation_table, next; gc_thread_data *thd = (gc_thread_data *)data;
list l = thd->mutations, next;
while (!nullp(l)) { while (!nullp(l)) {
next = cdr(l); next = cdr(l);
free(l); free(l);
l = next; l = next;
} }
mutation_table = nil; thd->mutations = nil;
} }
/* END mutation table */ /* END mutation table */
@ -897,7 +900,7 @@ object Cyc_set_car(void *data, object l, object val) {
if (Cyc_is_cons(l) == boolean_f) Cyc_invalid_type_error(data, cons_tag, l); if (Cyc_is_cons(l) == boolean_f) Cyc_invalid_type_error(data, cons_tag, l);
gc_mut_update((gc_thread_data *)data, car(l), val); gc_mut_update((gc_thread_data *)data, car(l), val);
car(l) = val; car(l) = val;
add_mutation(l, val); add_mutation(data, l, val);
return l; return l;
} }
@ -905,7 +908,7 @@ object Cyc_set_cdr(void *data, object l, object val) {
if (Cyc_is_cons(l) == boolean_f) Cyc_invalid_type_error(data, cons_tag, l); if (Cyc_is_cons(l) == boolean_f) Cyc_invalid_type_error(data, cons_tag, l);
gc_mut_update((gc_thread_data *)data, cdr(l), val); gc_mut_update((gc_thread_data *)data, cdr(l), val);
cdr(l) = val; cdr(l) = val;
add_mutation(l, val); add_mutation(data, l, val);
return l; return l;
} }
@ -926,7 +929,7 @@ object Cyc_vector_set(void *data, object v, object k, object obj) {
((vector)v)->elts[idx] = obj; ((vector)v)->elts[idx] = obj;
// TODO: probably could be more efficient here and also pass // TODO: probably could be more efficient here and also pass
// index, so only that one entry needs GC. // index, so only that one entry needs GC.
add_mutation(v, obj); add_mutation(data, v, obj);
return v; return v;
} }
@ -2366,7 +2369,7 @@ int gc_minor(void *data, object low_limit, object high_limit, closure cont, obje
// Transport mutations // Transport mutations
{ {
list l; list l;
for (l = mutation_table; !nullp(l); l = cdr(l)) { for (l = ((gc_thread_data *)data)->mutations; !nullp(l); l = cdr(l)) {
object o = car(l); object o = car(l);
if (type_of(o) == cons_tag) { if (type_of(o) == cons_tag) {
gc_move2heap(car(o)); gc_move2heap(car(o));
@ -2385,7 +2388,7 @@ int gc_minor(void *data, object low_limit, object high_limit, closure cont, obje
} }
} }
} }
clear_mutations(); // Reset for next time clear_mutations(data); // Reset for next time
// Transport globals // Transport globals
gc_move2heap(Cyc_global_variables); // Internal global used by the runtime gc_move2heap(Cyc_global_variables); // Internal global used by the runtime