private void clear( long bufferAddress, int bufferSize ) { UnsafeUtil.setMemory( bufferAddress, bufferSize, MuninnPageCache.ZERO_BYTE ); }
@Override public void clear() { setMemory( block.unalignedAddr, block.unalignedSize, (byte) 0 ); }
private void clearMemory() { UnsafeUtil.setMemory( address, dataSize, (byte) -1 ); }
protected VALUE internalRemove( long keyAddress ) { UnsafeUtil.setMemory( keyAddress, bytesPerKey, (byte) -1 ); return valueMarker; }
@Override public void zapPage() { if ( pageSize == 0 ) { // if this page has been closed then pageSize == 0 and we must adhere to making writes // trigger outOfBounds when closed outOfBounds = true; } else { UnsafeUtil.setMemory( pointer, pageSize, (byte) 0 ); } }
@Override public void putBytes( int bytes, byte value ) { long p = getBoundedPointer( offset, bytes ); if ( !outOfBounds ) { UnsafeUtil.setMemory( p, bytes, value ); } offset += bytes; }
@Override public long read( long fpId, long bufferAddress, int bufferSize ) throws IOException { if ( fpId == filePageId ) { UnsafeUtil.setMemory( bufferAddress, bufferSize, pageByteContents ); return bufferSize; } throw new IOException( "Did not expect this file page id = " + fpId ); } };
@Override public Memory allocate( long size, boolean zeroed ) { final MemoryBlock block = blockAllocator.allocate( size, tracker ); if ( zeroed ) { setMemory( block.unalignedAddr, block.unalignedSize, (byte) 0 ); } return new OffHeapMemory( block ); }
"pointer = %h, readTotal = %s, length = %s, page size = %s", bufferAddress, readTotal, filePageSize, bufferSize ); UnsafeUtil.setMemory( bufferAddress + readTotal, filePageSize - readTotal, MuninnPageCache.ZERO_BYTE ); return readTotal;
@Override public void clear() { if ( isByteUniform( defaultValue ) ) { UnsafeUtil.setMemory( address, length << shift, (byte)defaultValue ); } else { for ( long i = 0, adr = address; i < length; i++, adr += itemSize ) { UnsafeUtil.putInt( adr, defaultValue ); } } } }
@Override public void clear() { if ( isByteUniform( defaultValue ) ) { UnsafeUtil.setMemory( address, length << shift, (byte)defaultValue ); } else { for ( long i = 0, adr = address; i < length; i++, adr += itemSize ) { UnsafeUtil.putLong( adr, defaultValue ); } } } }
@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 ); } }
/** * Allocate a block of memory of the given size in bytes, and return a pointer to that memory. * <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 ) throws NativeMemoryAllocationRefusedError { final long pointer; try { pointer = unsafe.allocateMemory( bytes ); } catch ( Throwable e ) { throw new NativeMemoryAllocationRefusedError( bytes, GlobalMemoryTracker.INSTANCE.usedDirectMemory(), e ); } if ( DIRTY_MEMORY ) { setMemory( pointer, bytes, (byte) 0xA5 ); } addAllocatedPointer( pointer, bytes ); GlobalMemoryTracker.INSTANCE.allocated( bytes ); return pointer; }
try setMemory( address, sizeInBytes, (byte) 0 ); ByteBuffer a = newDirectByteBuffer( address, sizeInBytes ); assertThat( a, is( not( sameInstance( newDirectByteBuffer( address, sizeInBytes ) ) ) ) ); try setMemory( address2, sizeInBytes2, (byte) 0 ); initDirectByteBuffer( a, address2, sizeInBytes2 ); assertThat( a.hasArray(), is( false ) );
setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getByte( address ), is( (byte) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getByteVolatile( address ), is( (byte) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getShort( address ), is( (short) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getShortVolatile( address ), is( (short) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getFloat( address ), is( (float) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getFloatVolatile( address ), is( (float) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getChar( address ), is( (char) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getCharVolatile( address ), is( (char) 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getInt( address ), is( 0 ) ); setMemory( address, sizeInBytes, (byte) 0 ); assertThat( getIntVolatile( address ), is( 0 ) );
protected VALUE internalRemove( long keyAddress ) { UnsafeUtil.setMemory( keyAddress, bytesPerKey, (byte) -1 ); return valueMarker; }
@Override public void clear() { setMemory( block.unalignedAddr, block.unalignedSize, (byte) 0 ); }
@Override public void putBytes( int bytes, byte value ) { long p = getBoundedPointer( offset, bytes ); if ( !outOfBounds ) { UnsafeUtil.setMemory( p, bytes, value ); } offset += bytes; }
@Override public Memory allocate( long size, boolean zeroed ) { final MemoryBlock block = blockAllocator.allocate( size, tracker ); if ( zeroed ) { setMemory( block.unalignedAddr, block.unalignedSize, (byte) 0 ); } return new OffHeapMemory( block ); }