org.mmtk.plan
Class Plan

java.lang.Object
  extended by org.mmtk.plan.Plan
All Implemented Interfaces:
Constants
Direct Known Subclasses:
NoGC, Simple

public abstract class Plan
extends Object
implements Constants

This abstract class implements the global core functionality for all memory management schemes. All global MMTk plans should inherit from this class.

All plans make a clear distinction between global and thread-local activities, and divides global and local state into separate class hierarchies. Global activities must be synchronized, whereas no synchronization is required for thread-local activities. There is a single instance of Plan (or the appropriate sub-class), and a 1:1 mapping of PlanLocal to "kernel threads" (aka CPUs). Thus instance methods of PlanLocal allow fast, unsynchronized access to functions such as allocation and collection. The global instance defines and manages static resources (such as memory and virtual memory resources). This mapping of threads to instances is crucial to understanding the correctness and performance properties of MMTk plans.


Field Summary
static int ALLOC_CODE
           
static int ALLOC_COLD_CODE
           
static int ALLOC_DEFAULT
           
static int ALLOC_GCSPY
           
static int ALLOC_HOT_CODE
           
static int ALLOC_IMMORTAL
           
static int ALLOC_LARGE_CODE
           
static int ALLOC_LOS
           
static int ALLOC_NON_MOVING
           
static int ALLOC_NON_REFERENCE
           
static int ALLOC_PRIMITIVE_LOS
           
static int ALLOC_STACK
           
protected static int allocationSiteCount
          Support for allocation-site identification
static int ALLOCATORS
           
static ParallelCollectorGroup concurrentWorkers
           
static ControllerCollectorContext controlCollectorContext
           
static int DEFAULT_MAX_NURSERY
           
static int DEFAULT_MIN_NURSERY
           
static int DEFAULT_SITE
           
protected  Class<? extends ParallelCollector> defaultCollectorContext
          Default collector context
protected static boolean emergencyCollection
           
static boolean GATHER_WRITE_BARRIER_STATS
           
static int GC_PREPARE
           
static int GC_PROPER
           
private static int gcStatus
           
static int IMMORTAL
           
static ImmortalSpace immortalSpace
          Any immortal objects allocated after booting are allocated here.
private static boolean initialized
           
protected static boolean insideHarness
           
protected static boolean internalTriggeredCollection
           
static int LARGE_CODE
           
static LargeObjectSpace largeCodeSpace
           
protected static boolean lastInternalTriggeredCollection
           
private  long lastStressPages
           
static int LOS
           
static LargeObjectSpace loSpace
          Large objects are allocated into a special large object space.
static int MAX_NON_LOS_COPY_BYTES
           
static int MAX_NON_LOS_DEFAULT_ALLOC_BYTES
           
static int MAX_NON_LOS_NONMOVING_ALLOC_BYTES
           
static int META
           
static RawPageSpace metaDataSpace
          All meta data that is used by MMTk is allocated (and accounted for) in the meta data space.
static boolean NEEDS_LOG_BIT_IN_HEADER
           
static int NON_MOVING
           
static int NON_PARTICIPANT
           
static MarkSweepSpace nonMovingSpace
          Space used to allocate objects that cannot be moved. we do not need a large space as the LOS is non-moving.
static int NOT_IN_GC
           
static ParallelCollectorGroup parallelWorkers
           
static int pretenureThreshold
           
static int SANITY
           
static SanityChecker sanityChecker
          Global sanity checking state
static RawPageSpace sanitySpace
          Space used by the sanity checker (used at runtime only if sanity checking enabled
static boolean SCAN_BOOT_IMAGE
           
static int SMALL_CODE
           
static MarkSweepSpace smallCodeSpace
           
protected static boolean stacksPrepared
           
static Timer totalTime
          Timer that counts total time
static boolean USE_CODE_SPACE
           
protected static boolean userTriggeredCollection
           
static int VM_SPACE
           
static Space vmSpace
          The space that holds any VM specific objects (e.g. a boot image)
 
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
Plan()
          Constructor.
 
Method Summary
static Extent availableMemory()
          Return the amount of available memory, in bytes.
 Word bootTimeWriteBarrier(Word reference)
          Perform any required write barrier action when installing an object reference a boot time.
abstract  void collectionPhase(short phaseId)
          Perform a (global) collection phase.
protected  boolean collectionRequired(boolean spaceFull, Space space)
          This method controls the triggering of a GC.
protected  boolean concurrentCollectionRequired()
          This method controls the triggering of an atomic phase of a concurrent collection.
 void enableAllocation()
          The enableAllocation method is called early in the boot process to allow allocation.
 void enableCollection()
          The enableCollection method is called by the runtime after it is safe to spawn collector contexts and allow garbage collection.
 void forceFullHeapCollection()
          Force the next collection to be full heap.
static Extent freeMemory()
          Return the amount of free memory, in bytes (where free is defined as not in use).
 void fullyBooted()
           
static boolean gcInProgress()
          Return true if a collection is in progress.
static boolean gcInProgressProper()
          Return true if a collection is in progress and past the preparatory stage.
static int getAllocationSite(boolean compileTime)
           
 int getCollectionReserve()
          Return the number of pages reserved for collection.
 int getPagesAvail()
          Return the number of pages available for allocation.
 int getPagesReserved()
          Return the number of pages reserved for use given the pending allocation.
 int getPagesUsed()
          Return the number of pages reserved for use given the pending allocation.
 Class<?> getSpecializedScanClass(int id)
          Get the specialized scan with the given id.
 int getTotalPages()
          Return the total amount of memory managed to the memory management system, in pages.
static void handleUserCollectionRequest()
          The application code has requested a collection.
static void harnessBegin()
          Generic hook to allow benchmarks to be harnessed.
static void harnessEnd()
          Generic hook to allow benchmarks to be harnessed.
 void insertPhaseAfter(int markerScheduledPhase, int scheduledPhase)
          Insert a phase.
 boolean isCurrentGCNursery()
           
static boolean isEmergencyCollection()
           
static boolean isInitialized()
           
static boolean isInternalTriggeredCollection()
           
static boolean isUserTriggeredCollection()
           
 boolean lastCollectionFullHeap()
           
 boolean lastCollectionWasExhaustive()
           
 ObjectReference loadObjectReference(Address slot)
          Load an object reference
protected  void logPoll(Space space, String message)
          Log a message from within 'poll'
 void notifyExit(int value)
          The VM is about to exit.
 boolean poll(boolean spaceFull, Space space)
          This method is called periodically by the allocation subsystem (by default, each time a page is consumed), and provides the collector with an opportunity to collect.
protected  void printDetailedTiming(boolean totals)
          Any Plan can override this to provide additional plan specific timing information.
 void printPostStats()
          Print out statistics at the end of a GC
 void printPreStats()
          Print pre-collection statistics.
 void printUsedPages()
           
 void processOptions()
          The processOptions method is called by the runtime immediately after command-line arguments are available.
protected  void registerSpecializedMethods()
          Register specialized methods.
 void replacePhase(int oldScheduledPhase, int scheduledPhase)
          Replace a phase.
static Extent reservedMemory()
          Return the amount of memory in use, in bytes.
static void resetCollectionTrigger()
          Reset collection state information.
 int sanityExpectedRC(ObjectReference object, int sanityRootRC)
          Return the expected reference count.
 void sanityLinearScan(LinearScan scanner)
          Perform a linear scan of all spaces to check for possible leaks.
static void setGCStatus(int s)
          Sets the GC status.
static boolean stacksPrepared()
          Return true if stacks have been prepared in this collection cycle.
 void startGCspyServer(int port, boolean wait)
          Start GCspy server.
 void storeObjectReference(Address slot, ObjectReference value)
          Store an object reference
 boolean stressTestGCRequired()
           
static Extent totalMemory()
          Return the total amount of memory managed to the memory management system, in bytes.
static void triggerInternalCollectionRequest()
          MMTK has requested stop-the-world activity (e.g., stw within a concurrent gc).
static Extent usedMemory()
          Return the amount of memory in use, in bytes.
 boolean willNeverMove(ObjectReference object)
          Can this object ever move.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_IN_GC

public static final int NOT_IN_GC
See Also:
Constant Field Values

GC_PREPARE

public static final int GC_PREPARE
See Also:
Constant Field Values

GC_PROPER

public static final int GC_PROPER
See Also:
Constant Field Values

USE_CODE_SPACE

public static final boolean USE_CODE_SPACE
See Also:
Constant Field Values

ALLOC_DEFAULT

public static final int ALLOC_DEFAULT
See Also:
Constant Field Values

ALLOC_NON_REFERENCE

public static final int ALLOC_NON_REFERENCE
See Also:
Constant Field Values

ALLOC_NON_MOVING

public static final int ALLOC_NON_MOVING
See Also:
Constant Field Values

ALLOC_IMMORTAL

public static final int ALLOC_IMMORTAL
See Also:
Constant Field Values

ALLOC_LOS

public static final int ALLOC_LOS
See Also:
Constant Field Values

ALLOC_PRIMITIVE_LOS

public static final int ALLOC_PRIMITIVE_LOS
See Also:
Constant Field Values

ALLOC_GCSPY

public static final int ALLOC_GCSPY
See Also:
Constant Field Values

ALLOC_CODE

public static final int ALLOC_CODE
See Also:
Constant Field Values

ALLOC_LARGE_CODE

public static final int ALLOC_LARGE_CODE
See Also:
Constant Field Values

ALLOC_HOT_CODE

public static final int ALLOC_HOT_CODE
See Also:
Constant Field Values

ALLOC_COLD_CODE

public static final int ALLOC_COLD_CODE
See Also:
Constant Field Values

ALLOC_STACK

public static final int ALLOC_STACK
See Also:
Constant Field Values

ALLOCATORS

public static final int ALLOCATORS
See Also:
Constant Field Values

DEFAULT_SITE

public static final int DEFAULT_SITE
See Also:
Constant Field Values

NON_PARTICIPANT

public static final int NON_PARTICIPANT
See Also:
Constant Field Values

GATHER_WRITE_BARRIER_STATS

public static final boolean GATHER_WRITE_BARRIER_STATS
See Also:
Constant Field Values

DEFAULT_MIN_NURSERY

public static final int DEFAULT_MIN_NURSERY

DEFAULT_MAX_NURSERY

public static final int DEFAULT_MAX_NURSERY

SCAN_BOOT_IMAGE

public static final boolean SCAN_BOOT_IMAGE
See Also:
Constant Field Values

MAX_NON_LOS_DEFAULT_ALLOC_BYTES

public static final int MAX_NON_LOS_DEFAULT_ALLOC_BYTES

MAX_NON_LOS_NONMOVING_ALLOC_BYTES

public static final int MAX_NON_LOS_NONMOVING_ALLOC_BYTES

MAX_NON_LOS_COPY_BYTES

public static final int MAX_NON_LOS_COPY_BYTES

NEEDS_LOG_BIT_IN_HEADER

public static final boolean NEEDS_LOG_BIT_IN_HEADER

vmSpace

public static final Space vmSpace
The space that holds any VM specific objects (e.g. a boot image)


immortalSpace

public static final ImmortalSpace immortalSpace
Any immortal objects allocated after booting are allocated here.


metaDataSpace

public static final RawPageSpace metaDataSpace
All meta data that is used by MMTk is allocated (and accounted for) in the meta data space.


loSpace

public static final LargeObjectSpace loSpace
Large objects are allocated into a special large object space.


sanitySpace

public static final RawPageSpace sanitySpace
Space used by the sanity checker (used at runtime only if sanity checking enabled


nonMovingSpace

public static final MarkSweepSpace nonMovingSpace
Space used to allocate objects that cannot be moved. we do not need a large space as the LOS is non-moving.


smallCodeSpace

public static final MarkSweepSpace smallCodeSpace

largeCodeSpace

public static final LargeObjectSpace largeCodeSpace

pretenureThreshold

public static int pretenureThreshold

IMMORTAL

public static final int IMMORTAL

VM_SPACE

public static final int VM_SPACE

META

public static final int META

LOS

public static final int LOS

SANITY

public static final int SANITY

NON_MOVING

public static final int NON_MOVING

SMALL_CODE

public static final int SMALL_CODE

LARGE_CODE

public static final int LARGE_CODE

totalTime

public static final Timer totalTime
Timer that counts total time


allocationSiteCount

protected static int allocationSiteCount
Support for allocation-site identification


sanityChecker

public static final SanityChecker sanityChecker
Global sanity checking state


defaultCollectorContext

protected final Class<? extends ParallelCollector> defaultCollectorContext
Default collector context


parallelWorkers

public static final ParallelCollectorGroup parallelWorkers

concurrentWorkers

public static final ParallelCollectorGroup concurrentWorkers

controlCollectorContext

public static final ControllerCollectorContext controlCollectorContext

lastStressPages

private long lastStressPages

userTriggeredCollection

protected static boolean userTriggeredCollection

internalTriggeredCollection

protected static boolean internalTriggeredCollection

lastInternalTriggeredCollection

protected static boolean lastInternalTriggeredCollection

emergencyCollection

protected static boolean emergencyCollection

stacksPrepared

protected static boolean stacksPrepared

initialized

private static boolean initialized

gcStatus

private static int gcStatus

insideHarness

protected static boolean insideHarness
Constructor Detail

Plan

public Plan()
Constructor.

Method Detail

enableAllocation

public void enableAllocation()
The enableAllocation method is called early in the boot process to allow allocation.


processOptions

public void processOptions()
The processOptions method is called by the runtime immediately after command-line arguments are available. Allocation must be supported prior to this point because the runtime infrastructure may require allocation in order to parse the command line arguments. For this reason all plans should operate gracefully on the default minimum heap size until the point that processOptions is called.


enableCollection

public void enableCollection()
The enableCollection method is called by the runtime after it is safe to spawn collector contexts and allow garbage collection.


fullyBooted

public void fullyBooted()

notifyExit

public void notifyExit(int value)
The VM is about to exit. Perform any clean up operations.

Parameters:
value - The exit value

printDetailedTiming

protected void printDetailedTiming(boolean totals)
Any Plan can override this to provide additional plan specific timing information.

Parameters:
totals - Print totals

bootTimeWriteBarrier

public Word bootTimeWriteBarrier(Word reference)
Perform any required write barrier action when installing an object reference a boot time.

Parameters:
reference - the reference value that is to be stored
Returns:
The raw value to be

getAllocationSite

public static int getAllocationSite(boolean compileTime)
Parameters:
compileTime - is this a call by the compiler?
Returns:
an allocation site

collectionPhase

public abstract void collectionPhase(short phaseId)
Perform a (global) collection phase.

Parameters:
phaseId - The unique id of the phase to perform.

replacePhase

public void replacePhase(int oldScheduledPhase,
                         int scheduledPhase)
Replace a phase.

Parameters:
oldScheduledPhase - The scheduled phase to insert after
scheduledPhase - The scheduled phase to insert

insertPhaseAfter

public void insertPhaseAfter(int markerScheduledPhase,
                             int scheduledPhase)
Insert a phase.

Parameters:
markerScheduledPhase - The scheduled phase to insert after
scheduledPhase - The scheduled phase to insert

lastCollectionWasExhaustive

public boolean lastCollectionWasExhaustive()
Returns:
Whether last GC was an exhaustive attempt to collect the heap. For many collectors this is the same as asking whether the last GC was a full heap collection.

lastCollectionFullHeap

public boolean lastCollectionFullHeap()
Returns:
Whether last GC is a full GC.

isEmergencyCollection

public static boolean isEmergencyCollection()
Returns:
Is last GC a full collection?

forceFullHeapCollection

public void forceFullHeapCollection()
Force the next collection to be full heap.


isCurrentGCNursery

public boolean isCurrentGCNursery()
Returns:
Is current GC only collecting objects allocated since last GC.

sanityExpectedRC

public int sanityExpectedRC(ObjectReference object,
                            int sanityRootRC)
Return the expected reference count. For non-reference counting collectors this becomes a true/false relationship.

Parameters:
object - The object to check.
sanityRootRC - The number of root references to the object.
Returns:
The expected (root excluded) reference count.

sanityLinearScan

public void sanityLinearScan(LinearScan scanner)
Perform a linear scan of all spaces to check for possible leaks. This is only called after a full-heap GC.

Parameters:
scanner - The scanner callback to use.

stressTestGCRequired

public final boolean stressTestGCRequired()
Returns:
true is a stress test GC is required

isInitialized

public static boolean isInitialized()
Returns:
Is the memory management system initialized?

stacksPrepared

public static boolean stacksPrepared()
Return true if stacks have been prepared in this collection cycle.

Returns:
true if stacks have been prepared in this collection cycle.

gcInProgress

public static boolean gcInProgress()
Return true if a collection is in progress.

Returns:
true if a collection is in progress.

gcInProgressProper

public static boolean gcInProgressProper()
Return true if a collection is in progress and past the preparatory stage.

Returns:
true if a collection is in progress and past the preparatory stage.

setGCStatus

public static void setGCStatus(int s)
Sets the GC status.

Parameters:
s - The new GC status.

printPreStats

public void printPreStats()
Print pre-collection statistics.


printPostStats

public final void printPostStats()
Print out statistics at the end of a GC


printUsedPages

public final void printUsedPages()

handleUserCollectionRequest

public static void handleUserCollectionRequest()
The application code has requested a collection.


triggerInternalCollectionRequest

public static void triggerInternalCollectionRequest()
MMTK has requested stop-the-world activity (e.g., stw within a concurrent gc).


resetCollectionTrigger

public static void resetCollectionTrigger()
Reset collection state information.


isUserTriggeredCollection

public static boolean isUserTriggeredCollection()
Returns:
true if this collection was triggered by application code.

isInternalTriggeredCollection

public static boolean isInternalTriggeredCollection()
Returns:
true if this collection was triggered internally.

harnessBegin

public static void harnessBegin()
Generic hook to allow benchmarks to be harnessed. A plan may use this to perform certain actions prior to the commencement of a benchmark, such as a full heap collection, turning on instrumentation, etc. By default we do a full heap GC, and then start stats collection.


harnessEnd

public static void harnessEnd()
Generic hook to allow benchmarks to be harnessed. A plan may use this to perform certain actions after the completion of a benchmark, such as a full heap collection, turning off instrumentation, etc. By default we stop all statistics objects and print their values.


freeMemory

public static Extent freeMemory()
Return the amount of free memory, in bytes (where free is defined as not in use). Note that this may overstate the amount of available memory, which must account for unused memory that is held in reserve for copying, and therefore unavailable for allocation.

Returns:
The amount of free memory, in bytes (where free is defined as not in use).

availableMemory

public static Extent availableMemory()
Return the amount of available memory, in bytes. Note that this accounts for unused memory that is held in reserve for copying, and therefore unavailable for allocation.

Returns:
The amount of available memory, in bytes.

usedMemory

public static Extent usedMemory()
Return the amount of memory in use, in bytes. Note that this excludes unused memory that is held in reserve for copying, and therefore unavailable for allocation.

Returns:
The amount of memory in use, in bytes.

reservedMemory

public static Extent reservedMemory()
Return the amount of memory in use, in bytes. Note that this includes unused memory that is held in reserve for copying, and therefore unavailable for allocation.

Returns:
The amount of memory in use, in bytes.

totalMemory

public static Extent totalMemory()
Return the total amount of memory managed to the memory management system, in bytes.

Returns:
The total amount of memory managed to the memory management system, in bytes.

getTotalPages

public final int getTotalPages()
Return the total amount of memory managed to the memory management system, in pages.

Returns:
The total amount of memory managed to the memory management system, in pages.

getPagesAvail

public int getPagesAvail()
Return the number of pages available for allocation.

Returns:
The number of pages available for allocation.

getPagesReserved

public final int getPagesReserved()
Return the number of pages reserved for use given the pending allocation. Sub-classes must override the getCopyReserve method, as the arithmetic here is fixed.

Returns:
The number of pages reserved given the pending allocation, including space reserved for copying.

getCollectionReserve

public int getCollectionReserve()
Return the number of pages reserved for collection. In most cases this is a copy reserve, all subclasses that manage a copying space must add the copying contribution.

Returns:
The number of pages reserved given the pending allocation, including space reserved for collection.

getPagesUsed

public int getPagesUsed()
Return the number of pages reserved for use given the pending allocation.

Returns:
The number of pages reserved given the pending allocation, excluding space reserved for copying.

storeObjectReference

public void storeObjectReference(Address slot,
                                 ObjectReference value)
Store an object reference

Parameters:
slot - The location of the reference
value - The value to store

loadObjectReference

public ObjectReference loadObjectReference(Address slot)
Load an object reference

Parameters:
slot - The location of the reference
Returns:
the object reference loaded from slot

poll

public final boolean poll(boolean spaceFull,
                          Space space)
This method is called periodically by the allocation subsystem (by default, each time a page is consumed), and provides the collector with an opportunity to collect.

Parameters:
spaceFull - Space request failed, must recover pages within 'space'.
space - The space that triggered the poll.
Returns:
true if a collection is required.

logPoll

protected void logPoll(Space space,
                       String message)
Log a message from within 'poll'

Parameters:
space -
message -

collectionRequired

protected boolean collectionRequired(boolean spaceFull,
                                     Space space)
This method controls the triggering of a GC. It is called periodically during allocation. Returns true to trigger a collection.

Parameters:
spaceFull - Space request failed, must recover pages within 'space'.
space - TODO
Returns:
true if a collection is requested by the plan.

concurrentCollectionRequired

protected boolean concurrentCollectionRequired()
This method controls the triggering of an atomic phase of a concurrent collection. It is called periodically during allocation.

Returns:
true if a collection is requested by the plan.

startGCspyServer

public void startGCspyServer(int port,
                             boolean wait)
Start GCspy server.

Parameters:
port - The port to listen on,
wait - Should we wait for a client to connect?

willNeverMove

public boolean willNeverMove(ObjectReference object)
Can this object ever move. Used by the VM to make decisions about whether it needs to copy IO buffers etc.

Parameters:
object - The object in question
Returns:
true if it is not possible that the object will ever move.

registerSpecializedMethods

protected void registerSpecializedMethods()
Register specialized methods.


getSpecializedScanClass

public final Class<?> getSpecializedScanClass(int id)
Get the specialized scan with the given id.