org.mmtk.utility.heap
Class FreeListPageResource

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

public final class FreeListPageResource
extends PageResource
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.


Field Summary
private  GenericFreeList freeList
           
private  int highWaterMark
           
private  int metaDataPagesPerRegion
           
private  int pagesCurrentlyOnFreeList
           
 
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
FreeListPageResource(Space space, Address start, Extent bytes)
          Constructor Contiguous free list resource.
FreeListPageResource(Space space, Address start, Extent bytes, int metaDataPagesPerRegion)
          Constructor Contiguous free list resource.
FreeListPageResource(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.
private  int allocateContiguousChunks(int pages)
          Allocate sufficient contiguous chunks within a discontiguous region to satisfy the pending request.
protected  Address allocPages(int reservedPages, int requiredPages, boolean zeroed)
          Allocate pages pages from this resource.
private  void freeContiguousChunk(Address chunk)
          Release a single chunk from a discontiguous region.
 int getAvailablePhysicalPages()
          Return the number of available physical pages for this resource.
 Address getHighWater()
           
 Extent getSize(Address first)
          Return the size of the super page
private  void releaseFreeChunks(Address freedPage, int pagesFreed)
          The release of a page may have freed up an entire chunk or set of chunks.
 void releasePages(Address first)
          Release a group of pages, associated with this page resource, that were allocated together, optionally zeroing on release and optionally memory protecting on release.
private  void reserveMetaData(Extent extent)
          Reserve virtual address space for meta-data.
 void resizeFreeList(Address startAddress)
          Resize the free list associated with this resource and nail down its start address.
 
Methods inherited from class org.mmtk.utility.heap.PageResource
clearRequest, commitPages, committedPages, concurrentZeroing, 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

freeList

private final GenericFreeList freeList

highWaterMark

private int highWaterMark

metaDataPagesPerRegion

private final int metaDataPagesPerRegion

pagesCurrentlyOnFreeList

private int pagesCurrentlyOnFreeList
Constructor Detail

FreeListPageResource

public FreeListPageResource(Space space,
                            Address start,
                            Extent bytes)
Constructor Contiguous free list 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

FreeListPageResource

public FreeListPageResource(Space space,
                            Address start,
                            Extent bytes,
                            int metaDataPagesPerRegion)
Constructor Contiguous free list 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.

FreeListPageResource

public FreeListPageResource(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
Method Detail

getAvailablePhysicalPages

public int getAvailablePhysicalPages()
Return the number of available physical pages for this resource. This includes all pages currently free on the resource's free list. 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.

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.
zeroed - If true allocated pages are zeroed.
Returns:
The start of the first page if successful, zero on failure.

releasePages

public void releasePages(Address first)
Release a group of pages, associated with this page resource, that were allocated together, optionally zeroing on release and optionally memory protecting on release.

Parameters:
first - The first page in the group of pages that were allocated together.

releaseFreeChunks

private void releaseFreeChunks(Address freedPage,
                               int pagesFreed)
The release of a page may have freed up an entire chunk or set of chunks. We need to check whether any chunks can be freed, and if so, free them.

Parameters:
freedPage - The address of the page that was just freed.
pagesFreed - The number of pages made available when the page was freed.

allocateContiguousChunks

private int allocateContiguousChunks(int pages)
Allocate sufficient contiguous chunks within a discontiguous region to satisfy the pending request. Note that this is purely about address space allocation within a discontiguous region. This method does not reserve individual pages, it merely assigns a suitably large region of virtual memory from within the discontiguous region for use by a particular space.

Parameters:
pages - The number of pages currently being requested
Returns:
A chunk number or GenericFreelist.FAILURE

freeContiguousChunk

private void freeContiguousChunk(Address chunk)
Release a single chunk from a discontiguous region. All this does is release a chunk from the virtual address space associated with this discontiguous space.

Parameters:
chunk - The chunk to be freed

reserveMetaData

private void reserveMetaData(Extent extent)
Reserve virtual address space for meta-data.

Parameters:
extent - The size of this space

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 the case of a free-list allocator, meta-data is pre-allocated, so simply return the un-adjusted request size.

Specified by:
adjustForMetaData in class PageResource
Parameters:
pages - The size of the pending allocation in pages
Returns:
The (unadjusted) request size, since metadata is pre-allocated

getHighWater

public Address getHighWater()

getSize

public Extent getSize(Address first)
Return the size of the super page

Parameters:
first - the Address of the first word in the superpage
Returns:
the size in bytes

resizeFreeList

public void resizeFreeList(Address startAddress)
Resize the free list associated with this resource and nail down its start address. This method is called to re-set the free list once the global free list (which it shares) is finalized and the base address is finalized. There's a circular dependency, so we need an explicit call-back to reset the free list size and start

Parameters:
startAddress - The final start address for the discontiguous space.