org.mmtk.utility.alloc
Class Allocator

java.lang.Object
  extended by org.mmtk.utility.alloc.Allocator
All Implemented Interfaces:
Constants
Direct Known Subclasses:
BumpPointer, ImmixAllocator, LargeObjectAllocator, SegregatedFreeList

public abstract class Allocator
extends Object
implements Constants

This abstract base class provides the basis for processor-local allocation. The key functionality provided is the retry mechanism that is necessary to correctly handle the fact that a "slow-path" allocation can cause a GC which violate the uninterruptability assumption. This results in the thread being moved to a different processor so that the allocator object it is using is not actually the one for the processor it is running on.

This class also includes functionality to assist allocators with ensuring that requests are aligned according to requests.

Failing to handle this properly will lead to very hard to trace bugs where the allocation that caused a GC or allocations immediately following GC are run incorrectly.


Field Summary
private static boolean allocationSuccess
          Has an allocation succeeded since the emergency collection?
private static int collectionAttempts
          Maximum number of failed attempts by a single thread
private static Lock oomLock
          Lock used for out of memory handling
 
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
Allocator()
           
 
Method Summary
static Address alignAllocation(Address region, int alignment, int offset)
          Aligns up an allocation request.
static Address alignAllocation(Address region, int alignment, int offset, int knownAlignment, boolean fillAlignmentGap)
          Aligns up an allocation request.
static Address alignAllocationNoFill(Address region, int alignment, int offset)
          Aligns up an allocation request.
 Address allocSlow(int bytes, int alignment, int offset)
          Out-of-line slow path allocation.
 Address allocSlowInline(int bytes, int alignment, int offset)
          Inline slow path allocation.
protected abstract  Address allocSlowOnce(int bytes, int alignment, int offset)
          Single slow path allocation attempt.
static int determineCollectionAttempts()
           
static void fillAlignmentGap(Address start, Address end)
          Fill the specified region with the alignment value.
static int getMaximumAlignedSize(int size, int alignment)
          This method calculates the minimum size that will guarantee the allocation of a specified number of bytes at the specified alignment.
static int getMaximumAlignedSize(int size, int alignment, int knownAlignment)
          This method calculates the minimum size that will guarantee the allocation of a specified number of bytes at the specified alignment.
protected abstract  Space getSpace()
          Return the space this allocator is currently bound to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oomLock

private static Lock oomLock
Lock used for out of memory handling


allocationSuccess

private static volatile boolean allocationSuccess
Has an allocation succeeded since the emergency collection?


collectionAttempts

private static int collectionAttempts
Maximum number of failed attempts by a single thread

Constructor Detail

Allocator

public Allocator()
Method Detail

determineCollectionAttempts

public static int determineCollectionAttempts()
Returns:
a consecutive failure count for any allocating thread.

getSpace

protected abstract Space getSpace()
Return the space this allocator is currently bound to.

Returns:
The Space.

alignAllocation

public static Address alignAllocation(Address region,
                                      int alignment,
                                      int offset,
                                      int knownAlignment,
                                      boolean fillAlignmentGap)
Aligns up an allocation request. The allocation request accepts a region, that must be at least particle aligned, an alignment request (some power of two number of particles) and an offset (a number of particles). There is also a knownAlignment parameter to allow a more optimised check when the particular allocator in use always aligns at a coarser grain than individual particles, such as some free lists.

Parameters:
region - The region to align up.
alignment - The requested alignment
offset - The offset from the alignment
knownAlignment - The statically known minimum alignment.
Returns:
The aligned up address.

fillAlignmentGap

public static void fillAlignmentGap(Address start,
                                    Address end)
Fill the specified region with the alignment value.

Parameters:
start - The start of the region.
end - A pointer past the end of the region.

alignAllocation

public static Address alignAllocation(Address region,
                                      int alignment,
                                      int offset)
Aligns up an allocation request. The allocation request accepts a region, that must be at least particle aligned, an alignment request (some power of two number of particles) and an offset (a number of particles).

Parameters:
region - The region to align up.
alignment - The requested alignment
offset - The offset from the alignment
Returns:
The aligned up address.

alignAllocationNoFill

public static Address alignAllocationNoFill(Address region,
                                            int alignment,
                                            int offset)
Aligns up an allocation request. The allocation request accepts a region, that must be at least particle aligned, an alignment request (some power of two number of particles) and an offset (a number of particles).

Parameters:
region - The region to align up.
alignment - The requested alignment
offset - The offset from the alignment
Returns:
The aligned up address.

getMaximumAlignedSize

public static int getMaximumAlignedSize(int size,
                                        int alignment)
This method calculates the minimum size that will guarantee the allocation of a specified number of bytes at the specified alignment.

Parameters:
size - The number of bytes (not aligned).
alignment - The requested alignment (some factor of 2).

getMaximumAlignedSize

public static int getMaximumAlignedSize(int size,
                                        int alignment,
                                        int knownAlignment)
This method calculates the minimum size that will guarantee the allocation of a specified number of bytes at the specified alignment.

Parameters:
size - The number of bytes (not aligned).
alignment - The requested alignment (some factor of 2).
knownAlignment - The known minimum alignment. Specifically for use in allocators that enforce greater than particle alignment. It is a precondition that size is aligned to knownAlignment, and that knownAlignment >= MIN_ALGINMENT.

allocSlowOnce

protected abstract Address allocSlowOnce(int bytes,
                                         int alignment,
                                         int offset)
Single slow path allocation attempt. This is called by allocSlow.

Parameters:
bytes - The size of the allocation request
alignment - The required alignment
offset - The alignment offset
Returns:
The start address of the region, or zero if allocation fails

allocSlow

public final Address allocSlow(int bytes,
                               int alignment,
                               int offset)
Out-of-line slow path allocation. This method forces slow path allocation to be out of line (typically desirable, but not when the calling context is already explicitly out-of-line).

Parameters:
bytes - The size of the allocation request
alignment - The required alignment
offset - The alignment offset
Returns:
The start address of the region, or zero if allocation fails

allocSlowInline

public final Address allocSlowInline(int bytes,
                                     int alignment,
                                     int offset)
Inline slow path allocation. This method attempts allocSlowOnce several times, and allows collection to occur, and ensures that execution safely resumes by taking care of potential thread/mutator context affinity changes. All allocators should use this as the trampoline for slow path allocation.

Parameters:
bytes - The size of the allocation request
alignment - The required alignment
offset - The alignment offset
Returns:
The start address of the region, or zero if allocation fails