org.mmtk.utility.heap
Class PageResource

java.lang.Object
  extended by org.mmtk.utility.heap.PageResource
All Implemented Interfaces:
Constants
Direct Known Subclasses:
FreeListPageResource, MonotonePageResource

public abstract class PageResource
extends Object
implements Constants

This class manages the allocation of pages for a space. When a page is requested by the space both a page budget and the use of virtual address space are checked. If the request for space can't be satisfied (for either reason) a GC may be triggered.

This class is abstract, and is subclassed with monotone and freelist variants, which reflect monotonic and ad hoc space usage respectively. Monotonic use is easier to manage, but is obviously more restrictive (useful for copying collectors which allocate monotonically before freeing the entire space and starting over).


Field Summary
private static Lock classLock
           
protected  int committed
           
protected  boolean contiguous
           
private static long cumulativeCommitted
           
private  Lock lock
           
protected  int reserved
           
protected  Space space
           
protected  Address start
          only for contiguous spaces
protected static boolean ZERO_ON_RELEASE
           
protected  boolean zeroConcurrent
           
protected  ConcurrentZeroingContext zeroingContext
           
protected  boolean zeroNT
           
 
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
(package private) PageResource(Space space)
          Constructor for discontiguous spaces
(package private) PageResource(Space space, Address start)
          Constructor for contiguous spaces
private PageResource(Space space, boolean contiguous)
          Constructor
 
Method Summary
private static void addToCommitted(int pages)
          Add to the total cumulative committed page count.
abstract  int adjustForMetaData(int pages)
          Adjust a page request to include metadata requirements for a request of the given size.
(package private) abstract  Address allocPages(int reservedPages, int requiredPages, boolean zeroed)
           
 void clearRequest(int reservedPages)
          Remove a request to the space.
protected  void commitPages(int reservedPages, int actualPages)
          Commit pages to the page budget.
 int committedPages()
          Return the number of committed pages
 void concurrentZeroing()
          The entry point for the concurrent zeroing context.
static long cumulativeCommittedPages()
          Return the cumulative number of committed pages
abstract  int getAvailablePhysicalPages()
          Return the number of available physical pages for this resource.
 Address getNewPages(int pagesReserved, int pages, boolean zeroed)
          Allocate pages in virtual memory, returning zero on failure.
protected  void lock()
          Acquire the lock.
 int reservedPages()
          Return the number of reserved pages
 int reservePages(int pages)
          Reserve pages.
 void skipConcurrentZeroing()
          Skip concurrent zeroing (fall back to bulk zeroing).
 void triggerConcurrentZeroing()
          Trigger concurrent zeroing.
protected  void unlock()
          Release the lock.
 void updateZeroingApproach(boolean nontemporal, boolean concurrent)
          Update the zeroing approach for this page resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO_ON_RELEASE

protected static final boolean ZERO_ON_RELEASE
See Also:
Constant Field Values

classLock

private static final Lock classLock

cumulativeCommitted

private static long cumulativeCommitted

reserved

protected int reserved

committed

protected int committed

contiguous

protected final boolean contiguous

space

protected final Space space

start

protected Address start
only for contiguous spaces


lock

private final Lock lock

zeroNT

protected boolean zeroNT

zeroConcurrent

protected boolean zeroConcurrent

zeroingContext

protected ConcurrentZeroingContext zeroingContext
Constructor Detail

PageResource

private PageResource(Space space,
                     boolean contiguous)
Constructor

Parameters:
space - The space to which this resource is attached

PageResource

PageResource(Space space)
Constructor for discontiguous spaces

Parameters:
space - The space to which this resource is attached

PageResource

PageResource(Space space,
             Address start)
Constructor for contiguous spaces

Parameters:
space - The space to which this resource is attached
Method Detail

getAvailablePhysicalPages

public abstract int getAvailablePhysicalPages()
Return the number of available physical pages for this resource. This includes all pages currently unused by this resource's page cursor. If the resource is using discontiguous space it also includes currently unassigned discontiguous space.

Note: This just considers physical pages (ie virtual memory pages allocated for use by this resource). This calculation is orthogonal to and does not consider any restrictions on the number of pages this resource may actually use at any time (ie the number of committed and reserved pages).

Note: The calculation is made on the assumption that all space that could be assigned to this resource would be assigned to this resource (ie the unused discontiguous space could just as likely be assigned to another competing resource).

Returns:
The number of available physical pages for this resource.

reservePages

public final int reservePages(int pages)
Reserve pages.

The role of reserving pages is that it allows the request to be noted as pending (the difference between committed and reserved indicates pending requests). If the request would exceed the page budget then the caller must poll in case a GC is necessary.

Parameters:
pages - The number of pages requested
Returns:
The actual number of pages reserved (including metadata, etc.)

clearRequest

public final void clearRequest(int reservedPages)
Remove a request to the space.

Parameters:
reservedPages - The number of pages returned due to the request.

updateZeroingApproach

public void updateZeroingApproach(boolean nontemporal,
                                  boolean concurrent)
Update the zeroing approach for this page resource.


skipConcurrentZeroing

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


triggerConcurrentZeroing

public void triggerConcurrentZeroing()
Trigger concurrent zeroing.


concurrentZeroing

public void concurrentZeroing()
The entry point for the concurrent zeroing context.


allocPages

abstract Address allocPages(int reservedPages,
                            int requiredPages,
                            boolean zeroed)

adjustForMetaData

public abstract int adjustForMetaData(int pages)
Adjust a page request to include metadata requirements for a request of the given size. This must be a pure function, that is it does not depend on the state of the PageResource.

Parameters:
pages - The size of the pending allocation in pages
Returns:
The number of required pages, inclusive of any metadata

getNewPages

public final Address getNewPages(int pagesReserved,
                                 int pages,
                                 boolean zeroed)
Allocate pages in virtual memory, returning zero on failure.

If the request cannot be satisfied, zero is returned and it falls to the caller to trigger the GC. Call allocPages (subclass) to find the pages in virtual memory. If successful then commit the pending page request and return the address of the first page.

Parameters:
pagesReserved - The number of pages reserved by the initial request
pages - The number of pages requested
zeroed - If true allocated pages are zeroed.
Returns:
The address of the first of pages pages, or zero on failure.

commitPages

protected void commitPages(int reservedPages,
                           int actualPages)
Commit pages to the page budget. This is called after successfully determining that the request can be satisfied by both the page budget and virtual memory. This simply accounts for the discrepancy between committed and reserved while the request was pending. This *MUST* be called by each PageResource during the allocPages, and the caller must hold the lock.

Parameters:
reservedPages - The number of pages initially reserved due to this request
actualPages - The number of pages actually allocated.

reservedPages

public final int reservedPages()
Return the number of reserved pages

Returns:
The number of reserved pages.

committedPages

public final int committedPages()
Return the number of committed pages

Returns:
The number of committed pages.

cumulativeCommittedPages

public static long cumulativeCommittedPages()
Return the cumulative number of committed pages

Returns:
The cumulative number of committed pages.

addToCommitted

private static void addToCommitted(int pages)
Add to the total cumulative committed page count.

Parameters:
pages - The number of pages to be added.

lock

protected final void lock()
Acquire the lock.


unlock

protected final void unlock()
Release the lock.