Class PhantomReferenceLimitedPageSource
java.lang.Object
org.terracotta.offheapstore.paging.PhantomReferenceLimitedPageSource
- All Implemented Interfaces:
PageSource
A
PhantomReference based limited byte buffer source.
This buffer source tracks 'freeing' of allocated byte buffers using phantom
references to the allocated buffers and an associated reference queue. An
AtomicLong is then used to track number of available bytes for
allocation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ReferenceQueue<ByteBuffer> private final Map<PhantomReference<ByteBuffer>, Integer> private final AtomicLong -
Constructor Summary
ConstructorsConstructorDescriptionPhantomReferenceLimitedPageSource(long max) Create a source that will allocate at mostmaxbytes. -
Method Summary
Modifier and TypeMethodDescriptionallocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner) Allocates a byte buffer of the given size.voidFrees the supplied buffer.private voidtoString()
-
Field Details
-
allocatedBuffers
-
bufferSizes
-
max
-
-
Constructor Details
-
PhantomReferenceLimitedPageSource
public PhantomReferenceLimitedPageSource(long max) Create a source that will allocate at mostmaxbytes.- Parameters:
max- the maximum total size of all available buffers
-
-
Method Details
-
allocate
Allocates a byte buffer of the given size.This
BufferSourceplaces no restrictions on the requested size of the buffer.- Specified by:
allocatein interfacePageSource- Parameters:
size- size of page to allocatethief-trueif the allocation can steal space from victimsvictim-trueif the allocated page should be eligible for stealingowner- owner from which subsequent steal should occur- Returns:
- an allocated page, or
nullin the case of failure
-
free
Frees the supplied buffer.This implementation is a no-op, no validation of the supplied buffer is attempted, as freeing of allocated buffers is monitored via phantom references.
- Specified by:
freein interfacePageSource
-
processQueue
private void processQueue() -
toString
-