diff options
author | kan <kan@FreeBSD.org> | 2003-07-11 03:40:53 +0000 |
---|---|---|
committer | kan <kan@FreeBSD.org> | 2003-07-11 03:40:53 +0000 |
commit | b2a8872fbe1ec1c49094559ac7b78e6ea4ab7180 (patch) | |
tree | f6b0610f4a17fd26aa234354f050080f789861a4 /contrib/gcc/ggc-simple.c | |
parent | 52e69d78eee5612ac195e0701a5cebe40d1ab0e1 (diff) | |
download | FreeBSD-src-b2a8872fbe1ec1c49094559ac7b78e6ea4ab7180.zip FreeBSD-src-b2a8872fbe1ec1c49094559ac7b78e6ea4ab7180.tar.gz |
Gcc 3.3.1-pre as of 2003-07-11.
Diffstat (limited to 'contrib/gcc/ggc-simple.c')
-rw-r--r-- | contrib/gcc/ggc-simple.c | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/contrib/gcc/ggc-simple.c b/contrib/gcc/ggc-simple.c index 81d2c36..30b8725 100644 --- a/contrib/gcc/ggc-simple.c +++ b/contrib/gcc/ggc-simple.c @@ -27,20 +27,16 @@ #include "varray.h" #include "ggc.h" #include "timevar.h" +#include "params.h" /* Debugging flags. */ /* Zap memory before freeing to catch dangling pointers. */ -#define GGC_POISON +#undef GGC_POISON /* Collect statistics on how bushy the search tree is. */ #undef GGC_BALANCE -/* Perform collection every time ggc_collect is invoked. Otherwise, - collection is performed only when a significant amount of memory - has been allocated since the last collection. */ -#undef GGC_ALWAYS_COLLECT - /* Always verify that the to-be-marked memory is collectable. */ #undef GGC_ALWAYS_VERIFY @@ -48,9 +44,6 @@ #define GGC_POISON #define GGC_ALWAYS_VERIFY #endif -#ifdef ENABLE_GC_ALWAYS_COLLECT -#define GGC_ALWAYS_COLLECT -#endif #ifndef HOST_BITS_PER_PTR #define HOST_BITS_PER_PTR HOST_BITS_PER_LONG @@ -115,16 +108,6 @@ static struct globals int context; } G; -/* Skip garbage collection if the current allocation is not at least - this factor times the allocation at the end of the last collection. - In other words, total allocation must expand by (this factor minus - one) before collection is performed. */ -#define GGC_MIN_EXPAND_FOR_GC (1.3) - -/* Bound `allocated_last_gc' to 4MB, to prevent the memory expansion - test from triggering too often when the heap is small. */ -#define GGC_MIN_LAST_ALLOCATED (4 * 1024 * 1024) - /* Local function prototypes. */ static void tree_insert PARAMS ((struct ggc_mem *)); @@ -251,7 +234,7 @@ size_t ggc_get_size (p) const void *p; { - struct ggc_mem *x + struct ggc_mem *x = (struct ggc_mem *) ((const char *)p - offsetof (struct ggc_mem, u)); return x->size; } @@ -324,10 +307,16 @@ sweep_objs (root) void ggc_collect () { -#ifndef GGC_ALWAYS_COLLECT - if (G.allocated < GGC_MIN_EXPAND_FOR_GC * G.allocated_last_gc) + /* Avoid frequent unnecessary work by skipping collection if the + total allocations haven't expanded much since the last + collection. */ + size_t allocated_last_gc = + MAX (G.allocated_last_gc, (size_t)PARAM_VALUE (GGC_MIN_HEAPSIZE) * 1024); + + size_t min_expand = allocated_last_gc * PARAM_VALUE (GGC_MIN_EXPAND) / 100; + + if (G.allocated < allocated_last_gc + min_expand) return; -#endif #ifdef GGC_BALANCE debug_ggc_balance (); @@ -345,8 +334,6 @@ ggc_collect () sweep_objs (&G.root); G.allocated_last_gc = G.allocated; - if (G.allocated_last_gc < GGC_MIN_LAST_ALLOCATED) - G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED; timevar_pop (TV_GC); @@ -360,10 +347,9 @@ ggc_collect () /* Called once to initialize the garbage collector. */ -void +void init_ggc () { - G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED; } /* Start a new GGC context. Memory allocated in previous contexts @@ -383,7 +369,7 @@ ggc_push_context () /* Finish a GC context. Any uncollected memory in the new context will be merged with the old context. */ -void +void ggc_pop_context () { G.context--; @@ -425,7 +411,7 @@ debug_ggc_tree (p, indent) for (i = 0; i < indent; ++i) putc (' ', stderr); fprintf (stderr, "%lx %p\n", (unsigned long)PTR_KEY (p), p); - + if (p->sub[1]) debug_ggc_tree (p->sub[1], indent + 1); } @@ -490,7 +476,7 @@ ggc_print_statistics () /* Clear the statistics. */ memset (&stats, 0, sizeof (stats)); - + /* Make sure collection will really occur. */ G.allocated_last_gc = 0; |