Package org.infinispan.container.offheap
Class UnpooledOffHeapMemoryAllocator
java.lang.Object
org.infinispan.container.offheap.UnpooledOffHeapMemoryAllocator
- All Implemented Interfaces:
OffHeapMemoryAllocator
Memory allocator that just allocates memory directly using
Unsafe
.- Since:
- 9.0
- Author:
- wburns
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionlong
allocate
(long memoryLength) Allocates a new chunk of memory sized to the given length.void
deallocate
(long memoryAddress, long size) Deallocates the memory at the given address assuming a given size.static long
estimateSizeOverhead
(long size) Tries to estimate overhead of the allocation by first adding 8 to account for underlying allocator housekeeping and then rounds up to nearest power of 16 to account for 16 byte alignment.long
static long
offHeapEntrySize
(boolean evictionEnabled, boolean writeMetadataSize, int keySize, int valueSize) static long
offHeapEntrySize
(boolean evictionEnabled, boolean writeMetadataSize, int keySize, int valueSize, int metadataSize, int internalMetadataSize) It returns the off-heap size of an entry without alignment.
-
Constructor Details
-
UnpooledOffHeapMemoryAllocator
public UnpooledOffHeapMemoryAllocator()
-
-
Method Details
-
allocate
public long allocate(long memoryLength) Description copied from interface:OffHeapMemoryAllocator
Allocates a new chunk of memory sized to the given length.- Specified by:
allocate
in interfaceOffHeapMemoryAllocator
- Parameters:
memoryLength
- the size of memory to allocate- Returns:
- the memory address where the memory resides
-
deallocate
public void deallocate(long memoryAddress, long size) Description copied from interface:OffHeapMemoryAllocator
Deallocates the memory at the given address assuming a given size. This size is the size that was provided to allocate.- Specified by:
deallocate
in interfaceOffHeapMemoryAllocator
- Parameters:
memoryAddress
- the address to deallocate fromsize
- the total size
-
getAllocatedAmount
public long getAllocatedAmount()- Specified by:
getAllocatedAmount
in interfaceOffHeapMemoryAllocator
-
estimateSizeOverhead
public static long estimateSizeOverhead(long size) Tries to estimate overhead of the allocation by first adding 8 to account for underlying allocator housekeeping and then rounds up to nearest power of 16 to account for 16 byte alignment.- Parameters:
size
- the desired size of the allocation- Returns:
- the resulting size taking into account various overheads
-
offHeapEntrySize
public static long offHeapEntrySize(boolean evictionEnabled, boolean writeMetadataSize, int keySize, int valueSize) -
offHeapEntrySize
public static long offHeapEntrySize(boolean evictionEnabled, boolean writeMetadataSize, int keySize, int valueSize, int metadataSize, int internalMetadataSize) It returns the off-heap size of an entry without alignment.If alignment is required, use
estimateSizeOverhead(offHeapEntrySize(...))
. SeeestimateSizeOverhead(long)
,- Parameters:
evictionEnabled
- Set totrue
if eviction is enabled.writeMetadataSize
- Set totrue
if theMetadata
has versioning or it is a custom implementation.keySize
- The key size.valueSize
- The value size.metadataSize
- TheMetadata
size. IfwriteMetadataSize
is false, this parameter must include the size of mortal/transient entries (2 or 4 longs).internalMetadataSize
- ThePrivateMetadata
size.- Returns:
- The off-heap entry size without alignment!
-