org.mmtk.utility.heap
Class MonotonePageResource

java.lang.Object
  extended by org.mmtk.utility.heap.PageResource
      extended by org.mmtk.utility.heap.MonotonePageResource
All Implemented Interfaces:
Constants

public final class MonotonePageResource
extends PageResource

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.


Field Summary
private static int CONCURRENT_ZEROING_BLOCKSIZE
           
private  Address currentChunk
           
private  Address cursor
           
private  int metaDataPagesPerRegion
           
private  Address sentinel
           
private  Address zeroingCursor
           
private  Address zeroingSentinel
           
 
Fields inherited from class org.mmtk.utility.heap.PageResource
committed, contiguous, reserved, space, start, ZERO_ON_RELEASE, zeroConcurrent, zeroingContext, 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
MonotonePageResource(Space space, Address start, Extent bytes, int metaDataPagesPerRegion)
          Constructor Contiguous monotone resource.
MonotonePageResource(Space space, int metaDataPagesPerRegion)
          Constructor Discontiguous monotone resource.
 
Method Summary
 int adjustForMetaData(int pages)
          Adjust a page request to include metadata requirements for a request of the given size.
 int adjustForMetaData(int pages, Address begin)
          Adjust a page request to include metadata requirements, if any.
protected  Address allocPages(int reservedPages, int requiredPages, boolean zeroed)
          Allocate pages pages from this resource.
 void concurrentZeroing()
          The entry point for the concurrent zeroing context.
 int getAvailablePhysicalPages()
          Return the number of available physical pages for this resource.
private static Address getRegionStart(Address addr)
           
private  boolean moveToNextChunk()
          Adjust the currentChunk and cursor fields to point to the next chunk in the linked list of chunks tied down by this page resource.
private  void releasePages()
          Release all pages associated with this page resource, optionally zeroing on release and optionally memory protecting on release.
private  void releasePages(Address first, Extent bytes)
          Release a range of pages associated with this page resource, optionally zeroing on release and optionally memory protecting on release.
 void reset()
          Reset this page resource, freeing all pages and resetting reserved and committed pages appropriately.
 void reusePages(int pages)
          Notify that previously unused pages are in use again.
 void unusePages(int pages)
          Notify that several pages are no longer in use.
 
Methods inherited from class org.mmtk.utility.heap.PageResource
clearRequest, commitPages, committedPages, cumulativeCommittedPages, getNewPages, lock, reservedPages, reservePages, skipConcurrentZeroing, triggerConcurrentZeroing, unlock, updateZeroingApproach
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cursor

private Address cursor

sentinel

private Address sentinel

metaDataPagesPerRegion

private final int metaDataPagesPerRegion

currentChunk

private Address currentChunk

zeroingCursor

private volatile Address zeroingCursor

zeroingSentinel

private Address zeroingSentinel

CONCURRENT_ZEROING_BLOCKSIZE

private static int CONCURRENT_ZEROING_BLOCKSIZE
Constructor Detail

MonotonePageResource

public MonotonePageResource(Space space,
                            Address start,
                            Extent bytes,
                            int metaDataPagesPerRegion)
Constructor Contiguous monotone resource. The address range is pre-defined at initialization time and is immutable.

Parameters:
space - The space to which this resource is attached
start - The start of the address range allocated to this resource
bytes - The size of the address rage allocated to this resource
metaDataPagesPerRegion - The number of pages of meta data that are embedded in each region.

MonotonePageResource

public MonotonePageResource(Space space,
                            int metaDataPagesPerRegion)
Constructor Discontiguous monotone resource. The address range is not pre-defined at initialization time and is dynamically defined to be some set of pages, according to demand and availability.

Parameters:
space - The space to which this resource is attached
metaDataPagesPerRegion - The number of pages of meta data that are embedded in each region.
Method Detail

getAvailablePhysicalPages

public int getAvailablePhysicalPages()
Description copied from class: PageResource
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).

Specified by:
getAvailablePhysicalPages in class PageResource
Returns:
The number of available physical pages for this resource.

allocPages

protected Address allocPages(int reservedPages,
                             int requiredPages,
                             boolean zeroed)
Allocate pages pages from this resource. Simply bump the cursor, and fail if we hit the sentinel.

If the request can be satisfied, then ensure the pages are mmpapped and zeroed before returning the address of the start of the region. If the request cannot be satisfied, return zero.

Specified by:
allocPages in class PageResource
Parameters:
reservedPages - The number of pages reserved due to the initial request.
requiredPages - The number of pages required to be allocated.
Returns:
The start of the first page if successful, zero on failure.

adjustForMetaData

public 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.

In this case we simply report the expected page cost. We can't use worst case here because we would exhaust our budget every time.

Specified by:
adjustForMetaData in class PageResource
Parameters:
pages - The size of the pending allocation in pages
Returns:
The number of required pages, inclusive of any metadata

adjustForMetaData

public int adjustForMetaData(int pages,
                             Address begin)
Adjust a page request to include metadata requirements, if any.

Note that there could be a race here, with multiple threads each adjusting their request on account of the same single metadata region. This should not be harmful, as the failing requests will just retry, and if multiple requests succeed, only one of them will actually have the metadata accounted against it, the others will simply have more space than they originally requested.

Parameters:
pages - The size of the pending allocation in pages
begin - The start address of the region assigned to this pending request
Returns:
The number of required pages, inclusive of any metadata

getRegionStart

private static Address getRegionStart(Address addr)

reset

public void reset()
Reset this page resource, freeing all pages and resetting reserved and committed pages appropriately.


unusePages

public void unusePages(int pages)
Notify that several pages are no longer in use.

Parameters:
pages - The number of pages

reusePages

public void reusePages(int pages)
Notify that previously unused pages are in use again.

Parameters:
pages - The number of pages

releasePages

private void releasePages()
Release all pages associated with this page resource, optionally zeroing on release and optionally memory protecting on release.


moveToNextChunk

private boolean moveToNextChunk()
Adjust the currentChunk and cursor fields to point to the next chunk in the linked list of chunks tied down by this page resource.

Returns:
true if we moved to the next chunk; false if we hit the end of the linked list.

releasePages

private void releasePages(Address first,
                          Extent bytes)
Release a range of pages associated with this page resource, optionally zeroing on release and optionally memory protecting on release.


concurrentZeroing

public void concurrentZeroing()
Description copied from class: PageResource
The entry point for the concurrent zeroing context.

Overrides:
concurrentZeroing in class PageResource