Reduce pauses for weak reference access

Remove the "preserve references" machinery. Instead let the reference
processor inform GetReferent about its state, so that it can leverage
knowledge about whether reachable memory has in fact been completely
marked.

Restructure the ReferenceProcessor interface by adding Setup to
ensure that ReferenceProcessor fields are properly set up before
we disable the normal fast path through GetReferent.

For the CC collector, forward essentially all SoftReferences as
part of normal marking, so we don't stall weak reference access
for those.

Note briefly in the log if we encounter References that are only
reachable from finalizers.

SS and MS collectors are only minimally updated to keep them working.

We now block in GetReferent only for the hopefully very brief period of
marking objects that were initially missed as a result of a mutator
collector race. This should hopefully eliminate multi-millisecond delays
here. For 2043-reference-pauses from aosp/1952438, it reduces blocking
from over 100 msecs to under 1 on host. This is mostly due to the
better SoftReference treatment; 100 msec pauses in GetReferent()
were never near-typical.

We iteratively mark through SoftReferences now. Previously we could
mistakenly clear SoftReferences discovered while marking from the top
level ones. (Lokesh pointed this out.) To make this work, we change
ForwardSoftReferences to actually remove References from the queue,
as the comment always said it did.

This also somewhat prepares us for a much less complete solution for
pauses to access WeakGlobalRefs or other "system weaks".

This fixes a memory ordering issue for the per-thread weak reference
access flags used with the CC collector. I think the issue is still
there for the CMS collector. That requires further discussion.

Bug: 190867430
Bug: 189738006
Bug: 211784084

Test: Build and boot aosp & Treehugger; aosp/195243

Change-Id: I02f12ac481db4c4e400d253662a7a126318d4bec
19 files changed