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 gcLock
           
private  Lock mutatorLock
           
private  int pageBudget
           
protected  int required
           
protected  int reserved
          Instance variables
protected  Space space
           
protected  Address start
           
protected static boolean ZERO_ON_RELEASE
          Class variables
 
Fields inherited from interface org.mmtk.utility.Constants
AALOAD_READ_BARRIER, AASTORE_WRITE_BARRIER, ALIGNMENT_VALUE, BITS_IN_ADDRESS, BITS_IN_BYTE, BITS_IN_INT, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BYTE, 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, GETFIELD_READ_BARRIER, GETSTATIC_READ_BARRIER, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BYTE, 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_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, PUTFIELD_WRITE_BARRIER, PUTSTATIC_WRITE_BARRIER, SUPPORT_CARD_SCANNING
 
Constructor Summary
(package private) PageResource(int pageBudget, Space space)
          Constructor for discontiguous spaces
(package private) PageResource(int pageBudget, Space space, Address start)
          Constructor for contiguous spaces
private PageResource(int pageBudget, 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 pages)
           
 void clearRequest(int pages)
          Remove a request to the space.
protected  void commitPages(int requestedPages, int totalPages)
          Commit pages to the page budget.
 int committedPages()
          Return the number of committed pages
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 pages)
          Allocate pages in virtual memory, returning zero on failure.
protected  void lock()
          Acquire the appropriate lock depending on whether the context is GC or mutator.
 int requiredPages()
          Return the number of required pages
 int reservedPages()
          Return the number of reserved pages
 boolean reservePages(int pages)
          Reserve pages.
 void unconditionallyReleasePages(int pages)
          Release pages unconditionally.
 void unconditionallyReservePages(int pages)
          Reserve pages unconditionally.
protected  void unlock()
          Release the appropriate lock depending on whether the context is GC or mutator.
 
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
Class variables

See Also:
Constant Field Values

classLock

private static final Lock classLock

cumulativeCommitted

private static long cumulativeCommitted

reserved

protected int reserved
Instance variables


committed

protected int committed

required

protected int required

pageBudget

private final int pageBudget

contiguous

protected final boolean contiguous

space

protected final Space space

start

protected Address start

gcLock

private final Lock gcLock

mutatorLock

private final Lock mutatorLock
Constructor Detail

PageResource

private PageResource(int pageBudget,
                     Space space,
                     boolean contiguous)
Constructor

Parameters:
pageBudget - The budget of pages available to this memory manager before it must poll the collector.
space - The space to which this resource is attached

PageResource

PageResource(int pageBudget,
             Space space)
Constructor for discontiguous spaces

Parameters:
pageBudget - The budget of pages available to this memory manager before it must poll the collector.
space - The space to which this resource is attached

PageResource

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

Parameters:
pageBudget - The budget of pages available to this memory manager before it must poll the collector.
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. 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 boolean 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:
True if the page budget could satisfy the request.

clearRequest

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

Parameters:
pages - The number of pages in the request.

unconditionallyReservePages

public final void unconditionallyReservePages(int pages)
Reserve pages unconditionally.

An example of where this is useful is in cases where it is desirable to put some space aside as head-room. By unconditionally reserving the pages, the pages are counted against the collectors budget. When the space is actually needed, the pages can be unconditionally released, freeing the pages for other purposes.

Parameters:
pages - The number of pages to be unconditionally reserved.

unconditionallyReleasePages

public final void unconditionallyReleasePages(int pages)
Release pages unconditionally.

This call allows pages to be unconditionally removed from the collectors page budget.

Parameters:
pages - The number of pages to be unconditionally released.
See Also:
unconditionallyReservePages(int)

allocPages

abstract Address allocPages(int pages)

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 pages)
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:
pages - The number of pages requested
Returns:
The address of the first of pages pages, or zero on failure.

commitPages

protected void commitPages(int requestedPages,
                           int totalPages)
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 descrepency 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:
requestedPages - The number of pages from this request
totalPages - The number of pages

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.

requiredPages

public final int requiredPages()
Return the number of required pages

Returns:
The number of required 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 appropriate lock depending on whether the context is GC or mutator.


unlock

protected final void unlock()
Release the appropriate lock depending on whether the context is GC or mutator.