From 37b31aefeb2848b5cd9133b2bf652ab91533c533 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Thu, 9 Sep 1999 03:26:58 +0000 Subject: [PATCH] ggc.h (ggc_alloc): New function. * ggc.h (ggc_alloc): New function. (ggc_mark): Likewise. * ggc-simple.c (ggc_any): New structure. (ggc_status): Add anys. (n_anys_collected): New variable. (ggc_alloc): Define. (ggc_mark): Likewise. (ggc_collect): Collect the anys. From-SVN: r29222 --- gcc/ChangeLog | 11 +++++++ gcc/ggc-simple.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++-- gcc/ggc.h | 2 ++ 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b7593c18e94..bdd4753b1a8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +Wed Sep 8 20:30:42 1999 Mark Mitchell + + * ggc.h (ggc_alloc): New function. + (ggc_mark): Likewise. + * ggc-simple.c (ggc_any): New structure. + (ggc_status): Add anys. + (n_anys_collected): New variable. + (ggc_alloc): Define. + (ggc_mark): Likewise. + (ggc_collect): Collect the anys. + Wed Sep 8 20:15:14 1999 Kaveh R. Ghazi * c-decl.c (mark_binding_level): Make static to match prototype. diff --git a/gcc/ggc-simple.c b/gcc/ggc-simple.c index f5e5a9740f3..4858934f361 100644 --- a/gcc/ggc-simple.c +++ b/gcc/ggc-simple.c @@ -74,6 +74,21 @@ struct ggc_string char string[1]; }; +/* A generic allocation, with an external mark bit. */ + +struct ggc_any +{ + struct ggc_any *chain; + char mark; + + /* Make sure the data is reasonably aligned. */ + union { + char c; + HOST_WIDE_INT i; + long double d; + } u; +}; + #define GGC_STRING_MAGIC ((unsigned int)0xa1b2c3d4) struct ggc_status @@ -83,6 +98,7 @@ struct ggc_status struct ggc_rtvec *vecs; struct ggc_tree *trees; struct ggc_string *strings; + struct ggc_any *anys; size_t bytes_alloced_since_gc; }; @@ -96,6 +112,7 @@ static int n_rtxs_collected; static int n_vecs_collected; static int n_trees_collected; static int n_strings_collected; +static int n_anys_collected; extern int gc_time; #ifdef GGC_DUMP @@ -289,6 +306,24 @@ ggc_alloc_string (contents, length) return s->string; } +/* Like xmalloc, but allocates GC-able memory. */ + +void * +ggc_alloc (bytes) + size_t bytes; +{ + struct ggc_any *a; + + if (bytes == 0) + bytes = 1; + bytes += (&((struct ggc_any *) 0)->u.c - (char *) 0); + + a = (struct ggc_any *) xmalloc (bytes); + a->chain = ggc_chain->anys; + ggc_chain->anys = a; + + return &a->u; +} /* Freeing a bit of rtl is as simple as calling free. */ @@ -630,6 +665,18 @@ ggc_mark_string (s) *magic = GGC_STRING_MAGIC | 1; } +/* Mark P, allocated with ggc_alloc. */ + +void +ggc_mark (p) + void *p; +{ + struct ggc_any *a; + ptrdiff_t d = (&((struct ggc_any *) 0)->u.c - (char *) 0); + a = (struct ggc_any *) (((char*) p) - d); + a->mark = 1; +} + /* The top level mark-and-sweep routine. */ void @@ -641,7 +688,8 @@ ggc_collect () struct ggc_string *s, **sp; struct ggc_root *x; struct ggc_status *gs; - int time, n_rtxs, n_trees, n_vecs, n_strings; + struct ggc_any *a, **ap; + int time, n_rtxs, n_trees, n_vecs, n_strings, n_anys; #ifndef ENABLE_CHECKING /* See if it's even worth our while. */ @@ -665,6 +713,8 @@ ggc_collect () t->tree.common.gc_mark = 0; for (s = gs->strings; s != NULL; s = s->chain) s->magic_mark = GGC_STRING_MAGIC; + for (a = gs->anys; a != NULL; a = a->chain) + a->mark = 0; } /* Mark through all the roots. */ @@ -680,6 +730,9 @@ ggc_collect () } /* Sweep the resulting dead nodes. */ + + /* The RTXs. */ + rp = &ggc_chain->rtxs; r = ggc_chain->rtxs; n_rtxs = 0; @@ -699,6 +752,8 @@ ggc_collect () *rp = NULL; n_rtxs_collected += n_rtxs; + /* The vectors. */ + vp = &ggc_chain->vecs; v = ggc_chain->vecs; n_vecs = 0; @@ -718,6 +773,8 @@ ggc_collect () *vp = NULL; n_vecs_collected += n_vecs; + /* The trees. */ + tp = &ggc_chain->trees; t = ggc_chain->trees; n_trees = 0; @@ -737,6 +794,8 @@ ggc_collect () *tp = NULL; n_trees_collected += n_trees; + /* The strings. */ + sp = &ggc_chain->strings; s = ggc_chain->strings; n_strings = 0; @@ -755,6 +814,27 @@ ggc_collect () } *sp = NULL; n_strings_collected += n_strings; + + /* The generic data. */ + + ap = &ggc_chain->anys; + a = ggc_chain->anys; + n_anys = 0; + while (a != NULL) + { + struct ggc_any *chain = a->chain; + if (!a->mark) + { + free (a); + *ap = chain; + n_anys++; + } + else + ap = &a->chain; + a = chain; + } + n_anys_collected += n_anys; + ggc_chain->bytes_alloced_since_gc = 0; time = get_run_time () - time; @@ -763,8 +843,8 @@ ggc_collect () if (!quiet_flag) { time = (time + 500) / 1000; - fprintf (stderr, "%dr,%dv,%dt,%ds %d.%03d}", n_rtxs, n_vecs, n_trees, - n_strings, time / 1000, time % 1000); + fprintf (stderr, "%dr,%dv,%dt,%ds,%da %d.%03d}", n_rtxs, n_vecs, + n_trees, n_strings, n_anys, time / 1000, time % 1000); } } diff --git a/gcc/ggc.h b/gcc/ggc.h index 785e25bf80f..b0673e0e05a 100644 --- a/gcc/ggc.h +++ b/gcc/ggc.h @@ -56,6 +56,7 @@ struct rtx_def *ggc_alloc_rtx PROTO ((int nslots)); struct rtvec_def *ggc_alloc_rtvec PROTO ((int nelt)); union tree_node *ggc_alloc_tree PROTO ((int length)); char *ggc_alloc_string PROTO ((const char *contents, int length)); +void *ggc_alloc PROTO ((size_t)); /* Invoke the collector. This is really just a hint, but in the case of the simple collector, the only time it will happen. */ @@ -78,6 +79,7 @@ void ggc_mark_tree PROTO ((union tree_node *)); void ggc_mark_tree_varray PROTO ((struct varray_head_tag *)); void ggc_mark_tree_hash_table PROTO ((struct hash_table *)); void ggc_mark_string PROTO ((char *)); +void ggc_mark PROTO ((void *)); /* Callbacks to the languages. */ -- 2.30.2