Quote from “Real World OCaml” on color in value header:
...
Gray Reachable, but its fields have not been scanned
Black Reachable, and its fields have been scanned
...
However, it seems that the gray color is only used in compact.c:
...
- Gray words are the encoding of pointers in inverted lists.
...
For instance, in major_gc.c, mark_slice_darken never even checks for gray values, it just blackens the white values immediately and pushes it onto stack.
In fact, I’ve always wondered why a gray color is needed in the implementation of a mark & sweep GC, if we are pushing the gray values onto a stack/worklist already. (I think it’s conceptually helpful but redundant in practice)
Thus my question: is it correct to say that the gray color in the OCaml GC is used for compaction only?
Thanks for the pointer, although I don’t seem to see any reference to the gray color there either…
It seems that this function sets things up for redarken_chunk (seems to be about lazily pushing gray values onto stack), but still the gray color is never used there explicitly, and with my limited understanding of GC internals, I can’t think of a reason to use it there…
What is making things a bit complicated is that the gray colour in the GC was actually removed in 4.12: https://github.com/ocaml/ocaml/pull/9756 . The PR has a well written explanation (cough) of why we made the change.
On a side note, am I correct in thinking that mark & sweep GC implementations don’t really require a gray color in general? (it bothers me a bit because all online materials I’ve found just restate the textbook definition…)