public class BumpPointer extends Allocator
Intra-block allocation is fast, requiring only a load, addition comparison and store. If a block boundary is encountered the allocator will request more memory (virtual and actual).
In the current implementation the scanned objects maintain affinity with the thread that allocated the objects in the region. In the future it is anticipated that subclasses should be allowed to choose to improve load balancing during the parallel scan.
Each region is laid out as follows:
+-------------+-------------+-------------+--------------- | Region End | Next Region | Data End | Data --> +-------------+-------------+-------------+---------------The minimum region size is 32768 bytes, so the 3 or 4 word overhead is less than 0.05% of all space.
An intended enhancement is to facilitate a reallocation operation where a second cursor is maintained over earlier regions (and at the limit a lower location in the same region). This would be accompianied with an alternative slow path that would allow reuse of empty regions.
This class relies on the supporting virtual machine implementing the getNextObject and related operations.
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowScanning
linear scanning is permitted if true
|
protected static Word |
BLOCK_MASK |
private static int |
BLOCK_SIZE |
protected Address |
cursor
insertion point
|
protected static Offset |
DATA_END_OFFSET |
protected static Offset |
DATA_START_OFFSET |
protected Address |
initialRegion
first contiguous region
|
private Address |
internalLimit
current internal slow-path sentinel for bump pointer
|
private Address |
limit
current external slow-path sentinel for bump pointer
|
protected static int |
LOG_BLOCK_SIZE |
private static int |
LOG_DEFAULT_STEP_SIZE |
protected static Offset |
MAX_DATA_START_OFFSET |
static int |
MINIMUM_DATA_SIZE |
protected static Offset |
NEXT_REGION_OFFSET |
protected Address |
region
current contiguous region
|
protected static Offset |
REGION_LIMIT_OFFSET |
private static int |
SIZE_OF_TWO_X86_CACHE_LINES_IN_BYTES |
protected Space |
space
space this bump pointer is associated with
|
private static int |
STEP_SIZE |
private static boolean |
VERBOSE |
Modifier | Constructor and Description |
---|---|
protected |
BumpPointer(Space space,
boolean allowScanning)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Address |
alloc(int bytes,
int align,
int offset)
Allocate space for a new object.
|
private Address |
allocSlow(Address start,
Address end,
int align,
int offset)
Internal allocation slow path.
|
protected Address |
allocSlowOnce(int bytes,
int align,
int offset)
External allocation slow path (called by superclass when slow path is
actually taken.
|
static void |
checkRegionMetadata(Address region)
Sanity check a region header
|
static void |
clearNextRegion(Address region)
Clear the next region pointer in the linked-list of regions
|
private Address |
consumeNextRegion(Address nextRegion,
int bytes,
int align,
int offset)
A bump pointer chunk/region has been consumed but the contiguous region
is available, so consume it and then return the address of the start
of a memory region satisfying the outstanding allocation request.
|
private void |
createCardAnchor(Address card,
Address start,
int bytes)
Given an allocation which starts a new card, create a record of
where the start of the object is relative to the start of the
card.
|
void |
gcspyGatherData(LinearSpaceDriver driver)
Gather data for GCspy.
|
void |
gcspyGatherData(LinearSpaceDriver driver,
Space scanSpace)
Gather data for GCspy.
|
private static Address |
getCard(Address address)
Return the start of the card corresponding to a given address.
|
private static Address |
getCardMetaData(Address card)
Return the address of the metadata for a card, given the address of the card.
|
Address |
getCursor() |
static Address |
getDataEnd(Address region) |
static Address |
getDataStart(Address region)
The first offset in a region after the header
|
static Address |
getNextRegion(Address region)
The next region in the linked-list of regions
|
static Address |
getRegionLimit(Address region)
Return the end address of the given region.
|
Space |
getSpace()
Return the space this allocator is currently bound to.
|
static boolean |
isRegionAligned(Address region) |
void |
linearScan(LinearScan scanner)
Perform a linear scan through the objects allocated by this bump pointer.
|
protected Extent |
maximumRegionSize()
Maximum size of a single region.
|
void |
rebind(Space space)
Re-associate this bump pointer with a different space.
|
void |
reset()
Reset the allocator.
|
protected void |
reusePages(int pages)
Some pages are about to be re-used to satisfy a slow path request.
|
private void |
scanRegion(LinearScan scanner,
Address start)
Perform a linear scan through a single contiguous region
|
static void |
setDataEnd(Address region,
Address endAddress) |
static void |
setNextRegion(Address region,
Address nextRegion)
Set the next region in the linked-list of regions
|
static void |
setRegionLimit(Address region,
Address limit)
Stores the limit value at the end of the region.
|
void |
show()
Print out the status of the allocator (for debugging)
|
protected void |
updateLimit(Address newLimit,
Address start,
int bytes)
Update the limit pointer.
|
private void |
updateMetaData(Address start,
Extent size,
int bytes)
Update the metadata to reflect the addition of a new region.
|
alignAllocation, alignAllocation, alignAllocationNoFill, allocSlow, allocSlowInline, determineCollectionAttempts, fillAlignmentGap, getMaximumAlignedSize, getMaximumAlignedSize
private static final int LOG_DEFAULT_STEP_SIZE
private static final int STEP_SIZE
protected static final int LOG_BLOCK_SIZE
protected static final Word BLOCK_MASK
private static final int BLOCK_SIZE
protected static final Offset REGION_LIMIT_OFFSET
protected static final Offset NEXT_REGION_OFFSET
protected static final Offset DATA_END_OFFSET
protected static final Offset DATA_START_OFFSET
protected static final Offset MAX_DATA_START_OFFSET
public static final int MINIMUM_DATA_SIZE
private static final int SIZE_OF_TWO_X86_CACHE_LINES_IN_BYTES
private static final boolean VERBOSE
private Address internalLimit
protected Address initialRegion
protected final boolean allowScanning
protected BumpPointer(Space space, boolean allowScanning)
space
- The space to bump point into.allowScanning
- Allow linear scanning of this region of memory.public final void reset()
public final void rebind(Space space)
alloc
.space
- The space to associate the bump pointer with.public final Address alloc(int bytes, int align, int offset)
bytes
- The number of bytes allocatedalign
- The requested alignmentoffset
- The offset from the alignmentprivate Address allocSlow(Address start, Address end, int align, int offset)
start
- The start address for the pending allocationend
- The end address for the pending allocationalign
- The requested alignmentoffset
- The offset from the alignmentprivate void createCardAnchor(Address card, Address start, int bytes)
card
- An address that lies within the card to be markedstart
- The address of an object which creates a new card.bytes
- The size of the pending allocation in bytes (used for debugging)private static Address getCard(Address address)
address
- The address for which the card start is requiredprivate static Address getCardMetaData(Address card)
card
- The address of some cardprotected final Address allocSlowOnce(int bytes, int align, int offset)
allocSlowOnce
in class Allocator
bytes
- The number of bytes allocatedoffset
- The offset from the alignmentalign
- The requested alignmentprotected final void updateLimit(Address newLimit, Address start, int bytes)
newLimit
- The new value for the limit pointerstart
- The start of the region to be allocated intobytes
- The size of the pending allocation (if any).private Address consumeNextRegion(Address nextRegion, int bytes, int align, int offset)
nextRegion
- The region to be consumedbytes
- The number of bytes allocatedalign
- The requested alignmentoffset
- The offset from the alignmentpublic static Address getDataStart(Address region)
region
- The regionpublic static Address getNextRegion(Address region)
region
- The regionpublic static void setNextRegion(Address region, Address nextRegion)
region
- The regionnextRegion
- the next region in the listpublic static void clearNextRegion(Address region)
region
- The regionpublic static Address getDataEnd(Address region)
region
- The bump-pointer regionpublic static void setDataEnd(Address region, Address endAddress)
region
- The bump-pointer regionendAddress
- The new DATA_END address from the region headerpublic static Address getRegionLimit(Address region)
region
- The region.public static void setRegionLimit(Address region, Address limit)
region
- region addresslimit
- the limit valuepublic static boolean isRegionAligned(Address region)
region
- The region.true
if the address is region-alignedpublic static void checkRegionMetadata(Address region)
region
- Region to checkprivate void updateMetaData(Address start, Extent size, int bytes)
start
- The start of the new regionsize
- The size of the new region (rounded up to block-alignment)bytes
- the size of the pending allocation, if anypublic void gcspyGatherData(LinearSpaceDriver driver)
This method calls the drivers linear scanner to scan through the objects allocated by this bump pointer.
driver
- The GCspy driver for this space.public void gcspyGatherData(LinearSpaceDriver driver, Space scanSpace)
This method calls the drivers linear scanner to scan through the objects allocated by this bump pointer.
driver
- The GCspy driver for this space.scanSpace
- The space to scanpublic final void linearScan(LinearScan scanner)
scanner
- The scan object to delegate scanning to.private void scanRegion(LinearScan scanner, Address start)
scanner
- The scan object to delegate to.start
- The start of this regionprotected void reusePages(int pages)
pages
- The number of pages.protected Extent maximumRegionSize()
public final Space getSpace()
Allocator
public final void show()