[MLton] gc question
Matthew Fluet
fluet at tti-c.org
Sun Feb 25 14:12:24 PST 2007
> Is this code (in foreachObjptrInObject) correct?
>
> else if (WEAK_TAG == tag) {
> p += bytesNonObjptrs;
> if (1 == numObjptrs) {
> if (not skipWeaks)
> callIfIsObjptr (s, f, (objptr*)p);
> p += OBJPTR_SIZE;
> }
> }
Yes.
> We only advance p past the weak pointer if it is valid, but this does
> not seem to square with the description of foreachObjptrInObject:
>
> Returns pointer to the end of object, i.e. just past object.
>
> or with the way it is called in foreachObjptrInRange. Am I missing
> something?
See runtime/gc/weak.h.
The object type indexed by the header of the weak pointer object
determines whether the weak is valid or not. When a weak goes dead, we
update its header.
If the type has numObjptrs == 1, then the weak pointer is valid and
bytesNonObjptrs == 4 (or 8 for -align 8). Hence, in this case the code
above advances by 4 and then again by 4.
If the type has numObjptrs == 0, then the weak pointer is invalid and
bytesNonObjptrs == 8 (or 12 for -align 8). Hence, in this case, the
code above advances by 8.
We do things this way so that in many situations, we can treat a weak
object just like a normal object, using the bytesNonObjptrs and numObjptrs.
More information about the MLton
mailing list