[MLton] pinned objects (was: implement _address and _symbol)
Thu, 21 Jul 2005 08:32:02 -0700
> > There is no need for another level beyond the pin that lives outside
> > the heap. The ML value is the pin (address of the malloc'd object).
> ... which is exactly what I said.
Good. I misunderstood you as saying that there was yet another level of
pointers beyond the malloc'd object.
> Anyways, I don't need this particular feature, and am not brave
> enough to touch the scary GC. So, don't even *think* about
> delegating. ;-)
It's really not all that hard. Less than 100 lines of code in gc.c,
just the right size for a gentle introduction. You could probably get
by with an additional field in the GC_state that is a doubly-linked
list of all pinned objects. The heap pointers in this list must be
treated as roots during a GC and must be updated when the GC moves the
object they point to. This is handled differently depending on the
type of GC. Fortunately, we've already abstracted out the treatment
of external pointers into the heap -- the foreachGlobal function in
void foreachGlobal (GC_state s, GC_pointerFun f);
You could add a few lines to this that walk the linked list of pins
and apply f to the address of each heap pointer in the list. Then,
voila, the heap pointers will automatically get updated correctly for
each type of GC. Optimistically speaking, that's all you need for
gc.c. Beyond that, the SML basis interface is easy.
One additional hack to speed things up would be to keep two linked
lists, one for pointers known to be into the old generation and one
for pointers into the nursery. That way, when doing a minor GC you
can walk only the nursery list, which could save a lot of time if
there are many pinned objects (unlikely, but still). Once you've
walked the nursery list, you can splice it into the old-generation
list, since all objects will be in the old generation after the minor
> PS. I thought you lived on the West Coast?
I do -- in Silicon Valley.
> You read the mailing list pretty damn early...
I have a new baby, so I am available to read the list at many times of
the day :-).
> Also, this has been bugging me for a while, what is your
> Stephan is a very German name, and I always have to double-check
> I've spelt your's correctly.
"Stephen" is quite common here too, although perhaps "Steven" and
"Steve" are more common spellings. I respond to all of them :-).