mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-12 15:27:36 +02:00
Relocate setjmp code to runtime
This commit is contained in:
parent
e1063c4e19
commit
33abfc3bfa
6 changed files with 33 additions and 40 deletions
2
gc.c
2
gc.c
|
@ -675,7 +675,7 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon
|
|||
(1 - STACK_GROWS_DOWNWARD));
|
||||
exit(1);
|
||||
}
|
||||
thd->mutator_num = mut_num;
|
||||
//thd->mutator_num = mut_num;
|
||||
thd->jmp_start = malloc(sizeof(jmp_buf));
|
||||
thd->gc_args = malloc(sizeof(object) * NUM_GC_ANS);
|
||||
thd->gc_num_args = 0;
|
||||
|
|
|
@ -15,7 +15,6 @@ long global_stack_size = 0;
|
|||
long global_heap_size = 0;
|
||||
|
||||
static void c_entry_pt(void *,int,closure,closure);
|
||||
static void Cyc_main(long stack_size, char *stack_base);
|
||||
static void Cyc_heap_init(long heap_size);
|
||||
|
||||
static void Cyc_heap_init(long heap_size)
|
||||
|
@ -29,40 +28,8 @@ static void Cyc_heap_init(long heap_size)
|
|||
printf("main: Allocating and initializing heap...\n");
|
||||
#endif
|
||||
Cyc_heap = gc_heap_create(heap_size / 2, 0, 0);
|
||||
Cyc_num_mutators = 10; // TODO: alloca this using a vpbuffer, or maybe another type of data structure
|
||||
Cyc_mutators = malloc(sizeof(gc_thread_data *) * Cyc_num_mutators);
|
||||
Cyc_num_mutators = 1; // TODO: alloca this using a vpbuffer, or maybe another type of data structure
|
||||
}
|
||||
|
||||
TODO: relocate this to a runtime function (that accepts gc_thread_data and does the setjmp/dispatch, and
|
||||
to cgen (to setup a new gc_thread_data and call to the new function)
|
||||
|
||||
static void Cyc_main (long stack_size, char *stack_base)
|
||||
{
|
||||
mclosure0(clos_halt,&Cyc_halt); // Halt if final closure is reached
|
||||
mclosure0(entry_pt,&c_entry_pt); // First function to execute
|
||||
Cyc_mutators[0] = malloc(sizeof(gc_thread_data));
|
||||
gc_thread_data_init(Cyc_mutators[0], 0, stack_base, stack_size);
|
||||
|
||||
Cyc_mutators[0]->gc_cont = &entry_pt;
|
||||
Cyc_mutators[0]->gc_args[0] = &clos_halt;
|
||||
Cyc_mutators[0]->gc_num_args = 1;
|
||||
|
||||
/* Tank, load the jump program... */
|
||||
setjmp(*(Cyc_mutators[0]->jmp_start));
|
||||
// TODO: note, if longjmp is passed 0 it will return 1. need to
|
||||
// account for that there (add one to mut_num) and here (subtract 1 unless 0)
|
||||
#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_mutators[0]->gc_cont) == cons_tag || prim(Cyc_mutators[0]->gc_cont)) {
|
||||
Cyc_apply_from_buf(Cyc_mutators[0], Cyc_mutators[0]->gc_num_args, Cyc_mutators[0]->gc_cont, Cyc_mutators[0]->gc_args);
|
||||
} else {
|
||||
do_dispatch(Cyc_mutators[0], Cyc_mutators[0]->gc_num_args, ((closure)(Cyc_mutators[0]->gc_cont))->fn, Cyc_mutators[0]->gc_cont, Cyc_mutators[0]->gc_args);
|
||||
}
|
||||
|
||||
printf("Internal error: should never have reached this line\n"); exit(0);
|
||||
}
|
||||
|
||||
#endif /* CYCLONE_RUNTIME_MAIN_H */
|
||||
|
|
|
@ -181,7 +181,8 @@ object get(object,object);
|
|||
object equalp(object,object);
|
||||
object memberp(void *,object,list);
|
||||
object memqp(void *,object,list);
|
||||
char *transport(char *,int);
|
||||
|
||||
void Cyc_start_thread(gc_thread_data *thd);
|
||||
void GC(void *,closure,object*,int);
|
||||
|
||||
void Cyc_st_init();
|
||||
|
|
|
@ -45,7 +45,7 @@ struct gc_thread_data_t {
|
|||
void **moveBuf;
|
||||
int moveBufLen;
|
||||
// Need the following to perform longjmp's
|
||||
int mutator_num;
|
||||
//int mutator_num;
|
||||
jmp_buf *jmp_start;
|
||||
// After longjmp, pick up execution using continuation/arguments
|
||||
object gc_cont;
|
||||
|
|
22
runtime.c
22
runtime.c
|
@ -2343,6 +2343,25 @@ void Cyc_apply_from_buf(void *data, int argc, object prim, object *buf) {
|
|||
// longjmp(jmp_main,1); /* Return globals gc_cont, gc_ans. */
|
||||
//}
|
||||
|
||||
void Cyc_start_thread(gc_thread_data *thd)
|
||||
{
|
||||
/* Tank, load the jump program... */
|
||||
setjmp(*(thd->jmp_start));
|
||||
|
||||
#if DEBUG_GC
|
||||
printf("Done with GC\n");
|
||||
#endif
|
||||
|
||||
if (type_of(thd->gc_cont) == cons_tag || prim(thd->gc_cont)) {
|
||||
Cyc_apply_from_buf(thd, thd->gc_num_args, thd->gc_cont, thd->gc_args);
|
||||
} else {
|
||||
do_dispatch(thd, thd->gc_num_args, ((closure)(thd->gc_cont))->fn, thd->gc_cont, thd->gc_args);
|
||||
}
|
||||
|
||||
printf("Internal error: should never have reached this line\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Collect garbage using mark&sweep algorithm
|
||||
// Note non-global roots should be marked prior to calling this function.
|
||||
size_t gc_collect(gc_heap *h, size_t *sum_freed)
|
||||
|
@ -2727,8 +2746,7 @@ void GC(void *data, closure cont, object *args, int num_args)
|
|||
}
|
||||
|
||||
/* Let it all go, Neo... */
|
||||
longjmp(*(((gc_thread_data *)data)->jmp_start),
|
||||
(((gc_thread_data *)data)->mutator_num));
|
||||
longjmp(*(((gc_thread_data *)data)->jmp_start), 1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,10 +76,17 @@
|
|||
"main(int argc,char **argv)
|
||||
{long stack_size = global_stack_size = STACK_SIZE;
|
||||
long heap_size = global_heap_size = HEAP_SIZE;
|
||||
mclosure0(clos_halt,&Cyc_halt); // Halt if final closure is reached
|
||||
mclosure0(entry_pt,&c_entry_pt); // First function to execute
|
||||
_cyc_argc = argc;
|
||||
_cyc_argv = argv;
|
||||
Cyc_heap_init(heap_size);
|
||||
Cyc_main(stack_size, (char *) &stack_size);
|
||||
Cyc_mutators[0] = malloc(sizeof(gc_thread_data));
|
||||
gc_thread_data_init(Cyc_mutators[0], 0, (char *) &stack_size, stack_size);
|
||||
Cyc_mutators[0]->gc_cont = &entry_pt;
|
||||
Cyc_mutators[0]->gc_args[0] = &clos_halt;
|
||||
Cyc_mutators[0]->gc_num_args = 1;
|
||||
Cyc_start_thread(Cyc_mutators[0]);
|
||||
return 0;}")
|
||||
|
||||
;;; Auto-generation of C macros
|
||||
|
|
Loading…
Add table
Reference in a new issue