org.mmtk.plan
Class Phase

java.lang.Object
  extended by org.mmtk.plan.Phase
All Implemented Interfaces:
Constants
Direct Known Subclasses:
ComplexPhase, ConcurrentPhase, SimplePhase

public abstract class Phase
extends Object
implements Constants

A garbage collection proceeds as a sequence of phases. Each phase is either simple (singular) or complex (an array).

The context an individual phase executes in may be global, mutator, or collector.

Phases are executed within a stack and all synchronization between parallel GC threads is managed from within this class.

See Also:
MutatorContext.collectionPhase(short, boolean)

Field Summary
private static boolean allowConcurrentPhase
          Do we want to allow new concurrent workers to become active
private static int[] complexPhaseCursor
          Stores the current sub phase for a complex phase.
private static short concurrentPhaseId
          The concurrent phase being executed
private static boolean evenMutatorResetRendezvous
          Do we need to add a sync point to reset the mutator count.
private static int evenScheduledPhase
          The current even (0 mod 2) scheduled phase.
protected  short id
          The unique phase identifier.
private static int MAX_PHASE_STACK_DEPTH
          The maximum stack depth for the phase stack.
private static int MAX_PHASES
          The maximum number of phases
protected  String name
          The name of the phase.
private static short nextPhaseId
          The id to be allocated for the next phase
private static boolean oddMutatorResetRendezvous
          Do we need to add a sync point to reset the mutator count.
private static int oddScheduledPhase
          The current odd (1 mod 2) scheduled phase.
private static Phase[] phases
          The array of phase instances.
private static int[] phaseStack
          The phase stack.
private static int phaseStackPointer
          The current stack pointer
protected static short SCHEDULE_COLLECTOR
          Run the phase on collectors.
protected static short SCHEDULE_COMPLEX
          This is a complex phase.
protected static short SCHEDULE_CONCURRENT
          Run this phase concurrently with the mutators
protected static short SCHEDULE_GLOBAL
          Run the phase globally.
protected static short SCHEDULE_MUTATOR
          Run the phase on mutators.
protected static short SCHEDULE_PLACEHOLDER
          Don't run this phase.
private static short startComplexTimer
          The complex phase whose timer should be started after the next rendezvous.
private static short stopComplexTimer
          The complex phase whose timer should be stopped after the next rendezvous.
protected  Timer timer
          The Timer that is started and stopped around the execution of this phase.
 
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
protected Phase(String name)
          Create a new Phase.
protected Phase(String name, Timer timer)
          Create a new phase.
 
Method Summary
static void beginNewPhaseStack(int scheduledPhase)
          Place a phase on the phase stack and begin processing.
static void clearConcurrentPhase()
          Clear the current phase Id.
static boolean concurrentPhaseActive()
           
static void continuePhaseStack()
          Continue the execution of a phase stack.
static short createComplex(String name, int... scheduledPhases)
          Construct a complex phase.
static short createComplex(String name, Timer timer, int... scheduledPhases)
          Construct a complex phase, re-using a specified timer.
static short createConcurrent(String name, int atomicScheduledPhase)
          Construct a phase.
static short createConcurrent(String name, Timer timer, int atomicScheduledPhase)
          Construct a phase, re-using a specified timer.
static short createSimple(String name)
          Construct a phase.
static short createSimple(String name, Timer timer)
          Construct a phase, re-using a specified timer.
static short getConcurrentPhaseId()
          Get the current phase Id.
private static int getCurrentPhase(boolean isEvenPhase)
          Get the next phase.
 short getId()
           
static String getName(short phaseId)
           
private static int getNextPhase()
          Pull the next scheduled phase off the stack.
static Phase getPhase(short id)
          Retrieve a phase by the unique phase identifier.
protected static short getPhaseId(int scheduledPhase)
          Get the phase id component of an encoded phase
protected static short getSchedule(int scheduledPhase)
          Get the ordering component of an encoded phase
protected static String getScheduleName(short ordering)
          Get the ordering component of an encoded phase
private static int incrementComplexPhaseCursor()
          Increment the cursor associated with the current phase stack entry.
static boolean isPhaseStackEmpty()
          Return true if phase stack is empty, false otherwise.
protected abstract  void logPhase()
          Display a description of this phase, for debugging purposes.
private static boolean needsMutatorResetRendezvous(boolean isEvenPhase)
          Do we need a mutator reset rendezvous in this phase?
static boolean notifyConcurrentPhaseComplete()
          Notify that the concurrent phase has completed successfully.
static void notifyConcurrentPhaseIncomplete()
          Notify that the concurrent phase has not finished, and must be re-attempted.
private static void pauseComplexTimers()
          Pause all of the timers for the complex phases sitting in the stack.
private static int peekScheduledPhase()
          Peek the scheduled phase at the top of the work stack.
private static int popScheduledPhase()
          Pop off the scheduled phase at the top of the work stack.
private static void processPhaseStack(boolean resume)
          Process the phase stack.
static void pushScheduledPhase(int scheduledPhase)
          Push a scheduled phase onto the top of the work stack.
static void resetPhaseStack()
          Clears the scheduled phase stack.
private static void resumeComplexTimers()
          Resume all of the timers for the complex phases sitting in the stack.
static int scheduleCollector(short phaseId)
          Take the passed phase and return an encoded phase to run that phase in a collector context;
static int scheduleComplex(short phaseId)
          Take the passed phase and return an encoded phase to run that phase as a complex phase.
static int scheduleConcurrent(short phaseId)
          Take the passed phase and return an encoded phase to run that phase as a concurrent phase.
static int scheduleGlobal(short phaseId)
          Take the passed phase and return an encoded phase to run that phase in a global context;
static int scheduleMutator(short phaseId)
          Take the passed phase and return an encoded phase to run that phase in a mutator context;
static int schedulePlaceholder(short phaseId)
          Take the passed phase and return an encoded phase to run that phase in a mutator context;
private static void setNextPhase(boolean isEvenPhase, int scheduledPhase, boolean needsResetRendezvous)
          Set the next phase.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PHASES

private static final int MAX_PHASES
The maximum number of phases

See Also:
Constant Field Values

phases

private static final Phase[] phases
The array of phase instances. Zero is unused.


nextPhaseId

private static short nextPhaseId
The id to be allocated for the next phase


SCHEDULE_GLOBAL

protected static final short SCHEDULE_GLOBAL
Run the phase globally.

See Also:
Constant Field Values

SCHEDULE_COLLECTOR

protected static final short SCHEDULE_COLLECTOR
Run the phase on collectors.

See Also:
Constant Field Values

SCHEDULE_MUTATOR

protected static final short SCHEDULE_MUTATOR
Run the phase on mutators.

See Also:
Constant Field Values

SCHEDULE_CONCURRENT

protected static final short SCHEDULE_CONCURRENT
Run this phase concurrently with the mutators

See Also:
Constant Field Values

SCHEDULE_PLACEHOLDER

protected static final short SCHEDULE_PLACEHOLDER
Don't run this phase.

See Also:
Constant Field Values

SCHEDULE_COMPLEX

protected static final short SCHEDULE_COMPLEX
This is a complex phase.

See Also:
Constant Field Values

id

protected final short id
The unique phase identifier.


name

protected final String name
The name of the phase.


timer

protected final Timer timer
The Timer that is started and stopped around the execution of this phase.


MAX_PHASE_STACK_DEPTH

private static final int MAX_PHASE_STACK_DEPTH
The maximum stack depth for the phase stack.

See Also:
Constant Field Values

complexPhaseCursor

private static int[] complexPhaseCursor
Stores the current sub phase for a complex phase. Each entry corresponds to a phase stack entry


phaseStack

private static int[] phaseStack
The phase stack. Stores the current nesting of phases


phaseStackPointer

private static int phaseStackPointer
The current stack pointer


evenScheduledPhase

private static int evenScheduledPhase
The current even (0 mod 2) scheduled phase. As we only sync at the end of a phase we need this to ensure that the primary thread setting the phase does not race with the other threads reading it.


oddScheduledPhase

private static int oddScheduledPhase
The current odd (1 mod 2) scheduled phase. As we only sync at the end of a phase we need this to ensure that the primary thread setting the phase does not race with the other threads reading it.


evenMutatorResetRendezvous

private static boolean evenMutatorResetRendezvous
Do we need to add a sync point to reset the mutator count. This is necessary for consecutive mutator phases and unnecessary otherwise. Again we separate in even and odd to ensure that there is no race between the primary thread setting and the helper threads reading.


oddMutatorResetRendezvous

private static boolean oddMutatorResetRendezvous
Do we need to add a sync point to reset the mutator count. This is necessary for consecutive mutator phases and unnecessary otherwise. Again we separate in even and odd to ensure that there is no race between the primary thread setting and the helper threads reading.


startComplexTimer

private static short startComplexTimer
The complex phase whose timer should be started after the next rendezvous. We can not start the timer at the point we determine the next complex phase as we determine the next phase at the end of the previous phase before the sync point.


stopComplexTimer

private static short stopComplexTimer
The complex phase whose timer should be stopped after the next rendezvous. We can not start the timer at the point we determine the next complex phase as we determine the next phase at the end of the previous phase before the sync point.


concurrentPhaseId

private static short concurrentPhaseId
The concurrent phase being executed


allowConcurrentPhase

private static boolean allowConcurrentPhase
Do we want to allow new concurrent workers to become active

Constructor Detail

Phase

protected Phase(String name)
Create a new Phase. This involves creating a corresponding Timer instance, allocating a unique identifier, and registering the Phase.

Parameters:
name - The name for the phase.

Phase

protected Phase(String name,
                Timer timer)
Create a new phase. This involves setting the corresponding Timer instance, allocating a unique identifier, and registering the Phase.

Parameters:
name - The name of the phase.
timer - The timer, or null if this is an untimed phase.
Method Detail

getPhase

public static Phase getPhase(short id)
Retrieve a phase by the unique phase identifier.

Parameters:
id - The phase identifier.
Returns:
The Phase instance.

getPhaseId

protected static short getPhaseId(int scheduledPhase)
Get the phase id component of an encoded phase


getName

public static String getName(short phaseId)
Parameters:
phaseId - The unique phase identifier.
Returns:
The name of the phase.

getSchedule

protected static short getSchedule(int scheduledPhase)
Get the ordering component of an encoded phase


getScheduleName

protected static String getScheduleName(short ordering)
Get the ordering component of an encoded phase


createSimple

public static short createSimple(String name)
Construct a phase.

Parameters:
name - Display name of the phase

createSimple

public static short createSimple(String name,
                                 Timer timer)
Construct a phase, re-using a specified timer.

Parameters:
name - Display name of the phase

createComplex

public static short createComplex(String name,
                                  int... scheduledPhases)
Construct a complex phase.

Parameters:
name - Display name of the phase
scheduledPhases - The phases in this complex phase.

createComplex

public static short createComplex(String name,
                                  Timer timer,
                                  int... scheduledPhases)
Construct a complex phase, re-using a specified timer.

Parameters:
name - Display name of the phase
timer - Timer for this phase to contribute to
scheduledPhases - The phases in this complex phase.

createConcurrent

public static final short createConcurrent(String name,
                                           int atomicScheduledPhase)
Construct a phase.

Parameters:
name - Display name of the phase
atomicScheduledPhase - The corresponding atomic phase to run in a stop the world collection

createConcurrent

public static final short createConcurrent(String name,
                                           Timer timer,
                                           int atomicScheduledPhase)
Construct a phase, re-using a specified timer.

Parameters:
name - Display name of the phase
timer - Timer for this phase to contribute to
atomicScheduledPhase - The corresponding atomic phase to run in a stop the world collection

scheduleComplex

public static int scheduleComplex(short phaseId)
Take the passed phase and return an encoded phase to run that phase as a complex phase.

Parameters:
phaseId - The phase to run as complex
Returns:
The encoded phase value.

scheduleConcurrent

public static int scheduleConcurrent(short phaseId)
Take the passed phase and return an encoded phase to run that phase as a concurrent phase.

Parameters:
phaseId - The phase to run as concurrent
Returns:
The encoded phase value.

scheduleGlobal

public static int scheduleGlobal(short phaseId)
Take the passed phase and return an encoded phase to run that phase in a global context;

Parameters:
phaseId - The phase to run globally
Returns:
The encoded phase value.

scheduleCollector

public static int scheduleCollector(short phaseId)
Take the passed phase and return an encoded phase to run that phase in a collector context;

Parameters:
phaseId - The phase to run on collectors
Returns:
The encoded phase value.

scheduleMutator

public static int scheduleMutator(short phaseId)
Take the passed phase and return an encoded phase to run that phase in a mutator context;

Parameters:
phaseId - The phase to run on mutators
Returns:
The encoded phase value.

schedulePlaceholder

public static int schedulePlaceholder(short phaseId)
Take the passed phase and return an encoded phase to run that phase in a mutator context;

Parameters:
phaseId - The phase to run on mutators
Returns:
The encoded phase value.

getId

public final short getId()
Returns:
The unique identifier for this phase.

logPhase

protected abstract void logPhase()
Display a description of this phase, for debugging purposes.


beginNewPhaseStack

public static void beginNewPhaseStack(int scheduledPhase)
Place a phase on the phase stack and begin processing.

Parameters:
scheduledPhase - The phase to execute

continuePhaseStack

public static void continuePhaseStack()
Continue the execution of a phase stack. Used for incremental and concurrent collection.


processPhaseStack

private static void processPhaseStack(boolean resume)
Process the phase stack. This method is called by multiple threads.


getCurrentPhase

private static int getCurrentPhase(boolean isEvenPhase)
Get the next phase.


needsMutatorResetRendezvous

private static boolean needsMutatorResetRendezvous(boolean isEvenPhase)
Do we need a mutator reset rendezvous in this phase?


setNextPhase

private static void setNextPhase(boolean isEvenPhase,
                                 int scheduledPhase,
                                 boolean needsResetRendezvous)
Set the next phase. If we are in an even phase the next phase is odd.


getNextPhase

private static int getNextPhase()
Pull the next scheduled phase off the stack. This may involve processing several complex phases and skipping placeholders, etc.

Returns:
The next phase to run, or -1 if no phases are left.

pauseComplexTimers

private static void pauseComplexTimers()
Pause all of the timers for the complex phases sitting in the stack.


resumeComplexTimers

private static void resumeComplexTimers()
Resume all of the timers for the complex phases sitting in the stack.


isPhaseStackEmpty

public static boolean isPhaseStackEmpty()
Return true if phase stack is empty, false otherwise.

Returns:
true if phase stack is empty, false otherwise.

resetPhaseStack

public static void resetPhaseStack()
Clears the scheduled phase stack.


pushScheduledPhase

public static void pushScheduledPhase(int scheduledPhase)
Push a scheduled phase onto the top of the work stack.

Parameters:
scheduledPhase - The scheduled phase.

incrementComplexPhaseCursor

private static int incrementComplexPhaseCursor()
Increment the cursor associated with the current phase stack entry. This is used to remember the current sub phase when executing a complex phase.

Returns:
The old value of the cursor.

popScheduledPhase

private static int popScheduledPhase()
Pop off the scheduled phase at the top of the work stack.


peekScheduledPhase

private static int peekScheduledPhase()
Peek the scheduled phase at the top of the work stack.


getConcurrentPhaseId

public static short getConcurrentPhaseId()
Get the current phase Id.


clearConcurrentPhase

public static void clearConcurrentPhase()
Clear the current phase Id.


concurrentPhaseActive

public static boolean concurrentPhaseActive()
Returns:
trueif there is an active concurrent phase.

notifyConcurrentPhaseComplete

public static boolean notifyConcurrentPhaseComplete()
Notify that the concurrent phase has completed successfully. This must only be called by a single thread after it has determined that the phase has been completed successfully.


notifyConcurrentPhaseIncomplete

public static void notifyConcurrentPhaseIncomplete()
Notify that the concurrent phase has not finished, and must be re-attempted.