Use mutator number instead of casting pointer to an int

This commit is contained in:
Justin Ethier 2015-11-06 20:28:27 -05:00
parent 23453d264b
commit 9219279613
5 changed files with 30 additions and 19 deletions

3
gc.c
View file

@ -660,7 +660,7 @@ void gc_empty_collector_stack()
// Initialize runtime data structures for a thread.
// Must be called on the target thread itself during startup,
// to verify stack limits are setup correctly.
void gc_thread_data_init(gc_thread_data *thd, char *stack_base, long stack_size)
void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, long stack_size)
{
char stack_ref;
thd->stack_start = stack_base;
@ -675,6 +675,7 @@ void gc_thread_data_init(gc_thread_data *thd, char *stack_base, long stack_size)
(1 - STACK_GROWS_DOWNWARD));
exit(1);
}
thd->mutator_num = mut_num;
thd->jmp_start = malloc(sizeof(jmp_buf));
thd->gc_ans = malloc(sizeof(object) * NUM_GC_ANS);
thd->gc_num_ans = 0;

View file

@ -36,24 +36,34 @@ static void Cyc_main (stack_size,heap_size,stack_base)
#endif
Cyc_heap = gc_heap_create(heap_size / 2, 0, 0);
Cyc_thread = malloc(sizeof(gc_thread_data));
gc_thread_data_init(Cyc_thread, stack_base, stack_size);
Cyc_num_mutators = 1; // TODO: alloca this using a vpbuffer, or maybe another type of data structure
Cyc_mutators = malloc(sizeof(gc_thread_data *) * Cyc_num_mutators);
// TODO: from here, break this out into a separate function that
// could spin up additional threads
// would need mutator_num, stack args.
// don't want to waste stack space though, so maybe inits above
// get moved to the caller of Cyc_main, and Cyc_main becomes
// that separate function
// int mutator_num = 0;
Cyc_mutators[0] = malloc(sizeof(gc_thread_data));
gc_thread_data_init(Cyc_mutators[0], 0, stack_base, stack_size);
Cyc_thread->gc_cont = &entry_pt;
Cyc_thread->gc_ans[0] = &clos_halt;
Cyc_thread->gc_num_ans = 1;
Cyc_mutators[0]->gc_cont = &entry_pt;
Cyc_mutators[0]->gc_ans[0] = &clos_halt;
Cyc_mutators[0]->gc_num_ans = 1;
/* Tank, load the jump program... */
setjmp(*(Cyc_thread->jmp_start));
setjmp(*(Cyc_mutators[0]->jmp_start));
#if DEBUG_GC
printf("Done with GC\n");
#endif
// JAE - note for the general case, setjmp will return the data pointer's addy
if (type_of(Cyc_thread->gc_cont) == cons_tag || prim(Cyc_thread->gc_cont)) {
Cyc_apply_from_buf(Cyc_thread, Cyc_thread->gc_num_ans, Cyc_thread->gc_cont, Cyc_thread->gc_ans);
if (type_of(Cyc_mutators[0]->gc_cont) == cons_tag || prim(Cyc_mutators[0]->gc_cont)) {
Cyc_apply_from_buf(Cyc_mutators[0], Cyc_mutators[0]->gc_num_ans, Cyc_mutators[0]->gc_cont, Cyc_mutators[0]->gc_ans);
} else {
do_dispatch(Cyc_thread, Cyc_thread->gc_num_ans, ((closure)(Cyc_thread->gc_cont))->fn, Cyc_thread->gc_cont, Cyc_thread->gc_ans);
do_dispatch(Cyc_mutators[0], Cyc_mutators[0]->gc_num_ans, ((closure)(Cyc_mutators[0]->gc_cont))->fn, Cyc_mutators[0]->gc_cont, Cyc_mutators[0]->gc_ans);
}
printf("Internal error: should never have reached this line\n"); exit(0);}}

View file

@ -208,7 +208,8 @@ void do_dispatch(void *data, int argc, function_type func, object clo, object *b
/* Global variables. */
extern gc_heap *Cyc_heap;
extern gc_thread_data *Cyc_thread;
extern gc_thread_data **Cyc_mutators;
extern int Cyc_num_mutators;
extern long no_gcs; /* Count the number of GC's. */
extern long no_major_gcs; /* Count the number of GC's. */

View file

@ -40,6 +40,8 @@ struct gc_thread_data_t {
// Data needed for stack-based minor GC
char *stack_start;
char *stack_limit;
// Need the following to perform longjmp's
int mutator_num;
jmp_buf *jmp_start;
object gc_cont;
object *gc_ans;
@ -133,7 +135,7 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr);
size_t gc_collect(gc_heap *h, size_t *sum_freed);
void gc_thr_grow_move_buffer(gc_thread_data *d);
void gc_thr_add_to_move_buffer(gc_thread_data *d, int *alloci, object obj);
void gc_thread_data_init(gc_thread_data *thd, 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);
// Prototypes for mutator/collector:
void gc_mark_gray(gc_thread_data *thd, object obj);

View file

@ -80,7 +80,8 @@ void Cyc_check_bounds(void *data, const char *label, int len, int index) {
/* Global variables. */
gc_heap *Cyc_heap;
gc_thread_data *Cyc_thread;
gc_thread_data **Cyc_mutators;
int Cyc_num_mutators;
long no_gcs = 0; /* Count the number of GC's. */
long no_major_gcs = 0; /* Count the number of GC's. */
@ -2726,12 +2727,8 @@ void GC(void *data, closure cont, object *args, int num_args)
}
/* Let it all go, Neo... */
// TODO: apparently it is a bad idea to cast a pointer to an int on 64 bit platforms
// as a pointer may be larger than an int. so need to figure out another technique
// here to communicate back to the setjmp which data to use. need to store a data
// structure of thread buffers for heap gc, so maybe be able to use an int to index
// into that.
longjmp(*(((gc_thread_data *)data)->jmp_start), (int)(&data)); // Return globals gc_cont, gc_ans
longjmp(*(((gc_thread_data *)data)->jmp_start),
(((gc_thread_data *)data)->mutator_num));
}