org.jikesrvm.mm.mminterface
Class CollectorThread

java.lang.Object
  extended by org.mmtk.plan.MutatorContext
      extended by org.mmtk.plan.SimpleMutator
          extended by org.mmtk.plan.StopTheWorldMutator
              extended by org.mmtk.plan.generational.GenMutator
                  extended by org.mmtk.plan.generational.immix.GenImmixMutator
                      extended by org.jikesrvm.mm.mminterface.Selected.Mutator
                          extended by org.jikesrvm.mm.mminterface.ThreadContext
                              extended by org.jikesrvm.scheduler.RVMThread
                                  extended by org.jikesrvm.mm.mminterface.CollectorThread
All Implemented Interfaces:
Constants

public final class CollectorThread
extends RVMThread

System thread used to preform garbage collections. These threads are created by VM.boot() at runtime startup. One is created for each processor that will (potentially) participate in garbage collection.

 Its "run" method does the following:
    1. wait for a collection request
    2. synchronize with other collector threads (stop mutation)
    3. reclaim space
    4. synchronize with other collector threads (resume mutation)
    5. goto 1
 
Between collections, the collector threads are parked on a pthread condition variable. A collection in initiated by a call to the static collect(Handshake,int) method, which calls Handshake.requestAndAwaitCompletion(int) to signal the threads. The collection commences when all scheduled collector threads arrive at the first "rendezvous" in the run methods run loop. An instance of Handshake contains state information for the "current" collection. When a collection is finished, a new Handshake is allocated for the next garbage collection.

See Also:
Handshake

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jikesrvm.scheduler.RVMThread
RVMThread.BlockAdapter, RVMThread.GCBlockAdapter, RVMThread.HandshakeBlockAdapter, RVMThread.HardHandshakeVisitor, RVMThread.SoftHandshakeVisitor, RVMThread.SuspendBlockAdapter, RVMThread.Waiting
 
Field Summary
static int collectionAttemptBase
          The base collection attempt
(package private) static int collectionCount
          number of collections
(package private) static boolean DISPLAY_OPTIONS_AT_BOOT
          When true, causes RVM collectors to display heap configuration at startup
static int GC_ORDINAL_BASE
          gc threads are indexed from 1 for now...
static SynchronizationBarrier gcBarrier
          Use by collector threads to rendezvous during collection
private  int gcOrdinal
          arrival order of collectorThreads participating in a collection
(package private) static boolean gcThreadRunning
           
static Handshake handshake
          The Handshake object that contains the state of the next or current (in progress) collection.
static boolean MEASURE_WAIT_TIMES
          When true, collector threads measure time spent waiting for buffers while processing the Work Deque, and time spent waiting in Rendezvous during the collection process.
private static String myName
          Name used by toString() and when we create the associated java.lang.Thread.
private static int nextId
          Next collector thread id.
(package private) static int[] participantCount
          array of size 1 to count arriving collector threads
private  Address stackTraceThread
          The thread to use to determine stack traces if Throwables are created
private  ScanThread threadScanner
          used by each CollectorThread when scanning stacks for references
static boolean TIME_GC_PHASES
          When true, causes RVM collectors to measure time spent in each phase of collection.
(package private)  int timeInRendezvous
          time waiting in rendezvous (milliseconds)
private static int verbose
          Class variables
 
Fields inherited from class org.jikesrvm.scheduler.RVMThread
acctLock, activeMutatorContext, allButGC, ALWAYS_LOCK_ON_STATE_TRANSITION, asyncDebugRequestedForThisThread, BACKEDGE, barriersEntered, barriersExited, BLOCKED_IN_JNI, BLOCKED_IN_NATIVE, bootThread, bridgeInstructions, cachedFreeLock, codePatchSyncRequested, contextRegisters, contextRegistersSave, countdownCBSCall, countdownCBSMethod, daemon, debugLock, debugRequested, debugThreads, doProfileReport, dumpLock, dumpStackOnBlock, EPILOGUE, exitInProgress, feedlet, firstCBSCallSample, firstCBSMethodSample, flushRequested, fooFPOffset, gcBlockAdapter, handshakeBlockAdapter, handshakeLock, handshakeThreads, IN_JAVA, IN_JAVA_TO_BLOCK, IN_JNI, IN_NATIVE, inDumpStack, isWaitingForOsr, jniEnv, LAST_EXEC_STATUS, lockingId, LOG_MAX_THREADS, MAX_THREADS, NATIVE_EPILOGUE, NATIVE_PROLOGUE, NEW, nextSlot, numCBSCallSamples, numCBSMethodSamples, numProcessors, numThreads, onStackReplacementEvent, osr_done, OSROPT, PRIMORDIAL_THREAD_INDEX, PROLOGUE, pthread_id, requesting_osr, softHandshakeDataLock, softHandshakeLeft, softHandshakeRequested, stackLimit, suspendBlockAdapter, takeYieldpoint, TERMINATED, thread_cbs_counter, threadBySlot, threadingInitialized, threads, threadSlot, timerTicks, timeSliceExpired, trace, traceAboutToTerminate, traceAcct, traceBind, traceBlock, traceDetails, traceReallyBlock, tsFPOffset, waitCount, waiting, waitObject, yieldForCBSCall, yieldForCBSMethod, yieldToOSRRequested
 
Fields inherited from class org.jikesrvm.mm.mminterface.ThreadContext
collectorContext
 
Fields inherited from class org.mmtk.plan.generational.GenMutator
arrayRemset, nursery, remset
 
Fields inherited from class org.mmtk.plan.MutatorContext
immortal, lgcode, log, los, nonmove, smcode
 
Fields inherited from interface org.mmtk.utility.Constants
ALIGNMENT_VALUE, ARRAY_ELEMENT, BITS_IN_ADDRESS, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_INT, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_INT, BYTES_IN_KBYTE, BYTES_IN_MBYTE, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, CARD_MASK, CARD_META_PAGES_PER_REGION, INSTANCE_FIELD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_INT, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_ADDRESS_SPACE, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_INT, LOG_BYTES_IN_KBYTE, LOG_BYTES_IN_MBYTE, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD, LOG_CARD_BYTES, LOG_CARD_GRAIN, LOG_CARD_META_BYTES, LOG_CARD_META_PAGES, LOG_CARD_META_SIZE, LOG_CARD_UNITS, LOG_MIN_ALIGNMENT, MAX_ALIGNMENT, MAX_BYTES_PADDING, MAX_INT, MIN_ALIGNMENT, MIN_INT, SUPPORT_CARD_SCANNING
 
Constructor Summary
CollectorThread(byte[] stack)
          Constructor
 
Method Summary
 void allocateOOMEForThread(RVMThread thread)
          Allocate an OutOfMemoryError for a given thread.
static void asyncCollect(Handshake handshake, int why)
          Initiate a garbage collection at next GC safe point.
static void boot()
           
 void clearThreadForStackTrace()
          Set the thread to use for building stack traces.
static void collect(Handshake handshake, int why)
          Initiate a garbage collection.
static CollectorThread createActiveCollectorThread()
          Make a collector thread that will participate in gc.
 int getGCOrdinal()
          Return the GC ordinal for this collector thread.
 RVMThread getThreadForStackTrace()
          Get the thread to use for building stack traces.
 ScanThread getThreadScanner()
           
static void init()
          Initialize for boot image.
 boolean isGCThread()
          Is this the GC thread?
static boolean noThreadsInGC()
          Return true if no threads are still in GC.
static int numCollectors()
          Returns number of collector threads participating in a collection
 int rendezvous(int where)
           
 void run()
          Run method for collector thread (one per processor).
 void setGCOrdinal(int ord)
          Set the GC ordinal for this collector thread.
 void setThreadForStackTrace(RVMThread thread)
          Set the thread to use for building stack traces.
 String toString()
          Override Thread.toString
 
Methods inherited from class org.jikesrvm.scheduler.RVMThread
assertAcceptableStates, assertAcceptableStates, assertUnacceptableStates, assertUnacceptableStates, asyncBlock, attemptLeaveNativeNoBlock, beginPairHandshake, beginPairWith, beginPairWithCurrent, block, blockedFor, checkDebugRequest, clearDisallowAllocationsByThisThread, clearEmergencyAllocation, clearInterrupted, clearOutOfMemoryError, clearPhysicalAllocationFailed, communicationLock, communicationLockForSlot, countStackFrames, disableYieldpoints, dump, dump, dump, dump, dumpAcct, dumpAll, dumpStack, dumpStack, dumpStack, dumpStackAndDie, dumpVirtualMachine, dumpWithPadding, emergencyAllocation, enableYieldpoints, endPairHandshake, endPairWith, endPairWithCurrent, enterJNIBlockedFromCallIntoNative, enterJNIBlockedFromJNIFunctionCall, enterJNIFromCallIntoNative, enterJNIFromJNIFunctionCall, enterNative, extDump, failIfYieldpointsDisabled, fixupMovedStack, gcEnabled, getCollectionAttempt, getContextRegisters, getCurrentFeedlet, getCurrentThread, getCurrentThreadSlot, getDisableGCDepth, getDisallowAllocationsByThisThread, getExceptionRegisters, getExecStatus, getIsAboutToTerminate, getJavaLangThread, getJNIEnv, getLockingId, getName, getOutOfMemoryError, getPriority, getStack, getStackLength, getState, getThreadSlot, handleUncaughtException, hardHandshakeResume, hardHandshakeResume, hardHandshakeSuspend, hardHandshakeSuspend, hasNativeStackFrame, holdsLock, ignoreHandshakesAndGC, initializeJNIEnv, interrupt, isAlive, isBlocked, isBootThread, isDaemonThread, isInJava, isInterrupted, isSystemThread, join, leaveJNIBlockedFromCallIntoNative, leaveJNIFromCallIntoNative, leaveJNIFromJNIFunctionCall, leaveNative, makeDaemon, monitor, notify, notifyAll, notRunning, observeExecStatusAtSTW, park, physicalAllocationFailed, processAboutToTerminate, raiseIllegalMonitorStateException, reportCollectionAttempt, reportThreadTransitionCounts, resetCollectionAttempts, resizeCurrentStack, resume, safeAsyncBlock, safeBlock, safeToForceGCs, saveThreadState, setDisableGCDepth, setDisallowAllocationsByThisThread, setEmergencyAllocation, setName, setOutOfMemoryError, setPhysicalAllocationFailed, setPriority, setupBootJavaThread, setupBootThread, shouldBeSampled, sleep, sleep, snapshotHandshakeThreads, softHandshake, softRendezvous, softRendezvousCheckAndClear, softRendezvousCommit, start, stop, suspend, terminate, trace, trace, trace, traceback, traceback, traceHex, unblock, unpark, wait, wait, waitAbsoluteNanos, worldStopped, yield, yieldpoint, yieldpointFromBackedge, yieldpointFromEpilogue, yieldpointFromPrologue, yieldpointsEnabled
 
Methods inherited from class org.jikesrvm.mm.mminterface.Selected.Mutator
get, getThread
 
Methods inherited from class org.mmtk.plan.generational.immix.GenImmixMutator
alloc, collectionPhase, getAllocatorFromSpace, postAlloc
 
Methods inherited from class org.mmtk.plan.generational.GenMutator
assertRemsetsFlushed, flushRememberedSets, objectReferenceBulkCopy, objectReferenceNonHeapWrite, objectReferenceTryCompareAndSwap, objectReferenceWrite
 
Methods inherited from class org.mmtk.plan.MutatorContext
addressBulkCopy, addressRead, addressTryCompareAndSwap, addressWrite, booleanBulkCopy, booleanRead, booleanWrite, byteBulkCopy, byteRead, byteWrite, charBulkCopy, charRead, charWrite, checkAllocator, deinitMutator, doubleBulkCopy, doubleRead, doubleWrite, extentBulkCopy, extentRead, extentWrite, floatBulkCopy, floatRead, floatWrite, flush, getId, getLog, initMutator, intBulkCopy, intRead, intTryCompareAndSwap, intWrite, javaLangReferenceReadBarrier, longBulkCopy, longRead, longTryCompareAndSwap, longWrite, objectReferenceNonHeapRead, objectReferenceRead, offsetBulkCopy, offsetRead, offsetWrite, shortBulkCopy, shortRead, shortWrite, wordBulkCopy, wordRead, wordTryCompareAndSwap, wordWrite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

verbose

private static final int verbose
Class variables

See Also:
Constant Field Values

myName

private static final String myName
Name used by toString() and when we create the associated java.lang.Thread.

See Also:
Constant Field Values

DISPLAY_OPTIONS_AT_BOOT

static final boolean DISPLAY_OPTIONS_AT_BOOT
When true, causes RVM collectors to display heap configuration at startup

See Also:
Constant Field Values

TIME_GC_PHASES

public static final boolean TIME_GC_PHASES
When true, causes RVM collectors to measure time spent in each phase of collection. Will also force summary statistics to be generated.

See Also:
Constant Field Values

MEASURE_WAIT_TIMES

public static final boolean MEASURE_WAIT_TIMES
When true, collector threads measure time spent waiting for buffers while processing the Work Deque, and time spent waiting in Rendezvous during the collection process. Will also force summary statistics to be generated.

See Also:
Constant Field Values

GC_ORDINAL_BASE

public static final int GC_ORDINAL_BASE
gc threads are indexed from 1 for now...

See Also:
Constant Field Values

participantCount

static final int[] participantCount
array of size 1 to count arriving collector threads


collectionCount

static int collectionCount
number of collections


handshake

public static final Handshake handshake
The Handshake object that contains the state of the next or current (in progress) collection. Read by mutators when detecting a need for a collection, and passed to the collect method when requesting a collection.


gcBarrier

public static SynchronizationBarrier gcBarrier
Use by collector threads to rendezvous during collection


collectionAttemptBase

public static int collectionAttemptBase
The base collection attempt


gcOrdinal

private int gcOrdinal
arrival order of collectorThreads participating in a collection


threadScanner

private final ScanThread threadScanner
used by each CollectorThread when scanning stacks for references


timeInRendezvous

int timeInRendezvous
time waiting in rendezvous (milliseconds)


gcThreadRunning

static boolean gcThreadRunning

stackTraceThread

private Address stackTraceThread
The thread to use to determine stack traces if Throwables are created


nextId

private static int nextId
Next collector thread id. Collector threads are not created concurrently.

Constructor Detail

CollectorThread

CollectorThread(byte[] stack)
Constructor

Parameters:
stack - The stack this thread will run on
Method Detail

getThreadScanner

public ScanThread getThreadScanner()
Returns:
the thread scanner instance associated with this instance

isGCThread

public boolean isGCThread()
Is this the GC thread?

Overrides:
isGCThread in class RVMThread
Returns:
true

getThreadForStackTrace

public RVMThread getThreadForStackTrace()
Get the thread to use for building stack traces.

Overrides:
getThreadForStackTrace in class RVMThread

setThreadForStackTrace

public void setThreadForStackTrace(RVMThread thread)
Set the thread to use for building stack traces.


clearThreadForStackTrace

public void clearThreadForStackTrace()
Set the thread to use for building stack traces.


init

public static void init()
Initialize for boot image.


boot

public static void boot()

createActiveCollectorThread

public static CollectorThread createActiveCollectorThread()
Make a collector thread that will participate in gc.

Note: the new thread's stack must be in pinned memory: currently done by allocating it in immortal memory.

Returns:
a new collector thread

collect

public static void collect(Handshake handshake,
                           int why)
Initiate a garbage collection. Called by a mutator thread when its allocator runs out of space. The caller should pass the Handshake that was referenced by the static variable "collect" at the time space was unavailable.

Parameters:
handshake - Handshake for the requested collection

asyncCollect

public static void asyncCollect(Handshake handshake,
                                int why)
Initiate a garbage collection at next GC safe point. Called by a mutator thread at any time. The caller should pass the Handshake that was referenced by the static variable "collect".

Parameters:
handshake - Handshake for the requested collection

toString

public String toString()
Override Thread.toString

Overrides:
toString in class RVMThread
Returns:
A string describing this thread.

numCollectors

public static int numCollectors()
Returns number of collector threads participating in a collection

Returns:
The number of collector threads participating in a collection

getGCOrdinal

public int getGCOrdinal()
Return the GC ordinal for this collector thread. An integer, 1,2,... assigned to each collector thread participating in the current collection. Only valid while GC is "InProgress".

Returns:
The GC ordinal

setGCOrdinal

public void setGCOrdinal(int ord)
Set the GC ordinal for this collector thread. An integer, 1,2,... assigned to each collector thread participating in the current collection.

Parameters:
ord - The new GC ordinal for this thread

run

public void run()
Run method for collector thread (one per processor). Enters an infinite loop, waiting for collections to be requested, performing those collections, and then waiting again. Calls Collection.collect to perform the collection, which will be different for the different allocators/collectors that the RVM can be configured to use.

Overrides:
run in class RVMThread

noThreadsInGC

public static boolean noThreadsInGC()
Return true if no threads are still in GC.

Returns:
true if no threads are still in GC.

rendezvous

public int rendezvous(int where)

allocateOOMEForThread

public void allocateOOMEForThread(RVMThread thread)
Allocate an OutOfMemoryError for a given thread.

Parameters:
thread -