Remove a couple more usages of the global GC
svn: r12307
This commit is contained in:
parent
4b29ac09c3
commit
83fbfd72cb
|
@ -203,9 +203,8 @@ inline static void clean_up_owner_table(NewGC *gc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static unsigned long custodian_usage(void *custodian)
|
inline static unsigned long custodian_usage(NewGC*gc, void *custodian)
|
||||||
{
|
{
|
||||||
NewGC *gc = GC;
|
|
||||||
OTEntry **owner_table = gc->owner_table;
|
OTEntry **owner_table = gc->owner_table;
|
||||||
const int table_size = gc->owner_table_size;
|
const int table_size = gc->owner_table_size;
|
||||||
unsigned long retval = 0;
|
unsigned long retval = 0;
|
||||||
|
@ -214,7 +213,7 @@ inline static unsigned long custodian_usage(void *custodian)
|
||||||
if(!gc->really_doing_accounting) {
|
if(!gc->really_doing_accounting) {
|
||||||
gc->park[0] = custodian;
|
gc->park[0] = custodian;
|
||||||
gc->really_doing_accounting = 1;
|
gc->really_doing_accounting = 1;
|
||||||
garbage_collect(1);
|
garbage_collect(gc, 1);
|
||||||
custodian = gc->park[0];
|
custodian = gc->park[0];
|
||||||
gc->park[0] = NULL;
|
gc->park[0] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -450,7 +449,7 @@ inline static void BTC_add_account_hook(int type,void *c1,void *c2,unsigned long
|
||||||
gc->park[0] = c1;
|
gc->park[0] = c1;
|
||||||
gc->park[1] = c2;
|
gc->park[1] = c2;
|
||||||
gc->really_doing_accounting = 1;
|
gc->really_doing_accounting = 1;
|
||||||
garbage_collect(1);
|
garbage_collect(gc, 1);
|
||||||
c1 = gc->park[0]; gc->park[0] = NULL;
|
c1 = gc->park[0]; gc->park[0] = NULL;
|
||||||
c2 = gc->park[1]; gc->park[1] = NULL;
|
c2 = gc->park[1]; gc->park[1] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -614,11 +613,11 @@ static unsigned long custodian_single_time_limit(NewGC *gc, int set)
|
||||||
return owner_table[set]->single_time_limit;
|
return owner_table[set]->single_time_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
long BTC_get_memory_use(void *o)
|
long BTC_get_memory_use(NewGC* gc, void *o)
|
||||||
{
|
{
|
||||||
Scheme_Object *arg = (Scheme_Object*)o;
|
Scheme_Object *arg = (Scheme_Object*)o;
|
||||||
if(SAME_TYPE(SCHEME_TYPE(arg), scheme_custodian_type)) {
|
if(SAME_TYPE(SCHEME_TYPE(arg), scheme_custodian_type)) {
|
||||||
return custodian_usage(arg);
|
return custodian_usage(gc, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -565,7 +565,7 @@ static int is_marked(CompactGC *gc, void *p);
|
||||||
/* finalization */
|
/* finalization */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
static int is_finalizable_page(void *p)
|
static int is_finalizable_page(CompactGC *gc, void *p)
|
||||||
{
|
{
|
||||||
MPage *page;
|
MPage *page;
|
||||||
page = find_page(p);
|
page = find_page(p);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
finalizers
|
finalizers
|
||||||
num_fnls
|
num_fnls
|
||||||
Requires:
|
Requires:
|
||||||
is_finalizable_page(p)
|
is_finalizable_page(gc, p)
|
||||||
park
|
park
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ void GC_set_finalizer(void *p, int tagged, int level, void (*f)(void *p, void *d
|
||||||
GCTYPE *gc = GC;
|
GCTYPE *gc = GC;
|
||||||
Fnl *fnl;
|
Fnl *fnl;
|
||||||
|
|
||||||
if (!is_finalizable_page(p)) {
|
if (!is_finalizable_page(gc, p)) {
|
||||||
/* Never collected. Don't finalize it. */
|
/* Never collected. Don't finalize it. */
|
||||||
if (oldf) *oldf = NULL;
|
if (oldf) *oldf = NULL;
|
||||||
if (olddata) *olddata = NULL;
|
if (olddata) *olddata = NULL;
|
||||||
|
|
|
@ -75,6 +75,7 @@ static const char *type_name[PAGE_TYPES] = {
|
||||||
#include "newgc.h"
|
#include "newgc.h"
|
||||||
static THREAD_LOCAL NewGC *GC;
|
static THREAD_LOCAL NewGC *GC;
|
||||||
#define GCTYPE NewGC
|
#define GCTYPE NewGC
|
||||||
|
#define GC_get_GC() (GC)
|
||||||
|
|
||||||
#include "msgprint.c"
|
#include "msgprint.c"
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ void (*GC_fixup_xtagged)(void *obj);
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* OS-Level Memory Management Routines */
|
/* OS-Level Memory Management Routines */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static void garbage_collect(int);
|
static void garbage_collect(NewGC*, int);
|
||||||
|
|
||||||
static void out_of_memory()
|
static void out_of_memory()
|
||||||
{
|
{
|
||||||
|
@ -162,9 +163,9 @@ inline static void check_used_against_max(NewGC *gc, size_t len)
|
||||||
gc->unsafe_allocation_abort(gc);
|
gc->unsafe_allocation_abort(gc);
|
||||||
} else {
|
} else {
|
||||||
if(gc->used_pages > gc->max_pages_for_use) {
|
if(gc->used_pages > gc->max_pages_for_use) {
|
||||||
garbage_collect(0); /* hopefully this will free enough space */
|
garbage_collect(gc, 0); /* hopefully this will free enough space */
|
||||||
if(gc->used_pages > gc->max_pages_for_use) {
|
if(gc->used_pages > gc->max_pages_for_use) {
|
||||||
garbage_collect(1); /* hopefully *this* will free enough space */
|
garbage_collect(gc, 1); /* hopefully *this* will free enough space */
|
||||||
if(gc->used_pages > gc->max_pages_for_use) {
|
if(gc->used_pages > gc->max_pages_for_use) {
|
||||||
/* too much memory allocated.
|
/* too much memory allocated.
|
||||||
* Inform the thunk and then die semi-gracefully */
|
* Inform the thunk and then die semi-gracefully */
|
||||||
|
@ -398,9 +399,9 @@ static inline int BTC_single_allocation_limit(NewGC *gc, size_t sizeb);
|
||||||
/* the core allocation functions */
|
/* the core allocation functions */
|
||||||
static void *allocate_big(size_t sizeb, int type)
|
static void *allocate_big(size_t sizeb, int type)
|
||||||
{
|
{
|
||||||
|
NewGC *gc = GC;
|
||||||
mpage *bpage;
|
mpage *bpage;
|
||||||
void *addr;
|
void *addr;
|
||||||
NewGC *gc = GC;
|
|
||||||
|
|
||||||
#ifdef NEWGC_BTC_ACCOUNT
|
#ifdef NEWGC_BTC_ACCOUNT
|
||||||
if(GC_out_of_memory) {
|
if(GC_out_of_memory) {
|
||||||
|
@ -425,7 +426,7 @@ static void *allocate_big(size_t sizeb, int type)
|
||||||
|
|
||||||
if((gc->gen0.current_size + sizeb) >= gc->gen0.max_size) {
|
if((gc->gen0.current_size + sizeb) >= gc->gen0.max_size) {
|
||||||
if (!gc->dumping_avoid_collection)
|
if (!gc->dumping_avoid_collection)
|
||||||
garbage_collect(0);
|
garbage_collect(gc, 0);
|
||||||
}
|
}
|
||||||
gc->gen0.current_size += sizeb;
|
gc->gen0.current_size += sizeb;
|
||||||
|
|
||||||
|
@ -548,7 +549,7 @@ inline static void *allocate(size_t sizeb, int type)
|
||||||
GC_gen0_alloc_page_end = NUM(new_mpage->addr) + GEN0_PAGE_SIZE;
|
GC_gen0_alloc_page_end = NUM(new_mpage->addr) + GEN0_PAGE_SIZE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
garbage_collect(0);
|
garbage_collect(gc, 0);
|
||||||
}
|
}
|
||||||
newptr = GC_gen0_alloc_page_ptr + sizeb;
|
newptr = GC_gen0_alloc_page_ptr + sizeb;
|
||||||
}
|
}
|
||||||
|
@ -818,11 +819,10 @@ static void dump_heap(NewGC *gc)
|
||||||
|
|
||||||
#if MZ_GC_BACKTRACE
|
#if MZ_GC_BACKTRACE
|
||||||
|
|
||||||
static void backtrace_new_page(struct mpage *page)
|
static void backtrace_new_page(NewGC *gc, mpage *page)
|
||||||
{
|
{
|
||||||
/* This is a little wastefull for big pages, because we'll
|
/* This is a little wastefull for big pages, because we'll
|
||||||
only use the first few words: */
|
only use the first few words: */
|
||||||
NewGC *gc = GC;
|
|
||||||
page->backtrace = (void **)malloc_pages(gc, APAGE_SIZE, APAGE_SIZE);
|
page->backtrace = (void **)malloc_pages(gc, APAGE_SIZE, APAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -883,7 +883,7 @@ static void *get_backtrace(struct mpage *page, void *ptr)
|
||||||
# define BT_IMMOBILE (PAGE_TYPES + 4)
|
# define BT_IMMOBILE (PAGE_TYPES + 4)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# define backtrace_new_page(page) /* */
|
# define backtrace_new_page(gc, page) /* */
|
||||||
# define free_backtrace(page) /* */
|
# define free_backtrace(page) /* */
|
||||||
# define set_backtrace_source(ptr, type) /* */
|
# define set_backtrace_source(ptr, type) /* */
|
||||||
# define record_backtrace(page, ptr) /* */
|
# define record_backtrace(page, ptr) /* */
|
||||||
|
@ -983,9 +983,8 @@ inline static void repair_roots(NewGC *gc)
|
||||||
/* finalizers */
|
/* finalizers */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static int is_finalizable_page(void *p)
|
static int is_finalizable_page(NewGC *gc, void *p)
|
||||||
{
|
{
|
||||||
NewGC *gc = GC;
|
|
||||||
return (pagemap_find_page(gc->page_maps, p) ? 1 : 0);
|
return (pagemap_find_page(gc->page_maps, p) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1080,9 +1079,9 @@ inline static void do_ordered_level3(NewGC *gc)
|
||||||
|
|
||||||
void GC_finalization_weak_ptr(void **p, int offset)
|
void GC_finalization_weak_ptr(void **p, int offset)
|
||||||
{
|
{
|
||||||
|
NewGC *gc = GC;
|
||||||
Weak_Finalizer *wfnl;
|
Weak_Finalizer *wfnl;
|
||||||
|
|
||||||
NewGC *gc = GC;
|
|
||||||
gc->park[0] = p; wfnl = GC_malloc_atomic(sizeof(Weak_Finalizer));
|
gc->park[0] = p; wfnl = GC_malloc_atomic(sizeof(Weak_Finalizer));
|
||||||
p = gc->park[0]; gc->park[0] = NULL;
|
p = gc->park[0]; gc->park[0] = NULL;
|
||||||
wfnl->p = p; wfnl->offset = offset * sizeof(void*); wfnl->saved = NULL;
|
wfnl->p = p; wfnl->offset = offset * sizeof(void*); wfnl->saved = NULL;
|
||||||
|
@ -1394,7 +1393,8 @@ void GC_init_type_tags(int count, int pair, int mutable_pair, int weakbox, int e
|
||||||
|
|
||||||
void GC_gcollect(void)
|
void GC_gcollect(void)
|
||||||
{
|
{
|
||||||
garbage_collect(1);
|
NewGC *gc = GC;
|
||||||
|
garbage_collect(gc, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GC_register_traversers(short tag, Size_Proc size, Mark_Proc mark,
|
void GC_register_traversers(short tag, Size_Proc size, Mark_Proc mark,
|
||||||
|
@ -1407,13 +1407,12 @@ void GC_register_traversers(short tag, Size_Proc size, Mark_Proc mark,
|
||||||
|
|
||||||
long GC_get_memory_use(void *o)
|
long GC_get_memory_use(void *o)
|
||||||
{
|
{
|
||||||
NewGC *gc;
|
NewGC *gc = GC;
|
||||||
#ifdef NEWGC_BTC_ACCOUNT
|
#ifdef NEWGC_BTC_ACCOUNT
|
||||||
if(o) {
|
if(o) {
|
||||||
return BTC_get_memory_use(o);
|
return BTC_get_memory_use(gc, o);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
gc = GC;
|
|
||||||
return gen0_size_in_use(gc) + gc->memory_in_use;
|
return gen0_size_in_use(gc) + gc->memory_in_use;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1469,7 +1468,7 @@ void GC_mark(const void *const_p)
|
||||||
gc->gen0.big_pages = page->next;
|
gc->gen0.big_pages = page->next;
|
||||||
if(page->next) page->next->prev = page->prev;
|
if(page->next) page->next->prev = page->prev;
|
||||||
|
|
||||||
backtrace_new_page(page);
|
backtrace_new_page(gc, page);
|
||||||
|
|
||||||
/* add to gen1 */
|
/* add to gen1 */
|
||||||
page->next = gc->gen1_pages[PAGE_BIG];
|
page->next = gc->gen1_pages[PAGE_BIG];
|
||||||
|
@ -1558,7 +1557,7 @@ void GC_mark(const void *const_p)
|
||||||
work->page_type = type;
|
work->page_type = type;
|
||||||
work->size = work->previous_size = PREFIX_SIZE;
|
work->size = work->previous_size = PREFIX_SIZE;
|
||||||
work->marked_on = 1;
|
work->marked_on = 1;
|
||||||
backtrace_new_page(work);
|
backtrace_new_page(gc, work);
|
||||||
work->next = gc->gen1_pages[type];
|
work->next = gc->gen1_pages[type];
|
||||||
work->prev = NULL;
|
work->prev = NULL;
|
||||||
if(work->next)
|
if(work->next)
|
||||||
|
@ -1599,10 +1598,9 @@ void GC_mark(const void *const_p)
|
||||||
|
|
||||||
/* this is the second mark routine. It's not quite as complicated. */
|
/* this is the second mark routine. It's not quite as complicated. */
|
||||||
/* this is what actually does mark propagation */
|
/* this is what actually does mark propagation */
|
||||||
static void propagate_marks(void)
|
static void propagate_marks(NewGC *gc)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
NewGC *gc = GC;
|
|
||||||
PageMap pagemap = gc->page_maps;
|
PageMap pagemap = gc->page_maps;
|
||||||
Mark_Proc *mark_table = gc->mark_table;
|
Mark_Proc *mark_table = gc->mark_table;
|
||||||
|
|
||||||
|
@ -1745,10 +1743,10 @@ void GC_dump_with_traces(int flags,
|
||||||
GC_print_tagged_value_proc print_tagged_value,
|
GC_print_tagged_value_proc print_tagged_value,
|
||||||
int path_length_limit)
|
int path_length_limit)
|
||||||
{
|
{
|
||||||
struct mpage *page;
|
NewGC *gc = GC;
|
||||||
|
mpage *page;
|
||||||
int i;
|
int i;
|
||||||
static unsigned long counts[MAX_DUMP_TAG], sizes[MAX_DUMP_TAG];
|
static unsigned long counts[MAX_DUMP_TAG], sizes[MAX_DUMP_TAG];
|
||||||
NewGC *gc = GC;
|
|
||||||
|
|
||||||
reset_object_traces();
|
reset_object_traces();
|
||||||
if (for_each_found)
|
if (for_each_found)
|
||||||
|
@ -1983,7 +1981,7 @@ struct mpage *allocate_compact_target(NewGC *gc, mpage *work)
|
||||||
npage->big_page = 0;
|
npage->big_page = 0;
|
||||||
npage->page_type = work->page_type;
|
npage->page_type = work->page_type;
|
||||||
npage->marked_on = 1;
|
npage->marked_on = 1;
|
||||||
backtrace_new_page(npage);
|
backtrace_new_page(gc, npage);
|
||||||
/* Link in this new replacement page */
|
/* Link in this new replacement page */
|
||||||
npage->prev = work;
|
npage->prev = work;
|
||||||
npage->next = work->next;
|
npage->next = work->next;
|
||||||
|
@ -2224,10 +2222,9 @@ static inline void cleanup_vacated_pages(NewGC *gc) {
|
||||||
gc->release_pages = NULL;
|
gc->release_pages = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void gen0_free_big_pages() {
|
inline static void gen0_free_big_pages(NewGC *gc) {
|
||||||
mpage *work;
|
mpage *work;
|
||||||
mpage *next;
|
mpage *next;
|
||||||
NewGC *gc = GC;
|
|
||||||
PageMap pagemap = gc->page_maps;
|
PageMap pagemap = gc->page_maps;
|
||||||
|
|
||||||
for(work = gc->gen0.big_pages; work; work = next) {
|
for(work = gc->gen0.big_pages; work; work = next) {
|
||||||
|
@ -2244,7 +2241,7 @@ static void clean_up_heap(NewGC *gc)
|
||||||
size_t memory_in_use = 0;
|
size_t memory_in_use = 0;
|
||||||
PageMap pagemap = gc->page_maps;
|
PageMap pagemap = gc->page_maps;
|
||||||
|
|
||||||
gen0_free_big_pages();
|
gen0_free_big_pages(gc);
|
||||||
|
|
||||||
for(i = 0; i < PAGE_TYPES; i++) {
|
for(i = 0; i < PAGE_TYPES; i++) {
|
||||||
if(gc->gc_full) {
|
if(gc->gc_full) {
|
||||||
|
@ -2317,9 +2314,8 @@ extern double scheme_get_inexact_milliseconds(void);
|
||||||
really clean up. The full_needed_for_finalization flag triggers
|
really clean up. The full_needed_for_finalization flag triggers
|
||||||
the second full GC. */
|
the second full GC. */
|
||||||
|
|
||||||
static void garbage_collect(int force_full)
|
static void garbage_collect(NewGC *gc, int force_full)
|
||||||
{
|
{
|
||||||
NewGC *gc = GC;
|
|
||||||
unsigned long old_mem_use = gc->memory_in_use;
|
unsigned long old_mem_use = gc->memory_in_use;
|
||||||
unsigned long old_gen0 = gc->gen0.current_size;
|
unsigned long old_gen0 = gc->gen0.current_size;
|
||||||
int next_gc_full;
|
int next_gc_full;
|
||||||
|
@ -2385,15 +2381,15 @@ static void garbage_collect(int force_full)
|
||||||
|
|
||||||
/* now propagate/repair the marks we got from these roots, and do the
|
/* now propagate/repair the marks we got from these roots, and do the
|
||||||
finalizer passes */
|
finalizer passes */
|
||||||
propagate_marks(); mark_ready_ephemerons(gc); propagate_marks();
|
propagate_marks(gc); mark_ready_ephemerons(gc); propagate_marks(gc);
|
||||||
check_finalizers(gc, 1); mark_ready_ephemerons(gc); propagate_marks();
|
check_finalizers(gc, 1); mark_ready_ephemerons(gc); propagate_marks(gc);
|
||||||
check_finalizers(gc, 2); mark_ready_ephemerons(gc); propagate_marks();
|
check_finalizers(gc, 2); mark_ready_ephemerons(gc); propagate_marks(gc);
|
||||||
if(gc->gc_full) zero_weak_finalizers(gc);
|
if(gc->gc_full) zero_weak_finalizers(gc);
|
||||||
do_ordered_level3(gc); propagate_marks();
|
do_ordered_level3(gc); propagate_marks(gc);
|
||||||
check_finalizers(gc, 3); propagate_marks();
|
check_finalizers(gc, 3); propagate_marks(gc);
|
||||||
if(gc->gc_full) {
|
if(gc->gc_full) {
|
||||||
reset_weak_finalizers(gc);
|
reset_weak_finalizers(gc);
|
||||||
propagate_marks();
|
propagate_marks(gc);
|
||||||
}
|
}
|
||||||
#ifndef NEWGC_BTC_ACCOUNT
|
#ifndef NEWGC_BTC_ACCOUNT
|
||||||
/* we need to clear out the stack pages. If we're doing memory accounting,
|
/* we need to clear out the stack pages. If we're doing memory accounting,
|
||||||
|
@ -2572,15 +2568,15 @@ void GC_dump_variable_stack(void **var_stack,
|
||||||
|
|
||||||
void GC_free_all(void)
|
void GC_free_all(void)
|
||||||
{
|
{
|
||||||
|
NewGC *gc = GC;
|
||||||
int i;
|
int i;
|
||||||
mpage *work;
|
mpage *work;
|
||||||
mpage *next;
|
mpage *next;
|
||||||
NewGC *gc = GC;
|
|
||||||
PageMap pagemap = gc->page_maps;
|
PageMap pagemap = gc->page_maps;
|
||||||
|
|
||||||
remove_signal_handler(gc);
|
remove_signal_handler(gc);
|
||||||
|
|
||||||
gen0_free_big_pages();
|
gen0_free_big_pages(gc);
|
||||||
|
|
||||||
for(i = 0; i < PAGE_TYPES; i++) {
|
for(i = 0; i < PAGE_TYPES; i++) {
|
||||||
for (work = gc->gen1_pages[i]; work; work = next) {
|
for (work = gc->gen1_pages[i]; work; work = next) {
|
||||||
|
|
|
@ -100,7 +100,7 @@ typedef struct NewGC {
|
||||||
Fnl *last_in_queue;
|
Fnl *last_in_queue;
|
||||||
Weak_Finalizer *weak_finalizers;
|
Weak_Finalizer *weak_finalizers;
|
||||||
|
|
||||||
struct GC *primoridal_gc;
|
struct NewGC *primoridal_gc;
|
||||||
unsigned long max_heap_size;
|
unsigned long max_heap_size;
|
||||||
unsigned long max_pages_in_heap;
|
unsigned long max_pages_in_heap;
|
||||||
unsigned long max_pages_for_use;
|
unsigned long max_pages_for_use;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user