public class ThreadLocalPoolingMemoryManager extends Object implements HazelcastMemoryManager
PoolingMemoryManager.registerThread(Thread). After that, all requests from that thread
will be forwarded to its own ThreadLocalPoolingMemoryManager instance. A request to free a
block from a thread different than the one that allocated it will result in an exception.| Modifier and Type | Field and Description |
|---|---|
protected static int |
EXTERNAL_BLOCK_HEADER_SIZE |
protected com.hazelcast.internal.memory.MemoryAllocator |
pageAllocator |
SIZE_INVALID| Modifier | Constructor and Description |
|---|---|
protected |
ThreadLocalPoolingMemoryManager(int minBlockSize,
int pageSize,
LibMalloc malloc,
PooledNativeMemoryStats stats) |
| Modifier and Type | Method and Description |
|---|---|
protected long |
acquireInternal(com.hazelcast.memory.AddressQueue queue) |
long |
allocate(long size)
Allocates memory from an internal memory pool or falls back to OS
if not enough memory available in pool.
|
protected long |
allocateExternalBlock(long size)
Allocates a memory block directly from the page allocator.
|
void |
compact()
Compacts the memory region.
|
protected void |
compact(com.hazelcast.memory.AddressQueue queue) |
protected com.hazelcast.memory.AddressQueue |
createAddressQueue(int index,
int size) |
void |
dispose() |
String |
dump() |
void |
free(long address,
long size)
Gives allocated memory block back to internal pool or to OS
if pool is over capacity.
|
protected void |
freeExternalBlock(long address,
long size)
Frees an external block, which was allocated directly from the page allocator.
|
protected void |
freePage(long pageAddress) |
protected com.hazelcast.memory.AddressQueue |
getAddressQueue(long size) |
long |
getAllocatedSize(long address)
Returns allocated size of memory block as if it belongs to and is allocated by this memory manager.
|
double |
getFragmentationRatio(int size) |
com.hazelcast.memory.MemoryStats |
getMemoryStats() |
protected int |
getOffsetWithinPage(long address) |
protected int |
getQueueMergeThreshold(com.hazelcast.memory.AddressQueue queue) |
protected long |
getSizeInternal(long address) |
com.hazelcast.internal.memory.MemoryAllocator |
getSystemAllocator() |
long |
getUsableSize(long address)
Returns size of memory block as if it belongs to and is allocated by this memory manager.
|
protected int |
headerSize() |
protected void |
initialize(long address,
int size,
int offset) |
protected boolean |
isAvailable(long address) |
boolean |
isDisposed()
Gets the disposed state of this memory manager.
|
protected boolean |
isValidAndAvailable(long address,
int expectedSize) |
protected void |
markAvailable(long address) |
protected boolean |
markInvalid(long address,
int expectedSize,
int offset) |
protected boolean |
markUnavailable(long address,
int usedSize,
int internalSize) |
protected com.hazelcast.internal.util.counters.Counter |
newCounter() |
long |
newSequence()
Creates a new sequence.
|
protected void |
onMallocPage(long pageAddress) |
protected void |
onOome(com.hazelcast.memory.NativeOutOfMemoryError e) |
long |
reallocate(long address,
long currentSize,
long newSize) |
protected long |
toHeaderAddress(long blockBase,
int pageOffset) |
String |
toString() |
long |
validateAndGetAllocatedSize(long address)
Returns allocated size of memory block if and only if it belongs to and is allocated by this memory manager.
|
long |
validateAndGetUsableSize(long address)
Returns size of memory block if and only if it belongs to and is allocated by this memory manager.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitallocate, compact, free, getAllocatedSize, getMemoryStats, getSystemAllocator, getUsableSize, newSequence, validateAndGetUsableSizeprotected static final int EXTERNAL_BLOCK_HEADER_SIZE
protected final com.hazelcast.internal.memory.MemoryAllocator pageAllocator
protected ThreadLocalPoolingMemoryManager(int minBlockSize,
int pageSize,
LibMalloc malloc,
PooledNativeMemoryStats stats)
public boolean isDisposed()
HazelcastMemoryManagerisDisposed in interface HazelcastMemoryManagertrue if this memory manager is destroyed, false otherwisepublic void dispose()
dispose in interface com.hazelcast.nio.Disposablepublic long validateAndGetAllocatedSize(long address)
HazelcastMemoryManagerHazelcastMemoryManager.SIZE_INVALID is returned.
Allocated size includes usable memory size plus any header or metadata region size reserved by memory manager.
validateAndGetAllocatedSize in interface HazelcastMemoryManageraddress - address of memory blockHazelcastMemoryManager.SIZE_INVALID if it's unknownHazelcastMemoryManager.validateAndGetUsableSize(long)protected void initialize(long address,
int size,
int offset)
protected com.hazelcast.memory.AddressQueue createAddressQueue(int index,
int size)
protected int headerSize()
protected void onMallocPage(long pageAddress)
protected void onOome(com.hazelcast.memory.NativeOutOfMemoryError e)
protected long allocateExternalBlock(long size)
size - requested size of the block (the block actually allocated will be large enough to also
accommodate the external block header)protected void freeExternalBlock(long address,
long size)
address - address of the block (it is directly preceded by the external block header,
which is an integral part of the block actually allocated)size - size of the block (excludes header size)protected void markAvailable(long address)
protected boolean markUnavailable(long address,
int usedSize,
int internalSize)
protected boolean isAvailable(long address)
protected boolean markInvalid(long address,
int expectedSize,
int offset)
protected boolean isValidAndAvailable(long address,
int expectedSize)
protected long getSizeInternal(long address)
protected int getOffsetWithinPage(long address)
protected int getQueueMergeThreshold(com.hazelcast.memory.AddressQueue queue)
protected com.hazelcast.internal.util.counters.Counter newCounter()
public final long allocate(long size)
HazelcastMemoryManager
Complement of HazelcastMemoryManager.free(long, long).
Memory allocated by this method should be freed using
HazelcastMemoryManager.free(long, long)
allocate in interface com.hazelcast.internal.memory.MemoryAllocatorallocate in interface HazelcastMemoryManagersize - of requested memory blockpublic long reallocate(long address,
long currentSize,
long newSize)
reallocate in interface com.hazelcast.internal.memory.MemoryAllocatorpublic final void free(long address,
long size)
HazelcastMemoryManager
Complement of HazelcastMemoryManager.allocate(long).
Only memory allocated by HazelcastMemoryManager.allocate(long) can be
freed using this method.
free in interface com.hazelcast.internal.memory.MemoryAllocatorfree in interface HazelcastMemoryManageraddress - address of memory blocksize - size of memory blockpublic final com.hazelcast.memory.MemoryStats getMemoryStats()
getMemoryStats in interface HazelcastMemoryManagerpublic final com.hazelcast.internal.memory.MemoryAllocator getSystemAllocator()
getSystemAllocator in interface HazelcastMemoryManagerpublic final void compact()
HazelcastMemoryManagercompact in interface HazelcastMemoryManagerpublic final long getAllocatedSize(long address)
HazelcastMemoryManagerHazelcastMemoryManager.SIZE_INVALID is returned.
Allocated size includes usable memory size plus any header or metadata region size reserved by memory manager.
getAllocatedSize in interface HazelcastMemoryManageraddress - address of memory blockHazelcastMemoryManager.SIZE_INVALID if it's unknownHazelcastMemoryManager.getUsableSize(long)public final long getUsableSize(long address)
HazelcastMemoryManagerHazelcastMemoryManager.SIZE_INVALID is returned.getUsableSize in interface HazelcastMemoryManageraddress - address of memory blockHazelcastMemoryManager.SIZE_INVALID if it's unknownpublic final long validateAndGetUsableSize(long address)
HazelcastMemoryManagerHazelcastMemoryManager.SIZE_INVALID is returned.validateAndGetUsableSize in interface HazelcastMemoryManageraddress - address of memory blockHazelcastMemoryManager.SIZE_INVALID if it's unknownpublic final long newSequence()
HazelcastMemoryManager
Use case for this sequence is to avoid ABA problem by using it with the address
to create a "safe pointer" (address, sequence) to a memory block.
newSequence in interface HazelcastMemoryManagerprotected final com.hazelcast.memory.AddressQueue getAddressQueue(long size)
protected final long acquireInternal(com.hazelcast.memory.AddressQueue queue)
protected final long toHeaderAddress(long blockBase,
int pageOffset)
protected final void compact(com.hazelcast.memory.AddressQueue queue)
protected final void freePage(long pageAddress)
public final double getFragmentationRatio(int size)
public final String dump()
Copyright © 2020 Hazelcast, Inc.. All Rights Reserved.