diff --git a/src/mzscheme/gc2/compact.c b/src/mzscheme/gc2/compact.c index aa034d904a..f3aba0d8c2 100644 --- a/src/mzscheme/gc2/compact.c +++ b/src/mzscheme/gc2/compact.c @@ -2829,7 +2829,7 @@ static void init(void) #if USE_FREELIST GC_register_traversers(gc_on_free_list_tag, size_on_free_list, size_on_free_list, size_on_free_list, 0, 0); #endif - GC_add_roots(&finalizers, (char *)&finalizers + sizeof(finalizers) + 1); + GC_add_roots(&GC->finalizers, (char *)&GC->finalizers + sizeof(GC->finalizers) + 1); GC_add_roots(&fnl_weaks, (char *)&fnl_weaks + sizeof(fnl_weaks) + 1); GC_add_roots(&run_queue, (char *)&run_queue + sizeof(run_queue) + 1); GC_add_roots(&last_in_queue, (char *)&last_in_queue + sizeof(last_in_queue) + 1); @@ -3049,7 +3049,7 @@ static void gcollect(int full) { Fnl *f; - for (f = finalizers; f; f = f->next) { + for (f = GC->finalizers; f; f = f->next) { #if RECORD_MARK_SRC mark_src = f; mark_type = MTYPE_FINALIZER; @@ -3108,7 +3108,7 @@ static void gcollect(int full) /* Propagate all marks. */ propagate_all_mpages(); - if ((did_fnls >= 3) || !finalizers) { + if ((did_fnls >= 3) || !GC->finalizers) { if (did_fnls == 3) { /* Finish up ordered finalization */ Fnl *f, *next, *prev; @@ -3117,7 +3117,7 @@ static void gcollect(int full) /* Enqueue and mark level 3 finalizers that still haven't been marked. */ /* (Recursive marking is already done, though.) */ prev = NULL; - for (f = finalizers; f; f = next) { + for (f = GC->finalizers; f; f = next) { next = f->next; if (f->eager_level == 3) { if (!is_marked(f->p)) { @@ -3131,7 +3131,7 @@ static void gcollect(int full) if (prev) prev->next = next; else - finalizers = next; + GC->finalizers = next; f->eager_level = 0; /* indicates queued */ @@ -3193,7 +3193,7 @@ static void gcollect(int full) /* Mark content of not-yet-marked finalized objects, but don't mark the finalized objects themselves. */ - for (f = finalizers; f; f = f->next) { + for (f = GC->finalizers; f; f = f->next) { if (f->eager_level == 3) { #if RECORD_MARK_SRC mark_src = f; @@ -3219,7 +3219,7 @@ static void gcollect(int full) /* Unordered finalization */ Fnl *f, *prev, *queue; - f = finalizers; + f = GC->finalizers; prev = NULL; queue = NULL; @@ -3232,7 +3232,7 @@ static void gcollect(int full) if (prev) prev->next = next; else - finalizers = next; + GC->finalizers = next; f->eager_level = 0; /* indicates queued */ @@ -3408,7 +3408,7 @@ static void gcollect(int full) { Fnl *f; - for (f = finalizers; f; f = f->next) { + for (f = GC->finalizers; f; f = f->next) { #if CHECKS fnl_count++; #endif @@ -3524,7 +3524,7 @@ static void gcollect(int full) run_queue = run_queue->next; if (!run_queue) last_in_queue = NULL; - --num_fnls; + --GC->num_fnls; gcs = GC_variable_stack; f->f(f->p, f->data); @@ -4700,7 +4700,7 @@ void GC_dump_with_traces(int flags, } } - GCPRINT(GCOUTF, "Active fnls: %d\n", num_fnls); + GCPRINT(GCOUTF, "Active fnls: %d\n", GC->num_fnls); GCPRINT(GCOUTF, "Active fnl weak links: %d\n", fnl_weak_link_count); if (memory_in_use > max_memory_use) diff --git a/src/mzscheme/gc2/compactgc_internal.h b/src/mzscheme/gc2/compactgc_internal.h index ed387700fd..e112989442 100644 --- a/src/mzscheme/gc2/compactgc_internal.h +++ b/src/mzscheme/gc2/compactgc_internal.h @@ -1,6 +1,11 @@ #include "commongc_internal.h" typedef struct CompactGC { + /* Common with NewGC */ + Fnl *finalizers; + Fnl *splayed_finalizers; + int num_fnls; + void *park[2]; void *park_save[2]; diff --git a/src/mzscheme/gc2/fnls.c b/src/mzscheme/gc2/fnls.c index b0cf1c2aa2..00a13d3974 100644 --- a/src/mzscheme/gc2/fnls.c +++ b/src/mzscheme/gc2/fnls.c @@ -11,9 +11,6 @@ park */ -static Fnl *finalizers, *splayed_finalizers; -static int num_fnls; - #define Tree Fnl #define Splay_Item(t) ((unsigned long)t->p) #define Set_Splay_Item(t, v) (t)->p = (void *)v @@ -26,8 +23,8 @@ static int num_fnls; #undef splay_delete void GC_set_finalizer(void *p, int tagged, int level, void (*f)(void *p, void *data), - void *data, void (**oldf)(void *p, void *data), - void **olddata) + void *data, void (**oldf)(void *p, void *data), + void **olddata) { Fnl *fnl; @@ -38,8 +35,8 @@ void GC_set_finalizer(void *p, int tagged, int level, void (*f)(void *p, void *d return; } - splayed_finalizers = fnl_splay((unsigned long)p, splayed_finalizers); - fnl = splayed_finalizers; + GC->splayed_finalizers = fnl_splay((unsigned long)p, GC->splayed_finalizers); + fnl = GC->splayed_finalizers; if (fnl && (fnl->p == p)) { if (oldf) *oldf = fnl->f; if (olddata) *olddata = fnl->data; @@ -48,18 +45,20 @@ void GC_set_finalizer(void *p, int tagged, int level, void (*f)(void *p, void *d fnl->data = data; fnl->eager_level = level; } else { + /* remove finalizer */ if (fnl->prev) - fnl->prev->next = fnl->next; + fnl->prev->next = fnl->next; else - finalizers = fnl->next; + GC->finalizers = fnl->next; if (fnl->next) - fnl->next->prev = fnl->prev; - --num_fnls; - splayed_finalizers = fnl_splay_delete((unsigned long)p, splayed_finalizers); + fnl->next->prev = fnl->prev; + + --GC->num_fnls; + GC->splayed_finalizers = fnl_splay_delete((unsigned long)p, GC->splayed_finalizers); } return; } - + if (oldf) *oldf = NULL; if (olddata) *olddata = NULL; @@ -78,11 +77,6 @@ void GC_set_finalizer(void *p, int tagged, int level, void (*f)(void *p, void *d GC->park[0] = NULL; GC->park[1] = NULL; - fnl->next = finalizers; - fnl->prev = NULL; - if (finalizers) { - finalizers->prev = fnl; - } fnl->p = p; fnl->f = f; @@ -98,41 +92,49 @@ void GC_set_finalizer(void *p, int tagged, int level, void (*f)(void *p, void *d if (tagged) { if (m->type != MTYPE_TAGGED) { - GCPRINT(GCOUTF, "Not tagged: %lx (%d)\n", - (long)p, m->type); - CRASH(4); + GCPRINT(GCOUTF, "Not tagged: %lx (%d)\n", + (long)p, m->type); + CRASH(4); } } else { if (m->type != MTYPE_XTAGGED) { - GCPRINT(GCOUTF, "Not xtagged: %lx (%d)\n", - (long)p, m->type); - CRASH(5); + GCPRINT(GCOUTF, "Not xtagged: %lx (%d)\n", + (long)p, m->type); + CRASH(5); } if (m->flags & MFLAG_BIGBLOCK) - fnl->size = m->u.size; + fnl->size = m->u.size; else - fnl->size = ((long *)p)[-1]; + fnl->size = ((long *)p)[-1]; } } #endif - finalizers = fnl; - splayed_finalizers = fnl_splay_insert((unsigned long)p, fnl, splayed_finalizers); + /* push finalizer */ + fnl->next = GC->finalizers; + fnl->prev = NULL; + if (GC->finalizers) { + GC->finalizers->prev = fnl; + } + GC->finalizers = fnl; - num_fnls++; + GC->splayed_finalizers = fnl_splay_insert((unsigned long)p, fnl, GC->splayed_finalizers); + + GC->num_fnls++; } static void reset_finalizer_tree() /* After a GC, rebuild the splay tree, since object addresses have moved. */ { - Fnl *fnl, *prev = NULL; + Fnl *fnl; + Fnl *prev = NULL; - splayed_finalizers = NULL; + GC->splayed_finalizers = NULL; - for (fnl = finalizers; fnl; fnl = fnl->next) { + for (fnl = GC->finalizers; fnl; fnl = fnl->next) { fnl->prev = prev; - splayed_finalizers = fnl_splay_insert((unsigned long)fnl->p, fnl, splayed_finalizers); + GC->splayed_finalizers = fnl_splay_insert((unsigned long)fnl->p, fnl, GC->splayed_finalizers); prev = fnl; } } diff --git a/src/mzscheme/gc2/newgc.c b/src/mzscheme/gc2/newgc.c index c9c3edf6c3..94dd514360 100644 --- a/src/mzscheme/gc2/newgc.c +++ b/src/mzscheme/gc2/newgc.c @@ -975,10 +975,10 @@ inline static void mark_finalizer_structs(void) { Fnl *fnl; - for(fnl = GC_resolve(finalizers); fnl; fnl = GC_resolve(fnl->next)) { + for(fnl = GC_resolve(GC->finalizers); fnl; fnl = GC_resolve(fnl->next)) { set_backtrace_source(fnl, BT_FINALIZER); gcMARK(fnl->data); - set_backtrace_source(&finalizers, BT_ROOT); + set_backtrace_source(&GC->finalizers, BT_ROOT); gcMARK(fnl); } for(fnl = GC->run_queue; fnl; fnl = fnl->next) { @@ -995,9 +995,9 @@ inline static void repair_finalizer_structs(void) Fnl *fnl; /* repair the base parts of the list */ - gcFIXUP(finalizers); gcFIXUP(GC->run_queue); + gcFIXUP(GC->finalizers); gcFIXUP(GC->run_queue); /* then repair the stuff inside them */ - for(fnl = finalizers; fnl; fnl = fnl->next) { + for(fnl = GC->finalizers; fnl; fnl = fnl->next) { gcFIXUP(fnl->data); gcFIXUP(fnl->p); gcFIXUP(fnl->next); @@ -1011,7 +1011,7 @@ inline static void repair_finalizer_structs(void) inline static void check_finalizers(int level) { - Fnl *work = GC_resolve(finalizers); + Fnl *work = GC_resolve(GC->finalizers); Fnl *prev = NULL; GCDEBUG((DEBUGOUTF, "CFNL: Checking level %i finalizers\n", level)); @@ -1025,11 +1025,11 @@ inline static void check_finalizers(int level) set_backtrace_source(work, BT_FINALIZER); gcMARK(work->p); if(prev) prev->next = next; - if(!prev) finalizers = next; + if(!prev) GC->finalizers = next; if(GC->last_in_queue) GC->last_in_queue = GC->last_in_queue->next = work; if(!GC->last_in_queue) GC->run_queue = GC->last_in_queue = work; work->next = NULL; - --num_fnls; + --GC->num_fnls; work = next; } else { @@ -1047,7 +1047,7 @@ inline static void do_ordered_level3(void) struct finalizer *temp; Mark_Proc *mark_table = GC->mark_table; - for(temp = GC_resolve(finalizers); temp; temp = GC_resolve(temp->next)) + for(temp = GC_resolve(GC->finalizers); temp; temp = GC_resolve(temp->next)) if(!marked(temp->p)) { GCDEBUG((DEBUGOUTF, "LVL3: %p is not marked. Marking payload (%p)\n", @@ -1839,7 +1839,7 @@ void GC_dump_with_traces(int flags, GC->actual_pages_size - (GC->used_pages * APAGE_SIZE))); GCWARN((GCOUTF,"# of major collections: %li\n", GC->num_major_collects)); GCWARN((GCOUTF,"# of minor collections: %li\n", GC->num_minor_collects)); - GCWARN((GCOUTF,"# of installed finalizers: %i\n", num_fnls)); + GCWARN((GCOUTF,"# of installed finalizers: %i\n", GC->num_fnls)); GCWARN((GCOUTF,"# of traced ephemerons: %i\n", num_last_seen_ephemerons)); if (flags & GC_DUMP_SHOW_TRACE) { diff --git a/src/mzscheme/gc2/newgc_internal.h b/src/mzscheme/gc2/newgc_internal.h index a160c6439c..70bf988d34 100644 --- a/src/mzscheme/gc2/newgc_internal.h +++ b/src/mzscheme/gc2/newgc_internal.h @@ -140,6 +140,10 @@ typedef struct NewGC { GC_Immobile_Box *immobile_boxes; /* Common with CompactGC */ + Fnl *finalizers; + Fnl *splayed_finalizers; + int num_fnls; + void *park[2]; void *park_save[2];