public abstract class Allocator extends Object
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.
TODO the comments in this class need to be rephrased from using the particle terminology to alignments.
Modifier and Type | Field and Description |
---|---|
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
|
Constructor and Description |
---|
Allocator() |
Modifier and Type | Method and Description |
---|---|
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.
|
private static volatile boolean allocationSuccess
private static int collectionAttempts
public Allocator()
public static int determineCollectionAttempts()
protected abstract Space getSpace()
public static Address alignAllocation(Address region, int alignment, int offset, int knownAlignment, boolean fillAlignmentGap)
region
- The region to align up.alignment
- The requested alignmentoffset
- The offset from the alignmentknownAlignment
- The statically known minimum alignment.fillAlignmentGap
- whether to fill up holes in the alignment
with the alignment value (Constants.ALIGNMENT_VALUE
)public static void fillAlignmentGap(Address start, Address end)
start
- The start of the region.end
- A pointer past the end of the region.public static Address alignAllocation(Address region, int alignment, int offset)
region
- The region to align up.alignment
- The requested alignmentoffset
- The offset from the alignmentpublic static Address alignAllocationNoFill(Address region, int alignment, int offset)
region
- The region to align up.alignment
- The requested alignmentoffset
- The offset from the alignmentpublic static int getMaximumAlignedSize(int size, int alignment)
size
- The number of bytes (not aligned).alignment
- The requested alignment (some factor of 2).public static int getMaximumAlignedSize(int size, int alignment, int knownAlignment)
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 >=
Constants.MIN_ALIGNMENT
.protected abstract Address allocSlowOnce(int bytes, int alignment, int offset)
bytes
- The size of the allocation requestalignment
- The required alignmentoffset
- The alignment offsetpublic final Address allocSlow(int bytes, int alignment, int offset)
bytes
- The size of the allocation requestalignment
- The required alignmentoffset
- The alignment offsetpublic final Address allocSlowInline(int bytes, int alignment, int offset)
bytes
- The size of the allocation requestalignment
- The required alignmentoffset
- The alignment offset