This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to use the garbage collector?

On 02-Jan-2001, Peter Gerwinski <> 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  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,
e.g.  using

       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 <>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]