Componentizing D's garbage collector

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 10 20:33:11 PST 2014


On Fri, Jan 10, 2014 at 11:58:21PM +0000, deadalnix wrote:
> On Friday, 10 January 2014 at 20:37:53 UTC, Rainer Schuetze wrote:
> >I think this might help in having different heaps (especially
> >thread local heaps if you include "shared"), but I'm not sure this
> >works in unsafe D where casting is allowed.
> >
> 
> One of the key to a fast GC is segregating the heap in smaller
> parts. This is why generational collectors are so popular in java
> for instance.
> 
> Segregating the heap imply so complications. For instance, it is
> necessary to track reference from one heap to another, typically
> from young to older objects.

Which unfortunately is not an option in D if write barriers are
required.


> In D, the type system provide a natural segregation. It would be
> a great missed opportunity to not take advantage of it. This
> segregation is really nice as pointers go from one to another in
> a single direction, avoiding the need to track references
> changes, and all element of the heap part share some common
> characteristics. These characteristics allow for specialized GC
> algorithms (for instance, a GC can run on the immutable heap
> without the program even knowing about it).

Yeah, the transitivity of immutable really makes this a big opportunity.
You know immutable can never point to mutable, and also that immutable
never ever changes, so that makes for a perfect partitioning of GC
memory. You never have to scan the immutable heap when collecting the
mutable heap, and there's never a problem with mutating references in
the immutable heap. So you don't need write barriers, and probably(?)
don't need locks when collecting the immutable heap, too.

Const is an interesting grey area here, though. It's also transitive,
and doesn't allow mutation through it, but something else may mutate the
data via another reference. So I'm not sure how exactly const will come
into play here, though it does seem like another promising area for GC
optimization.


> Casting is by essence bypassing the type system. In this case, you
> must be help responsible for what happen. The language cannot provide
> guarantees.

Agreed.


T

-- 
Don't drink and derive. Alcohol and algebra don't mix.


More information about the Digitalmars-d mailing list