View mode: basic / threaded / horizontal-split · Log in · Help
October 21, 2005
How does RTTI help gc?
Page:

  http://www.digitalmars.com/d/overview.html

contains:

  Runtime Type Identification. [snip] Fully supporting it enables better
  garbage collection

How does RTTI help GC?  I'm assuming it enables precise location of
pointers contained in an object.  I'm guessing it does this by 1st
finding the type of the object with RTTI, and then consulting
compiler generated pointer descriptor, something like that mentioned
here:

  http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcdescr.html

in the phrase:

  per-object type descriptors that determine pointer locations

I'm looking at the file:

  d/phobos/gc2/gcx.d

from:

  ftp://ftp.opend.org/CVS/HEAD/d-front-end.tar.gz

but I can't find anything that looks like such
a pointer descriptor.  It also appears like the
mark function on line 1186 of gcx.d does a
conservative search for pointers instead of
a precise one.

So where is RTTI used to do a precise pointer location,
or is this a future enhancement?

TIA.
October 21, 2005
Re: How does RTTI help gc?
In article <djb6j4$2a5m$1@digitaldaemon.com>, Larry Evans says...
>
>Page:
>
>   http://www.digitalmars.com/d/overview.html
>
>contains:
>
>   Runtime Type Identification. [snip] Fully supporting it enables better
>   garbage collection
>
>How does RTTI help GC?  I'm assuming it enables precise location of
>pointers contained in an object.  I'm guessing it does this by 1st
>finding the type of the object with RTTI, and then consulting
>compiler generated pointer descriptor, something like that mentioned
>here:
>
>   http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcdescr.html
>
>in the phrase:
>
>   per-object type descriptors that determine pointer locations
>
>I'm looking at the file:
>
>   d/phobos/gc2/gcx.d
>
>from:
>
>   ftp://ftp.opend.org/CVS/HEAD/d-front-end.tar.gz
>
>but I can't find anything that looks like such
>a pointer descriptor.  It also appears like the
>mark function on line 1186 of gcx.d does a
>conservative search for pointers instead of
>a precise one.
>
>So where is RTTI used to do a precise pointer location,
>or is this a future enhancement?
>
>TIA.

AFAIK, you're correct: under the current implementation, the scan is
conservative as it assumes that every contiguous 4-bytes of memory under GC
control is a valid pointer.  I say 'current' simply becuase Walter has a habit
of leaving the door chalked open for improvement now and later.

For example: Once upon a time, someone posted about a modified D GC they wrote
that actually used type hints to make the GC a little less conservative.  The
concept was dead simple: tag allocated blocks as containing some pointers or
none at all.  This meant that arrays of strings, or integers wouldn't ever get
searched for pointers while references, structs and objects would.

So to answer your question: no, the GC doesn't track precise locations, but it
can be hacked/modified/trained to approximate that.  I have no idea if this
planned for an offical enhancement to D or not.

- EricAnderton at yahoo
Top | Discussion index | About this forum | D home