public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to use the garbage collector?
@ 2001-01-01 18:51 Peter Gerwinski
  2001-01-01 23:58 ` Fergus Henderson
  2001-01-02 10:21 ` Mark Mitchell
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Gerwinski @ 2001-01-01 18:51 UTC (permalink / raw)
  To: gcc

Hello,

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?

    Peter

-- 
http://home.pages.de/~Peter.Gerwinski/ - G-N-U GmbH: http://www.g-n-u.de
Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-20010101
GnuPG key fingerprint: 9E7C 0FC4 8A62 5536 1730 A932 9834 65DB 2143 9422
keys: http://www.gerwinski.de/pubkeys/ - AntiSpam: http://spam.abuse.net

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to use the garbage collector?
  2001-01-01 18:51 How to use the garbage collector? Peter Gerwinski
@ 2001-01-01 23:58 ` Fergus Henderson
  2001-01-02  1:06   ` Richard Henderson
  2001-01-02 10:21 ` Mark Mitchell
  1 sibling, 1 reply; 4+ messages in thread
From: Fergus Henderson @ 2001-01-01 23:58 UTC (permalink / raw)
  To: Peter Gerwinski; +Cc: gcc

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to use the garbage collector?
  2001-01-01 23:58 ` Fergus Henderson
@ 2001-01-02  1:06   ` Richard Henderson
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2001-01-02  1:06 UTC (permalink / raw)
  To: Fergus Henderson; +Cc: Peter Gerwinski, gcc

On Tue, Jan 02, 2001 at 06:57:45PM +1100, Fergus Henderson wrote:
> 1. Delete obstack code.
> 2. Register your roots.
> 3. Mark your types.

Yep.

> 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.

See the use of ggc_push_context and ggc_pop_context in e.g.
cp/semantics.c for an alternative to marking local variables.


r~

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to use the garbage collector?
  2001-01-01 18:51 How to use the garbage collector? Peter Gerwinski
  2001-01-01 23:58 ` Fergus Henderson
@ 2001-01-02 10:21 ` Mark Mitchell
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Mitchell @ 2001-01-02 10:21 UTC (permalink / raw)
  To: peter; +Cc: gcc

>>>>> "Peter" == Peter Gerwinski <peter@gerwinski.de> writes:

    Peter> Hello,

    Peter> while integrating GNU Pascal into gcc-2.97, I reached the
    Peter> point where the compiler abort()s due to lang_mark_tree()
    Peter> in ggc-callbacks.c.

    Peter> What is the correct way to switch from obstacks to the GC
    Peter> in the frontend?

Sadly, there's no great documentation here.  But, the good news is
that it's pretty easy.  You use lang_mark_tree to mark bits of nodes
that don't exist in the generic front-end; see
cp/decl.c:lang_mark_tree for examples.  To get started, you can just
have lang_mark_tree return without doing anything -- that's fine, as
long as you have no language-specific tree nodes.  Then, add what you
need.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-01-02 10:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-01 18:51 How to use the garbage collector? Peter Gerwinski
2001-01-01 23:58 ` Fergus Henderson
2001-01-02  1:06   ` Richard Henderson
2001-01-02 10:21 ` Mark Mitchell

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).