Note [Static objects under the nonmoving collector]

rts/sm/Storage.c:486 rts

Static object management is a bit tricky under the nonmoving collector as we
need to maintain a bit more state than in the moving collector. In
particular, the moving collector uses the low bits of the STATIC_LINK field
to determine whether the object has been moved to the scavenger's work list
(see Note [STATIC_LINK fields] in Storage.h).

However, the nonmoving collector also needs a place to keep its mark bit.
This is problematic as we therefore need at least three bits of state
but can assume only two bits are available in STATIC_LINK (due to 32-bit
systems).

To accommodate this we move handling of static objects entirely to the
oldest generation when the nonmoving collector is in use. To do this safely
and efficiently we allocate the blackhole created by lockCAF() directly in
the non-moving heap. This means that the moving collector can completely
ignore static objects in minor collections since they are guaranteed not to
have any references into the moving heap. Of course, the blackhole itself
likely will contain a reference into the moving heap but this is
significantly easier to handle, being a heap-allocated object (see Note
[Aging under the non-moving collector] in NonMoving.c for details).

During the moving phase of a major collection we treat static objects
as we do any other reference into the non-moving heap by pushing them
to the non-moving mark queue (see Note [Aging under the non-moving
collector]).

This allows the non-moving collector to have full control over the flags
in STATIC_LINK, which it uses as described in Note [STATIC_LINK fields]).
This is implemented by NonMovingMark.c:bump_static_flag.

In short, the plan is:

  - lockCAF allocates its blackhole in the nonmoving heap. This is important
    to ensure that we do not need to place the static object on the mut_list
    lest we would need somw way to ensure that it evacuate only once during
    a moving collection.

  - evacuate_static_object adds merely pushes objects to the mark queue

  - the nonmoving collector uses the flags in STATIC_LINK as its mark bit.