org.mmtk.policy
Class Space

java.lang.Object
  extended by org.mmtk.policy.Space
All Implemented Interfaces:
Constants
Direct Known Subclasses:
BaseLargeObjectSpace, CopySpace, ImmixSpace, ImmortalSpace, MarkCompactSpace, RawPageSpace, SegregatedFreeListSpace

public abstract class Space
extends Object
implements Constants

This class defines and manages spaces. Each policy is an instance of a space. A space is a region of virtual memory (contiguous or discontigous) which is subject to the same memory management regime. Multiple spaces (instances of this class or its descendants) may have the same policy (eg there could be numerous instances of CopySpace, each with different roles). Spaces are defined in terms of a unique region of virtual memory, so no two space instances ever share any virtual memory.

In addition to tracking virtual memory use and the mapping to policy, spaces also manage memory consumption (used virtual memory).


Nested Class Summary
static interface Space.SpaceVisitor
          Interface to use to implement the Visitor Pattern for Spaces.
 
Field Summary
static Extent AVAILABLE_BYTES
           
static Address AVAILABLE_END
           
static int AVAILABLE_PAGES
           
static Address AVAILABLE_START
           
static int BYTES_IN_CHUNK
           
protected  boolean contiguous
           
private static boolean DEBUG
           
protected  int descriptor
           
protected  Extent extent
           
private static boolean FORCE_SLOW_MAP_LOOKUP
           
protected  Address headDiscontiguousRegion
           
static Address HEAP_END
           
static Address HEAP_START
           
private static Address heapCursor
           
private static Address heapLimit
           
protected  boolean immortal
           
private  int index
           
static int LOG_ADDRESS_SPACE
           
static int LOG_BYTES_IN_CHUNK
           
private static int LOG_MAX_CHUNKS
           
static int MAX_CHUNKS
           
static int MAX_SPACES
           
private static int MB
           
private static int MB_PAGES
           
protected  boolean movable
           
private  String name
           
private  int nameLength
           
private static int PAGES
           
static int PAGES_IN_CHUNK
           
private static int PAGES_MB
           
protected  PageResource pr
           
private static int spaceCount
           
private static Space[] spaces
           
protected  Address start
           
private  VMRequest vmRequest
           
protected  boolean zeroed
           
 
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 Space(String name, boolean movable, boolean immortal, boolean zeroed, VMRequest vmRequest)
          This is the base constructor for all spaces.
 
Method Summary
 Address acquire(int pages)
          Acquire a number of pages from the page resource, returning either the address of the first page, or zero on failure.
 int availablePhysicalPages()
          AvailablePages getter @return The number of pages available for allocation
static Address chunkAlign(Address addr, boolean down)
          Align an address to a space chunk
static Extent chunkAlign(Extent bytes, boolean down)
          Align an extent to a space chunk
 int committedPages()
          CommittedPages getter @return The number of committed pages
static long cumulativeCommittedPages()
          Cumulative committed pages getter @return Cumulative committed pages.
static void eagerlyMmapMMTkContiguousSpaces()
          Ensure that all contiguous MMTk spaces are mapped.
static void eagerlyMmapMMTkDiscontiguousSpaces()
          Ensure that all discontiguous MMTk spaces are mapped.
static void eagerlyMmapMMTkSpaces()
          Ensure that all MMTk spaces (all spaces aside from the VM space) are mapped.
 int getDescriptor()
          Descriptor method @return The integer descriptor for this space
static Address getDiscontigEnd()
          End of discontig getter @return The end of the discontiguous space
static Address getDiscontigStart()
          Start of discontig getter @return The start of the discontiguous space
 Extent getExtent()
          Extent getter @return The size (extent) of this space
static Extent getFracAvailable(float frac)
          Convert a fraction into a number of bytes according to the fraction of available bytes.
 Address getHeadDiscontiguousRegion()
           
 int getIndex()
          Index getter @return The index (ordinal number) of this space
 String getName()
          Name getter @return The name of this space
private static int getPagesReserved()
          Get the total number of pages reserved by all of the spaces
static Space getSpaceForAddress(Address addr)
          Return the space for a given address, not necessarily the start address of an object.
static Space getSpaceForObject(ObjectReference object)
          Return the space for a given object
 Address getStart()
          Start getter @return The start address of this space
 Address growDiscontiguousSpace(int chunks)
          Extend the virtual memory associated with a particular discontiguous space.
 void growSpace(Address start, Extent bytes, boolean newChunk)
          This hook is called by page resources each time a space grows.
 boolean isImmortal()
          Immortal getter @return true if this space is never collected
static boolean isImmortal(ObjectReference object)
          Return true if the given object is in an immortal (uncollected) space.
static boolean isInSpace(int descriptor, Address address)
          Return true if the given address is the space associated with the given descriptor.
static boolean isInSpace(int descriptor, ObjectReference object)
          Return true if the given object is the space associated with the given descriptor.
abstract  boolean isLive(ObjectReference object)
          Is the object in this space alive?
static boolean isMappedAddress(Address address)
          Return true if the given address is in a space managed by MMTk.
static boolean isMappedObject(ObjectReference object)
          Return true if the given object is in a space managed by MMTk.
 boolean isMovable()
          Movable getter @return true if objects in this space may move
static boolean isMovable(ObjectReference object)
          Return true if the given object is in space that moves objects.
 boolean isReachable(ObjectReference object)
          Has the object in this space been reached during the current collection.
private static void printPages(int pages, int mode)
          Print out the number of pages and or megabytes, depending on the mode.
private static void printUsage(int mode)
          Print out the memory used by all spaces in either megabytes or pages.
static void printUsageMB()
          Print out the memory used by all spaces, in megabytes
static void printUsagePages()
          Print out the memory used by all spaces, in megabytes
static void printVMMap()
          Print out a map of virtual memory useage by all spaces
abstract  void release(Address start)
          Release a unit of allocation (a page or pages)
 void releaseAllChunks()
           
 int releaseDiscontiguousChunks(Address chunk)
          Release one or more contiguous chunks associated with a discontiguous space.
static int requiredChunks(int pages)
          Return the number of chunks required to satisfy a request for a certain number of pages
 int reservedPages()
          ReservedPages getter @return The number of reserved pages
 void setZeroingApproach(boolean useNT, boolean concurrent)
          Update the zeroing approach for this space.
 void skipConcurrentZeroing()
          Skip concurrent zeroing (fall back to bulk zeroing).
abstract  ObjectReference traceObject(TransitiveClosure trace, ObjectReference object)
          Trace an object as part of a collection and return the object, which may have been forwarded (if a copying collector).
 void triggerConcurrentZeroing()
          Trigger concurrent zeroing.
static void visitSpaces(Space.SpaceVisitor v)
          Implement the Visitor Pattern for Spaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static boolean DEBUG

LOG_ADDRESS_SPACE

public static final int LOG_ADDRESS_SPACE

LOG_BYTES_IN_CHUNK

public static final int LOG_BYTES_IN_CHUNK
See Also:
Constant Field Values

BYTES_IN_CHUNK

public static final int BYTES_IN_CHUNK
See Also:
Constant Field Values

PAGES_IN_CHUNK

public static final int PAGES_IN_CHUNK

LOG_MAX_CHUNKS

private static final int LOG_MAX_CHUNKS

MAX_CHUNKS

public static final int MAX_CHUNKS

MAX_SPACES

public static final int MAX_SPACES
See Also:
Constant Field Values

HEAP_START

public static final Address HEAP_START

AVAILABLE_START

public static final Address AVAILABLE_START

AVAILABLE_END

public static final Address AVAILABLE_END

AVAILABLE_BYTES

public static final Extent AVAILABLE_BYTES

AVAILABLE_PAGES

public static final int AVAILABLE_PAGES

HEAP_END

public static final Address HEAP_END

FORCE_SLOW_MAP_LOOKUP

private static final boolean FORCE_SLOW_MAP_LOOKUP
See Also:
Constant Field Values

PAGES

private static final int PAGES
See Also:
Constant Field Values

MB

private static final int MB
See Also:
Constant Field Values

PAGES_MB

private static final int PAGES_MB
See Also:
Constant Field Values

MB_PAGES

private static final int MB_PAGES
See Also:
Constant Field Values

spaceCount

private static int spaceCount

spaces

private static Space[] spaces

heapCursor

private static Address heapCursor

heapLimit

private static Address heapLimit

name

private final String name

nameLength

private final int nameLength

descriptor

protected final int descriptor

index

private final int index

vmRequest

private final VMRequest vmRequest

immortal

protected final boolean immortal

movable

protected final boolean movable

contiguous

protected final boolean contiguous

zeroed

protected final boolean zeroed

pr

protected PageResource pr

start

protected final Address start

extent

protected final Extent extent

headDiscontiguousRegion

protected Address headDiscontiguousRegion
Constructor Detail

Space

protected Space(String name,
                boolean movable,
                boolean immortal,
                boolean zeroed,
                VMRequest vmRequest)
This is the base constructor for all spaces.

Parameters:
name - The name of this space (used when printing error messages etc)
movable - Are objects in this space movable?
immortal - Are objects in this space immortal (uncollected)?
zeroed - if it is true, allocated memory is zeroed.
vmRequest - An object describing the virtual memory requested.
Method Detail

getDiscontigStart

public static Address getDiscontigStart()
Start of discontig getter @return The start of the discontiguous space


getDiscontigEnd

public static Address getDiscontigEnd()
End of discontig getter @return The end of the discontiguous space


getName

public final String getName()
Name getter @return The name of this space


getStart

public final Address getStart()
Start getter @return The start address of this space


getExtent

public final Extent getExtent()
Extent getter @return The size (extent) of this space


getDescriptor

public final int getDescriptor()
Descriptor method @return The integer descriptor for this space


getIndex

public final int getIndex()
Index getter @return The index (ordinal number) of this space


isImmortal

public final boolean isImmortal()
Immortal getter @return true if this space is never collected


isMovable

public boolean isMovable()
Movable getter @return true if objects in this space may move


reservedPages

public final int reservedPages()
ReservedPages getter @return The number of reserved pages


committedPages

public final int committedPages()
CommittedPages getter @return The number of committed pages


availablePhysicalPages

public final int availablePhysicalPages()
AvailablePages getter @return The number of pages available for allocation


cumulativeCommittedPages

public static long cumulativeCommittedPages()
Cumulative committed pages getter @return Cumulative committed pages.


isImmortal

public static boolean isImmortal(ObjectReference object)
Return true if the given object is in an immortal (uncollected) space.

Parameters:
object - The object in question
Returns:
true if the given object is in an immortal (uncollected) space.

isMovable

public static boolean isMovable(ObjectReference object)
Return true if the given object is in space that moves objects.

Parameters:
object - The object in question
Returns:
true if the given object is in space that moves objects.

isMappedObject

public static boolean isMappedObject(ObjectReference object)
Return true if the given object is in a space managed by MMTk.

Parameters:
object - The object in question
Returns:
true if the given object is in a space managed by MMTk.

isMappedAddress

public static boolean isMappedAddress(Address address)
Return true if the given address is in a space managed by MMTk.

Parameters:
address - The address in question
Returns:
true if the given address is in a space managed by MMTk.

isInSpace

public static boolean isInSpace(int descriptor,
                                ObjectReference object)
Return true if the given object is the space associated with the given descriptor.

Parameters:
descriptor - The descriptor for a space
object - The object in question
Returns:
true if the given object is in the space associated with the descriptor.

isInSpace

public static boolean isInSpace(int descriptor,
                                Address address)
Return true if the given address is the space associated with the given descriptor.

Parameters:
descriptor - The descriptor for a space
address - The address in question.
Returns:
true if the given address is in the space associated with the descriptor.

getSpaceForObject

public static Space getSpaceForObject(ObjectReference object)
Return the space for a given object

Parameters:
object - The object in question
Returns:
The space containing the object

getSpaceForAddress

public static Space getSpaceForAddress(Address addr)
Return the space for a given address, not necessarily the start address of an object.

Parameters:
addr - The address in question
Returns:
The space containing the address

setZeroingApproach

public void setZeroingApproach(boolean useNT,
                               boolean concurrent)
Update the zeroing approach for this space.


skipConcurrentZeroing

public void skipConcurrentZeroing()
Skip concurrent zeroing (fall back to bulk zeroing).


triggerConcurrentZeroing

public void triggerConcurrentZeroing()
Trigger concurrent zeroing.


acquire

public final Address acquire(int pages)
Acquire a number of pages from the page resource, returning either the address of the first page, or zero on failure.

This may trigger a GC if necessary.

First the page budget is checked to see whether polling the GC is necessary. If so, the GC is polled. If a GC is required then the request fails and zero is returned.

If the check of the page budget does not lead to GC being triggered, then a request is made for specific pages in virtual memory. If the page manager cannot satisify this request, then the request fails, a GC is forced, and zero is returned. Otherwise the address of the first page is returned.

Parameters:
pages - The number of pages requested
Returns:
The start of the first page if successful, zero on failure.

growDiscontiguousSpace

public Address growDiscontiguousSpace(int chunks)
Extend the virtual memory associated with a particular discontiguous space. This simply involves requesting a suitable number of chunks from the pool of chunks available to discontiguous spaces.

Parameters:
chunks - The number of chunks by which the space needs to be extended
Returns:
The address of the new discontiguous space.

requiredChunks

public static int requiredChunks(int pages)
Return the number of chunks required to satisfy a request for a certain number of pages

Parameters:
pages - The number of pages desired
Returns:
The number of chunks needed to satisfy the request

growSpace

public void growSpace(Address start,
                      Extent bytes,
                      boolean newChunk)
This hook is called by page resources each time a space grows. The space may tap into the hook to monitor heap growth. The call is made from within the page resources' critical region, immediately before yielding the lock.

Parameters:
start - The start of the newly allocated space
bytes - The size of the newly allocated space
newChunk - true if the new space encroached upon or started a new chunk or chunks.

releaseDiscontiguousChunks

public int releaseDiscontiguousChunks(Address chunk)
Release one or more contiguous chunks associated with a discontiguous space.

Parameters:
chunk - The address of the start of the contiguous chunk or chunks
Returns:
The number of chunks freed

getHeadDiscontiguousRegion

public Address getHeadDiscontiguousRegion()
Returns:
The address of the head of the discontiguous chunk map.

releaseAllChunks

public void releaseAllChunks()

release

public abstract void release(Address start)
Release a unit of allocation (a page or pages)

Parameters:
start - The address of the start of the region to be released

getPagesReserved

private static int getPagesReserved()
Get the total number of pages reserved by all of the spaces

Returns:
the total number of pages reserved by all of the spaces

printUsageMB

public static void printUsageMB()
Print out the memory used by all spaces, in megabytes


printUsagePages

public static void printUsagePages()
Print out the memory used by all spaces, in megabytes


printVMMap

public static void printVMMap()
Print out a map of virtual memory useage by all spaces


visitSpaces

public static void visitSpaces(Space.SpaceVisitor v)
Implement the Visitor Pattern for Spaces.

Parameters:
v - The visitor to perform on each Space instance

eagerlyMmapMMTkSpaces

public static void eagerlyMmapMMTkSpaces()
Ensure that all MMTk spaces (all spaces aside from the VM space) are mapped. Demand zero map all of them if they are not already mapped.


eagerlyMmapMMTkContiguousSpaces

public static void eagerlyMmapMMTkContiguousSpaces()
Ensure that all contiguous MMTk spaces are mapped. Demand zero map all of them if they are not already mapped.


eagerlyMmapMMTkDiscontiguousSpaces

public static void eagerlyMmapMMTkDiscontiguousSpaces()
Ensure that all discontiguous MMTk spaces are mapped. Demand zero map all of them if they are not already mapped.


printUsage

private static void printUsage(int mode)
Print out the memory used by all spaces in either megabytes or pages.

Parameters:
mode - An enumeration type that specifies the format for the prining (PAGES, MB, PAGES_MB, or MB_PAGES).

printPages

private static void printPages(int pages,
                               int mode)
Print out the number of pages and or megabytes, depending on the mode.

Parameters:
pages - The number of pages
mode - An enumeration type that specifies the format for the printing (PAGES, MB, PAGES_MB, or MB_PAGES).

traceObject

public abstract ObjectReference traceObject(TransitiveClosure trace,
                                            ObjectReference object)
Trace an object as part of a collection and return the object, which may have been forwarded (if a copying collector).

Parameters:
trace - The trace being conducted.
object - The object to trace
Returns:
The object, forwarded, if appropriate

isReachable

public boolean isReachable(ObjectReference object)
Has the object in this space been reached during the current collection. This is used for GC Tracing.

Parameters:
object - The object reference.
Returns:
true if the object is reachable.

isLive

public abstract boolean isLive(ObjectReference object)
Is the object in this space alive?

Parameters:
object - The object reference.
Returns:
true if the object is live.

chunkAlign

public static Address chunkAlign(Address addr,
                                 boolean down)
Align an address to a space chunk

Parameters:
addr - The address to be aligned
down - If true the address will be rounded down, otherwise it will rounded up.
Returns:
The chunk-aligned address

chunkAlign

public static Extent chunkAlign(Extent bytes,
                                boolean down)
Align an extent to a space chunk

Parameters:
bytes - The extent to be aligned
down - If true the extent will be rounded down, otherwise it will rounded up.
Returns:
The chunk-aligned extent

getFracAvailable

public static Extent getFracAvailable(float frac)
Convert a fraction into a number of bytes according to the fraction of available bytes.

Parameters:
frac - The fraction of available virtual memory desired
Returns:
The corresponding number of bytes, chunk-aligned.