static synchronized long getVictimPage( int pageSize, MemoryAllocationTracker allocationTracker ) { if ( victimPageSize < pageSize ) { // Note that we NEVER free any old victim pages. This is important because we cannot tell // when we are done using them. Therefor, victim pages are allocated and stay allocated // until our process terminates. victimPagePointer = UnsafeUtil.allocateMemory( pageSize, allocationTracker ); victimPageSize = pageSize; } return victimPagePointer; } }
Grab( Grab next, long size, MemoryAllocationTracker memoryTracker ) { this.next = next; this.address = UnsafeUtil.allocateMemory( size, memoryTracker ); this.limit = address + size; this.memoryTracker = memoryTracker; nextPointer = address; }
/** * Allocate a block of memory of the given size in bytes and update memory allocation tracker accordingly. * <p> * The memory is aligned such that it can be used for any data type. * The memory is uninitialised, so it may contain random garbage, or it may not. * @return a pointer to the allocated memory */ public static long allocateMemory( long bytes, MemoryAllocationTracker allocationTracker ) throws NativeMemoryAllocationRefusedError { final long pointer = allocateMemory( bytes ); allocationTracker.allocated( bytes ); return pointer; }
protected OffHeapNumberArray( long length, int itemSize, long base, MemoryAllocationTracker allocationTracker ) { super( itemSize, base ); UnsafeUtil.assertHasUnsafe(); this.length = length; this.allocationTracker = allocationTracker; long dataSize = length * itemSize; boolean itemSizeIsPowerOfTwo = Integer.bitCount( itemSize ) == 1; if ( UnsafeUtil.allowUnalignedMemoryAccess || !itemSizeIsPowerOfTwo ) { // we can end up here even if we require aligned memory access. Reason is that item size // isn't power of two anyway and so we have to fallback to safer means of accessing the memory, // i.e. byte for byte. allocatedBytes = dataSize; this.allocatedAddress = this.address = UnsafeUtil.allocateMemory( allocatedBytes, allocationTracker ); } else { // the item size is a power of two and we're required to access memory aligned // so we can allocate a bit more to ensure we can get an aligned memory address to start from. allocatedBytes = dataSize + itemSize - 1; this.allocatedAddress = UnsafeUtil.allocateMemory( allocatedBytes, allocationTracker ); this.address = UnsafeUtil.alignedMemory( allocatedAddress, itemSize ); } }
this.allocatedAddress = this.address = UnsafeUtil.allocateMemory( allocatedBytes, this.allocationTracker ); this.allocatedAddress = UnsafeUtil.allocateMemory( allocatedBytes, this.allocationTracker ); this.address = UnsafeUtil.alignedMemory( allocatedAddress, Integer.BYTES );
@VisibleForTesting MemoryBlock allocateNew( long size, MemoryAllocationTracker tracker ) { final long unalignedSize = requirePositive( size ) + Long.BYTES - 1; final long unalignedAddr = UnsafeUtil.allocateMemory( unalignedSize, tracker ); final long addr = UnsafeUtil.alignedMemory( unalignedAddr, Long.BYTES ); return new MemoryBlock( addr, size, unalignedAddr, unalignedSize ); }
@BeforeAll static void initialise() { lockAddr = UnsafeUtil.allocateMemory( Long.BYTES ); executor = Executors.newCachedThreadPool( new DaemonThreadFactory() ); }
long address = allocateMemory( sizeInBytes ); try long address2 = allocateMemory( sizeInBytes2 ); try
@Override public void clear() { if ( isByteUniform( defaultValue ) ) { UnsafeUtil.setMemory( address, length * itemSize, defaultValue[0] ); } else { long intermediary = UnsafeUtil.allocateMemory( itemSize, allocationTracker ); for ( int i = 0; i < defaultValue.length; i++ ) { UnsafeUtil.putByte( intermediary + i, defaultValue[i] ); } for ( long i = 0, adr = address; i < length; i++, adr += itemSize ) { UnsafeUtil.copyMemory( intermediary, adr, itemSize ); } UnsafeUtil.free( intermediary, itemSize, allocationTracker ); } }
long address = allocateMemory( sizeInBytes ); try
Grab( Grab next, long size, MemoryAllocationTracker memoryTracker ) { this.next = next; this.address = UnsafeUtil.allocateMemory( size, memoryTracker ); this.limit = address + size; this.memoryTracker = memoryTracker; nextPointer = address; }
static synchronized long getVictimPage( int pageSize, MemoryAllocationTracker allocationTracker ) { if ( victimPageSize < pageSize ) { // Note that we NEVER free any old victim pages. This is important because we cannot tell // when we are done using them. Therefor, victim pages are allocated and stay allocated // until our process terminates. victimPagePointer = UnsafeUtil.allocateMemory( pageSize, allocationTracker ); victimPageSize = pageSize; } return victimPagePointer; } }
/** * Allocate a block of memory of the given size in bytes and update memory allocation tracker accordingly. * <p> * The memory is aligned such that it can be used for any data type. * The memory is uninitialised, so it may contain random garbage, or it may not. * @return a pointer to the allocated memory */ public static long allocateMemory( long bytes, MemoryAllocationTracker allocationTracker ) throws NativeMemoryAllocationRefusedError { final long pointer = allocateMemory( bytes ); allocationTracker.allocated( bytes ); return pointer; }
protected OffHeapNumberArray( long length, int itemSize, long base, MemoryAllocationTracker allocationTracker ) { super( itemSize, base ); UnsafeUtil.assertHasUnsafe(); this.length = length; this.allocationTracker = allocationTracker; long dataSize = length * itemSize; boolean itemSizeIsPowerOfTwo = Integer.bitCount( itemSize ) == 1; if ( UnsafeUtil.allowUnalignedMemoryAccess || !itemSizeIsPowerOfTwo ) { // we can end up here even if we require aligned memory access. Reason is that item size // isn't power of two anyway and so we have to fallback to safer means of accessing the memory, // i.e. byte for byte. allocatedBytes = dataSize; this.allocatedAddress = this.address = UnsafeUtil.allocateMemory( allocatedBytes, allocationTracker ); } else { // the item size is a power of two and we're required to access memory aligned // so we can allocate a bit more to ensure we can get an aligned memory address to start from. allocatedBytes = dataSize + itemSize - 1; this.allocatedAddress = UnsafeUtil.allocateMemory( allocatedBytes, allocationTracker ); this.address = UnsafeUtil.alignedMemory( allocatedAddress, itemSize ); } }
this.allocatedAddress = this.address = UnsafeUtil.allocateMemory( allocatedBytes, this.allocationTracker ); this.allocatedAddress = UnsafeUtil.allocateMemory( allocatedBytes, this.allocationTracker ); this.address = UnsafeUtil.alignedMemory( allocatedAddress, Integer.BYTES );
this.allocatedAddress = this.address = UnsafeUtil.allocateMemory( allocatedBytes, this.allocationTracker ); this.allocatedAddress = UnsafeUtil.allocateMemory( allocatedBytes, this.allocationTracker ); this.address = UnsafeUtil.alignedMemory( allocatedAddress, Integer.BYTES );
@VisibleForTesting MemoryBlock allocateNew( long size, MemoryAllocationTracker tracker ) { final long unalignedSize = requirePositive( size ) + Long.BYTES - 1; final long unalignedAddr = UnsafeUtil.allocateMemory( unalignedSize, tracker ); final long addr = UnsafeUtil.alignedMemory( unalignedAddr, Long.BYTES ); return new MemoryBlock( addr, size, unalignedAddr, unalignedSize ); }
@Override public void clear() { if ( isByteUniform( defaultValue ) ) { UnsafeUtil.setMemory( address, length * itemSize, defaultValue[0] ); } else { long intermediary = UnsafeUtil.allocateMemory( itemSize, allocationTracker ); for ( int i = 0; i < defaultValue.length; i++ ) { UnsafeUtil.putByte( intermediary + i, defaultValue[i] ); } for ( long i = 0, adr = address; i < length; i++, adr += itemSize ) { UnsafeUtil.copyMemory( intermediary, adr, itemSize ); } UnsafeUtil.free( intermediary, itemSize, allocationTracker ); } }