|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mmtk.vm.ReferenceProcessor org.jikesrvm.mm.mmtk.ReferenceProcessor
public final class ReferenceProcessor
This class manages SoftReferences, WeakReferences, and PhantomReferences. When a java/lang/ref/Reference object is created, its address is added to a table of pending reference objects of the appropriate type. An address is used so the reference will not stay alive during GC if it isn't in use elsewhere the mutator. During GC, the various lists are processed in the proper order to determine if any Reference objects are ready to be enqueued or whether referents that have died should be kept alive until the Reference is explicitly cleared. MMTk drives this processing and uses this class, via the VM interface, to scan the lists of pending reference objects.
As an optimization for generational collectors, each reference type maintains two queues: a nursery queue and the main queue.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.mmtk.vm.ReferenceProcessor |
---|
ReferenceProcessor.Semantics |
Field Summary | |
---|---|
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
|
Constructor Summary | |
---|---|
private |
ReferenceProcessor(ReferenceProcessor.Semantics semantics)
Create a reference processor for a given semantics |
Method Summary | |
---|---|
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)
Factory method. |
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)
Process a reference with the current semantics. |
void |
scan(TraceLocal trace,
boolean nursery)
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Lock lock
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
Constructor Detail |
---|
private ReferenceProcessor(ReferenceProcessor.Semantics semantics)
semantics
- Method Detail |
---|
public static ReferenceProcessor get(ReferenceProcessor.Semantics semantics)
private void addReference(Reference<?> ref, ObjectReference referent)
ref
- The reference to addprivate void setReference(int i, ObjectReference ref)
i
- The table indexref
- The reference to insertprivate ObjectReference getReference(int i)
i
- Table index
private AddressArray growReferenceTable()
Logically Uninterruptible 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)
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.public boolean enqueueReference(ObjectReference addr)
addr
- the address of the Reference object
true
if the reference was enqueuedReferenceQueue
public static void addSoftCandidate(SoftReference<?> ref, ObjectReference referent)
ref
- the SoftReference to addpublic static void addWeakCandidate(WeakReference<?> ref, ObjectReference referent)
ref
- the WeakReference to addpublic static void addPhantomCandidate(PhantomReference<?> ref, ObjectReference referent)
ref
- the PhantomReference to addpublic ObjectReference processReference(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.protected void clearReferent(ObjectReference newReference)
protected 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
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |