public class UpfrontAllocatingPageSource extends Object implements PageSource
This buffer source implementation allocates all of its required storage up-front in fixed size chunks. Runtime allocations are then satisfied using slices from these initial chunks.
| Modifier and Type | Class and Description |
|---|---|
static class |
UpfrontAllocatingPageSource.ThresholdDirection |
| Modifier and Type | Field and Description |
|---|---|
static String |
ALLOCATION_LOG_LOCATION |
| Constructor and Description |
|---|
UpfrontAllocatingPageSource(BufferSource source,
long toAllocate,
int chunkSize)
Create an up-front allocating buffer source of
toAllocate total bytes, in
chunkSize byte chunks. |
UpfrontAllocatingPageSource(BufferSource source,
long toAllocate,
int maxChunk,
int minChunk)
Create an up-front allocating buffer source of
toAllocate total bytes, in
maximally sized chunks, within the given bounds. |
| Modifier and Type | Method and Description |
|---|---|
Runnable |
addAllocationThreshold(UpfrontAllocatingPageSource.ThresholdDirection direction,
long threshold,
Runnable action)
Adds an allocation threshold action.
|
Page |
allocate(int size,
boolean thief,
boolean victim,
OffHeapStorageArea owner)
Allocates a byte buffer of at least the given size.
|
void |
free(Page page)
Frees the supplied buffer.
|
long |
getAllocatedSize() |
long |
getAllocatedSizeUnSync() |
long |
getCapacity()
Return the total allocated capacity, used or not
|
Runnable |
removeAllocationThreshold(UpfrontAllocatingPageSource.ThresholdDirection direction,
long threshold)
Removes an allocation threshold action.
|
String |
toString() |
public static final String ALLOCATION_LOG_LOCATION
public UpfrontAllocatingPageSource(BufferSource source, long toAllocate, int chunkSize)
toAllocate total bytes, in
chunkSize byte chunks.source - source from which initial buffers will be allocatedtoAllocate - total space to allocate in byteschunkSize - chunkSize size to allocate in bytespublic UpfrontAllocatingPageSource(BufferSource source, long toAllocate, int maxChunk, int minChunk)
toAllocate total bytes, in
maximally sized chunks, within the given bounds.source - source from which initial buffers will be allocatedtoAllocate - total space to allocate in bytesmaxChunk - the largest chunk size in bytesminChunk - the smallest chunk size in bytespublic long getCapacity()
public Page allocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner)
This BufferSource is limited to allocating regions that are a power
of two in size. Supplied sizes are therefore rounded up to the next
largest power of two.
allocate in interface PageSourcesize - size of page to allocatethief - true if the allocation can steal space from victimsvictim - true if the allocated page should be eligible for stealingowner - owner from which subsequent steal should occurpublic void free(Page page)
If the given buffer was not allocated by this source or has already been
freed then an AssertionError is thrown.
free in interface PageSourcepublic long getAllocatedSize()
public long getAllocatedSizeUnSync()
public Runnable addAllocationThreshold(UpfrontAllocatingPageSource.ThresholdDirection direction, long threshold, Runnable action)
There can be only a single action associated with each unique direction and threshold combination. If an action is already associated with the supplied combination then the action is replaced by the new action and the old action is returned.
Actions are fired on passing through the supplied threshold and are called synchronously with the triggering allocation. This means care must be taken to avoid mutating any map that uses this page source from within the action otherwise deadlocks may result. Exceptions thrown by the action will be caught and logged by the page source and will not be propagated on the allocating thread.
direction - new actions directionthreshold - new actions threshold levelaction - fired on breaching the thresholdnull if no action was present.public Runnable removeAllocationThreshold(UpfrontAllocatingPageSource.ThresholdDirection direction, long threshold)
Removes the allocation threshold action for the given level and direction.
direction - registered actions directionthreshold - registered actions threshold levelnull if no action was present.Copyright © 2015–2024. All rights reserved.