This is the mail archive of the
mailing list for the GCC project.
Re: How to use the garbage collector?
- To: Peter Gerwinski <peter at gerwinski dot de>
- Subject: Re: How to use the garbage collector?
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- Date: Tue, 2 Jan 2001 18:57:45 +1100
- Cc: gcc at gcc dot gnu dot org
- References: <20010102035117.B10663@esmeralda.gerwinski.de>
On 02-Jan-2001, Peter Gerwinski <email@example.com> wrote:
> while integrating GNU Pascal into gcc-2.97, I reached the
> point where the compiler abort()s due to lang_mark_tree()
> in ggc-callbacks.c.
> What is the correct way to switch from obstacks to the GC
> in the frontend?
Here's my very rough understanding, based on reading the code,
and on the code in Tim Josling's "toy" language front-end (see
http://gcc.gnu.org/readings.html). I could be way off here.
But empirically this works for me ;-)
1. Delete obstack code.
You should delete all the calls that mess with obstacks, i.e.
and the like.
2. Register your roots.
If you have any global variables which contain data
structures which are allocated in GC'd memory (e.g. tree nodes and
rtxs), then you need to register them with the garbage collector,
ggc_add_tree_root (&my_global_tree_node, 1);
See the ggc_add_*root function declarations in ggc.h for other alternatives.
ggc_add_root() is the general case -- for that you need to provide
a mark function (see below).
I think you probably also need to register any local variables which
contain pointers to GC'd memory, and which are not linked to from
other memory that will be traced, and which are live when ggc_collect
() is called. ggc_collect is called from rest_of_compilation().
The C front-end also calls ggc_collect() itself after every external
declaration -- note that rest_of_decl_compilation and
rest_of_type_compilation *don't* call ggc_collect().
3. Mark your types.
If you've added language-specific tree nodes, then you need
to provide a routine (lang_mark_tree) to mark them.
Likewise if you have added a language-specific false_label_stack,
you may also need to provide a routine to mark it.
And you need to define the mark routine for any other
types that you registered as roots using ggc_add_root().
Fergus Henderson <firstname.lastname@example.org> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.