public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Fergus Henderson <fjh@cs.mu.oz.au>
To: Peter Gerwinski <peter@gerwinski.de>
Cc: gcc@gcc.gnu.org
Subject: Re: How to use the garbage collector?
Date: Mon, 01 Jan 2001 23:58:00 -0000	[thread overview]
Message-ID: <20010102185745.B2460@hg.cs.mu.oz.au> (raw)
In-Reply-To: <20010102035117.B10663@esmeralda.gerwinski.de>

On 02-Jan-2001, Peter Gerwinski <peter@gerwinski.de> 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.

       suspend_momentary()
       push_obstacks_nochange()
       end_temporary_allocation()
       pop_obstacks()
       resume_momentary()

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 <fjh@cs.mu.oz.au>  |  "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.

  reply	other threads:[~2001-01-01 23:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-01 18:51 Peter Gerwinski
2001-01-01 23:58 ` Fergus Henderson [this message]
2001-01-02  1:06   ` Richard Henderson
2001-01-02 10:21 ` Mark Mitchell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010102185745.B2460@hg.cs.mu.oz.au \
    --to=fjh@cs.mu.oz.au \
    --cc=gcc@gcc.gnu.org \
    --cc=peter@gerwinski.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).