Componentizing D's garbage collector

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 10 12:00:23 PST 2014


On Fri, Jan 10, 2014 at 08:22:56AM -0800, Andrei Alexandrescu wrote:
> On 1/10/14 3:29 AM, Dmitry Olshansky wrote:
> >10-Jan-2014 12:03, Andrei Alexandrescu пишет:
> >>* I plan to rely on static introspection for the mark function, i.e:
> >>
> >>void mark(T)(ref T obj);
> >>
> >>would mark obj and everything transitively referred to by it. The
> >>function would probably take a second parameter that's the heap that
> >>obj is sitting in.
> >
> >This will not work AFAICT. Since nobody can tell what kind of type a
> >user-defined program may have and GC is certainly not templated on
> >all types.  GC would have to rely on TypeInfos or rather RTInfo-s
> >that describe the layout of Ts in a uniform way (bitmaps to indicate
> >pointers, etc.).  I think Walter had some ideas on how to represent
> >these to reduce space.
> 
> You know I wouldn't write that unless I had an ace up my sleeve.
> Watch me :o).

I don't see why having a templated mark() is a problem. Nothing says you
can't do this:

	module core.gc;
	void mark(T)(ref T obj) {
		size_t objSize = T.sizeof;
		// ... and whatever other type-specific info you need
		// here.

		// N.B.: non-template function call
		__mark_impl(cast(void*)&obj, objSize, /* ... whatever else is needed */);
	}


> >>* I plan to segregate all objects that don't include references and
> >>pointers (e.g. int, int[], Tuple!(int, double) etc) into a
> >>completely different heap than the "interesting" objects. For the
> >>simpler objects there's no need to save detailed type information so
> >>they can be stored in a more compact, efficient manner.
> >>
> >
> >Yup. I though GC already did something like that, with BlkAttr.NO_SCAN.
> 
> That design will disappear. The attribute won't be settable once
> initialized, and will never be conservative ("scan all words in this
> block").
[...]

So this will be the beginning of the precise GC that we've been talking
about for who knows how long now? I like that!


T

-- 
Любишь кататься - люби и саночки возить. 


More information about the Digitalmars-d mailing list