New approach to stack graying from write barrier

This commit is contained in:
Justin Ethier 2015-12-06 22:37:08 -05:00
parent 3d0d966e6d
commit 9ded782a06
2 changed files with 24 additions and 4 deletions

23
gc.c
View file

@ -786,6 +786,18 @@ void gc_stack_mark_refs_gray(gc_thread_data *thd, object obj, int depth)
} }
} }
/**
* Determine if object lives on the thread's stack
*/
int gc_is_stack_obj(gc_thread_data *thd, object obj)
{
char tmp;
object low_limit = &tmp;
object high_limit = thd->stack_start;
return (check_overflow(low_limit, obj) &&
check_overflow(obj, high_limit));
}
/** /**
Write barrier for updates to heap-allocated objects Write barrier for updates to heap-allocated objects
Plans: Plans:
@ -804,8 +816,15 @@ void gc_mut_update(gc_thread_data *thd, object old_obj, object value)
////fprintf(stderr, " for heap object "); ////fprintf(stderr, " for heap object ");
//fprintf(stderr, "\n"); //fprintf(stderr, "\n");
gc_mark_gray(thd, old_obj); gc_mark_gray(thd, old_obj);
// TODO: need this too??? // TODO: check if value is on the heap,
gc_stack_mark_gray(thd, value); // if so, mark gray right now
// otherwise set it to be marked after moved to heap during next GC
//gc_stack_mark_gray(thd, value);
if (gc_is_stack_obj(thd, value)) {
grayed(value) = 1;
} else {
gc_mark_gray(thd, value);
}
} else if (stage == STAGE_TRACING) { } else if (stage == STAGE_TRACING) {
//fprintf(stderr, "DEBUG - GC async tracing marking heap obj %p ", old_obj); //fprintf(stderr, "DEBUG - GC async tracing marking heap obj %p ", old_obj);
//Cyc_display(old_obj, stderr); //Cyc_display(old_obj, stderr);

View file

@ -95,11 +95,11 @@ struct gc_heap_t {
typedef struct gc_header_type_t gc_header_type; typedef struct gc_header_type_t gc_header_type;
struct gc_header_type_t { struct gc_header_type_t {
//unsigned char mark; // mark bits (only need 2)
unsigned int mark; // mark bits (only need 2) unsigned int mark; // mark bits (only need 2)
// TODO: forwarding address (probably not needed for mark/sweep), anything else??? unsigned char grayed; // stack object to be grayed when moved to heap
}; };
#define mark(x) (((list) x)->hdr.mark) #define mark(x) (((list) x)->hdr.mark)
#define grayed(x) (((list) x)->hdr.grayed)
/* HEAP definitions */ /* HEAP definitions */
// experimenting with a heap based off of the one in Chibi scheme // experimenting with a heap based off of the one in Chibi scheme
@ -158,6 +158,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:
int gc_is_stack_obj(gc_thread_data *thd, object obj);
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, int buf_len); 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);