GGC ICEs

Ian Lance Taylor iant@google.com
Tue Jan 16 23:16:00 GMT 2007


Mike Stump <mrs@apple.com> writes:

> On Jan 16, 2007, at 1:46 PM, Ian Lance Taylor wrote:
> > I don't think we should ever call ggc_free.
> 
> Do you think there is no performance benefit to releasing memory for
> reuse, or that we should just not care about that performance loss?
> What type of loss are you willing to throw away?
> 
> I'm interested enough in compile time performance to want to
> encourage the use of ggc_free.  I'm happy to limiting it to cases
> that might recover n% of used memory, if you want, we can quibble
> over n.  At 1%, not sure it is worth it.  When n hits 50% or a couple
> of hundred megabytes, I'd rather ggc_free be called.  Also, I suspect
> ggc_allocate/ggc_free is faster than malloc/free on some systems.

We used to free memory when we didn't need it any more.  We stopped
doing that.  Why?  Because it turned out to be error prone.  The fix
we chose to implement was garbage collection.  I have many
reservations about using garbage collection in gcc.  But it does have
one huge advantage: we no longer have errors in which memory was freed
while we are still holding a reference to it (barring the occasional
missing GTY marker).

When we start to use ggc_free, we effectively go back to the old
regime.  Honza's patch is a perfect example of that.  He added a call
to ggc_free.  That call turned out to be inappropriate because, as it
happened, something else still held a pointer to that memory.  The
compiler crashed.

It's very easy to avoid crashes of this sort, and the solution is
exactly the one which caused us to implement garbage collection in the
first place: don't call ggc_free.

The only time that we can safely call ggc_free is when we know the
exact lifetime of the object.  If we know the exact lifetime of the
object, then we don't need to use garbage collection for it.  So for
those objects for which we know the exact lifetime, I would strongly
recommend not using garbage collection.

Therefore I think that your choice about n% of used memory is a false
one.

I would also happily support an effort to remove gcc's garbage
collector.  I believe that most other compilers do not in face use
garbage collection.  Any such change would require careful reasoning
about object lifespans, and it would have to implemented in such a way
that we do not recreate the memory problems that we used to have when
we used obstacks.

Ian



More information about the Gcc-patches mailing list