@Override public long readLong( long offset ) { return getLong( block.addr + offset ); }
private long getLong( long p ) { if ( UnsafeUtil.allowUnalignedMemoryAccess ) { return UnsafeUtil.getLong( p ); } return UnsafeUtil.getLongByteWiseLittleEndian( p ); }
putLong( obj, aLongOffset, 1 ); assertThat( obj.aLong, is( 1L ) ); assertThat( getLong( obj, aLongOffset ), is( 1L ) ); obj.aLong = 0; assertThat( obj, is( new Obj() ) );
long getFilePageId( long pageRef ) { long filePageId = UnsafeUtil.getLong( offPageBinding( pageRef ) ) >>> SHIFT_FILE_PAGE_ID; return filePageId == MAX_FILE_PAGE_ID ? PageCursor.UNBOUND_PAGE_ID : filePageId; }
boolean isBoundTo( long pageRef, int swapperId, long filePageId ) { long address = offPageBinding( pageRef ); long expectedBinding = (filePageId << SHIFT_PARTIAL_FILE_PAGE_ID) + swapperId; long actualBinding = UnsafeUtil.getLong( address ) >>> SHIFT_SWAPPER_ID; return expectedBinding == actualBinding; }
int getSwapperId( long pageRef ) { long v = UnsafeUtil.getLong( offPageBinding( pageRef ) ) >>> SHIFT_SWAPPER_ID; return (int) (v & MASK_SHIFTED_SWAPPER_ID); // 21 bits. }
@Override public long get( long index ) { return UnsafeUtil.getLong( addressOf( index ) ); }
long getAddress( long pageRef ) { return UnsafeUtil.getLong( offAddress( pageRef ) ); }
protected long getLong( long address, int offset ) { return UnsafeUtil.getLong( address + offset ); }
private void setFilePageId( long pageRef, long filePageId ) { if ( filePageId > MAX_FILE_PAGE_ID ) { throw new IllegalArgumentException( format( "File page id: %s is bigger then max supported value %s.", filePageId, MAX_FILE_PAGE_ID ) ); } long address = offPageBinding( pageRef ); long v = UnsafeUtil.getLong( address ); filePageId = (filePageId << SHIFT_FILE_PAGE_ID) + (v & MASK_NOT_FILE_PAGE_ID); UnsafeUtil.putLong( address, filePageId ); }
private long getLongAt( long p ) { long value; if ( UnsafeUtil.allowUnalignedMemoryAccess ) { value = UnsafeUtil.getLong( p ); if ( !UnsafeUtil.storeByteOrderIsNative ) { value = Long.reverseBytes( value ); } } else { value = getLongBigEndian( p ); } return value; }
protected static long alignmentSafeGetLongAsTwoInts( long address ) { if ( UnsafeUtil.allowUnalignedMemoryAccess ) { return UnsafeUtil.getLong( address ); } // See javadoc in constructor as to why we do this long lsb = UnsafeUtil.getInt( address ) & 0xFFFFFFFFL; long msb = UnsafeUtil.getInt( address + Integer.BYTES ) & 0xFFFFFFFFL; return lsb | (msb << Integer.SIZE); } }
private void setSwapperId( long pageRef, int swapperId ) { swapperId = swapperId << SHIFT_SWAPPER_ID; long address = offPageBinding( pageRef ); long v = UnsafeUtil.getLong( address ) & MASK_NOT_SWAPPER_ID; UnsafeUtil.putLong( address, v + swapperId ); }
private void unsafeShiftRight( int fromPos, int toPos, int length, int shift ) { int longSteps = length >> 3; if ( UnsafeUtil.allowUnalignedMemoryAccess && longSteps > 0 ) { for ( int i = 0; i < longSteps; i++ ) { fromPos -= Long.BYTES; long x = UnsafeUtil.getLong( pointer + fromPos ); UnsafeUtil.putLong( pointer + fromPos + shift, x ); } } while ( fromPos > toPos ) { fromPos--; byte b = UnsafeUtil.getByte( pointer + fromPos ); UnsafeUtil.putByte( pointer + fromPos + shift, b ); } }
private void unsafeShiftLeft( int fromPos, int toPos, int length, int shift ) { int longSteps = length >> 3; if ( UnsafeUtil.allowUnalignedMemoryAccess && longSteps > 0 ) { for ( int i = 0; i < longSteps; i++ ) { long x = UnsafeUtil.getLong( pointer + fromPos ); UnsafeUtil.putLong( pointer + fromPos + shift, x ); fromPos += Long.BYTES; } } while ( fromPos < toPos ) { byte b = UnsafeUtil.getByte( pointer + fromPos ); UnsafeUtil.putByte( pointer + fromPos + shift, b ); fromPos++; } }
@Test void compareAndSetMaxLongField() { Obj obj = new Obj(); long offset = getFieldOffset( Obj.class, "aLong" ); assertThat( getAndSetLong( obj, offset, 42L ), equalTo( 0L ) ); compareAndSetMaxLong( obj, offset, 5 ); assertEquals( 42, getLong( obj, offset ) ); compareAndSetMaxLong( obj, offset, 105 ); assertEquals( 105, getLong( obj, offset ) ); }
boolean isBoundTo( long pageRef, int swapperId, long filePageId ) { long address = offPageBinding( pageRef ); long expectedBinding = (filePageId << SHIFT_PARTIAL_FILE_PAGE_ID) + swapperId; long actualBinding = UnsafeUtil.getLong( address ) >>> SHIFT_SWAPPER_ID; return expectedBinding == actualBinding; }
private void setFilePageId( long pageRef, long filePageId ) { if ( filePageId > MAX_FILE_PAGE_ID ) { throw new IllegalArgumentException( format( "File page id: %s is bigger then max supported value %s.", filePageId, MAX_FILE_PAGE_ID ) ); } long address = offPageBinding( pageRef ); long v = UnsafeUtil.getLong( address ); filePageId = (filePageId << SHIFT_FILE_PAGE_ID) + (v & MASK_NOT_FILE_PAGE_ID); UnsafeUtil.putLong( address, filePageId ); }
protected static long alignmentSafeGetLongAsTwoInts( long address ) { if ( UnsafeUtil.allowUnalignedMemoryAccess ) { return UnsafeUtil.getLong( address ); } // See javadoc in constructor as to why we do this long lsb = UnsafeUtil.getInt( address ) & 0xFFFFFFFFL; long msb = UnsafeUtil.getInt( address + Integer.BYTES ) & 0xFFFFFFFFL; return lsb | (msb << Integer.SIZE); }