public final class ReferenceProcessor extends ReferenceProcessor
As an optimization for generational collectors, each reference type maintains two queues: a nursery queue and the main queue.
ReferenceProcessor.Semantics
Modifier and Type | Field and Description |
---|---|
private boolean |
growingTable
Flag to prevent a race between threads growing the reference object
table.
|
private static double |
GROWTH_FACTOR
Grow the reference object table by this multiplier
on overflow
|
private static int |
INITIAL_SIZE
Initial size of the reference object table
|
private static Lock |
lock
Class fields
|
private int |
maxIndex
Index of the first free slot in the reference table.
|
private int |
nurseryIndex
Index into the
references table for the start of
the reference nursery. |
private static ReferenceProcessor |
phantomReferenceProcessor |
private AddressArray |
references
The table of reference objects for the current semantics
|
private ReferenceProcessor.Semantics |
semantics
Semantics
|
private String |
semanticsStr
Copy of semantics.toString() for use in uninterruptible code
|
private static ReferenceProcessor |
softReferenceProcessor |
private static boolean |
STRESS |
private static boolean |
TRACE |
private static boolean |
TRACE_DETAIL |
private static boolean |
TRACE_UNREACHABLE |
private AddressArray |
unforwardedReferences
In a MarkCompact (or similar) collector, we need to update the
references
field, and then update its contents. |
private static ReferenceProcessor |
weakReferenceProcessor |
Modifier | Constructor and Description |
---|---|
private |
ReferenceProcessor(ReferenceProcessor.Semantics semantics)
Create a reference processor for a given semantics
|
Modifier and Type | Method and Description |
---|---|
private void |
addCandidate(Reference<?> ref,
ObjectReference referent)
Add a reference to the list of references.
|
static void |
addPhantomCandidate(PhantomReference<?> ref,
ObjectReference referent)
Add a reference to the list of phantom references.
|
private void |
addReference(Reference<?> ref,
ObjectReference referent)
Add a reference at the end of the table
|
static void |
addSoftCandidate(SoftReference<?> ref,
ObjectReference referent)
Add a reference to the list of soft references.
|
static void |
addWeakCandidate(WeakReference<?> ref,
ObjectReference referent)
Add a reference to the list of weak references.
|
void |
clear()
Clear the contents of the table.
|
protected void |
clearReferent(ObjectReference newReference)
Weak and soft references always clear the referent
before enqueueing.
|
int |
countWaitingReferences()
Statistics and debugging
|
boolean |
enqueueReference(ObjectReference addr)
Put this Reference object on its ReferenceQueue (if it has one)
when its referent is no longer sufficiently reachable.
|
void |
forward(TraceLocal trace,
boolean nursery)
Iterate over all references and forward.
|
static ReferenceProcessor |
get(ReferenceProcessor.Semantics semantics)
Creates an instance of the appropriate reference type processor.
|
private ObjectReference |
getReference(int i)
Retrieve from the reference table
|
protected ObjectReference |
getReferent(ObjectReference object)
Get the referent from a reference.
|
private AddressArray |
growReferenceTable()
Grow the reference table by GROWTH_FACTOR.
|
ObjectReference |
processReference(TraceLocal trace,
ObjectReference reference)
Processes a reference with the current semantics.
|
protected void |
retainReferent(TraceLocal trace,
ObjectReference reference)
This method deals only with soft references.
|
void |
scan(TraceLocal trace,
boolean nursery,
boolean retain)
Scan through the list of references.
|
private void |
setReference(int i,
ObjectReference ref)
Update the reference table
|
protected void |
setReferent(ObjectReference ref,
ObjectReference referent)
Set the referent in a reference.
|
private static final ReferenceProcessor softReferenceProcessor
private static final ReferenceProcessor weakReferenceProcessor
private static final ReferenceProcessor phantomReferenceProcessor
private static final boolean TRACE
private static final boolean TRACE_UNREACHABLE
private static final boolean TRACE_DETAIL
private static final boolean STRESS
private static final int INITIAL_SIZE
private static final double GROWTH_FACTOR
private volatile AddressArray references
private volatile AddressArray unforwardedReferences
references
field, and then update its contents. We implement this by saving the pointer in
this untraced field for use during the forward
pass.private int nurseryIndex
references
table for the start of
the reference nursery.private volatile int maxIndex
private volatile boolean growingTable
private final ReferenceProcessor.Semantics semantics
private final String semanticsStr
private ReferenceProcessor(ReferenceProcessor.Semantics semantics)
semantics
- the semantics this processor should use
(i.e. the types of references that it will process)public static ReferenceProcessor get(ReferenceProcessor.Semantics semantics)
semantics
- the semantics that the reference processor should
use (i.e. the type of references that it will process)private void addReference(Reference<?> ref, ObjectReference referent)
ref
- The reference to addreferent
- the object pointed to by the referenceprivate void setReference(int i, ObjectReference ref)
i
- The table indexref
- The reference to insertprivate ObjectReference getReference(int i)
i
- Table indexprivate AddressArray growReferenceTable()
Marked as UninterruptibleNoWarn because it can GC when it allocates, but the rest of the code can't tolerate GC.
This method is called without the reference processor lock held,
but with the flag growingTable
set.
private void addCandidate(Reference<?> ref, ObjectReference referent)
referent
- The referent of the referenceref
- The reference to addpublic void forward(TraceLocal trace, boolean nursery)
Collectors like MarkCompact determine liveness and move objects using separate traces.
Currently ignores the nursery hint.
TODO parallelise this code
forward
in class ReferenceProcessor
trace
- The MMTk trace to forward tonursery
- The nursery collection hintpublic void clear()
ReferenceProcessor
clear
in class ReferenceProcessor
public void scan(TraceLocal trace, boolean nursery, boolean retain)
Depending on the value of nursery
, we will either
scan all references, or just those created since the last scan.
TODO parallelise this code
scan
in class ReferenceProcessor
nursery
- Scan only the newly created referencestrace
- the thread local trace element.retain
- whether to retain those references whose referents are not
reachableprotected void retainReferent(TraceLocal trace, ObjectReference reference)
reference
- the address of the reference. This may or may not
be the address of a heap object, depending on the VM.trace
- the thread local trace element.public boolean enqueueReference(ObjectReference addr)
The implementation of this routine is determined by the the implementation of java.lang.ref.ReferenceQueue in the class library. It is in this class rather than the public Reference class to ensure that Jikes has a safe way of enqueueing the object, one that cannot be overridden by the application program.
addr
- the address of the Reference objecttrue
if the reference was enqueuedReferenceQueue
public static void addSoftCandidate(SoftReference<?> ref, ObjectReference referent)
ref
- the SoftReference to addreferent
- the object that the reference points topublic static void addWeakCandidate(WeakReference<?> ref, ObjectReference referent)
ref
- the WeakReference to addreferent
- the object that the reference points topublic static void addPhantomCandidate(PhantomReference<?> ref, ObjectReference referent)
ref
- the PhantomReference to addreferent
- the object that the reference points topublic ObjectReference processReference(TraceLocal trace, ObjectReference reference)
This method deals with a soft reference as if it were a weak reference, i.e.
it does not retain the referent. To retain the referent, use
retainReferent(TraceLocal, ObjectReference)
followed by a transitive
closure phase.
reference
- the address of the reference. This may or may not
be the address of a heap object, depending on the VM.trace
- the thread local trace element.ObjectReference.nullReference()
otherwiseprotected void clearReferent(ObjectReference newReference)
Reference.clear()
as the user could have overridden the
implementation and we don't want any side-effects to
occur.newReference
- the reference whose referent is to
be clearedprotected ObjectReference getReferent(ObjectReference object)
object
- the object reference.protected void setReferent(ObjectReference ref, ObjectReference referent)
ref
- the ObjectReference for the reference (confusing eh?).referent
- the referent object reference.public int countWaitingReferences()
countWaitingReferences
in class ReferenceProcessor