@Override public void copyBytes(int src, int dst, int size) { assert size >= 0: "Size=" + size + ", but size must be >= 0"; assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(this.data+src, size); assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(this.data+dst, size); unsafe.copyMemory(this.data+src, this.data+dst, size); }
public static int readAbsoluteInt(long addr) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Integer.SIZE/Byte.SIZE); return unsafe.getInt(addr); } public static int readAbsoluteIntVolatile(long addr) {
public static int readAbsoluteIntVolatile(long addr) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Integer.SIZE/Byte.SIZE); return unsafe.getIntVolatile(null, addr); } public static long readAbsoluteLong(long addr) {
@Override public byte readByte(int offset) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(this.data+offset, 1); return readAbsoluteByte(this.data+offset); }
public static void writeAbsoluteIntVolatile(long addr, int value) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Integer.SIZE/Byte.SIZE); unsafe.putIntVolatile(null, addr, value); } public static boolean writeAbsoluteIntVolatile(long addr, int expected, int value) {
public static void writeAbsoluteLong(long addr, long value) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Long.SIZE/Byte.SIZE); unsafe.putLong(null, addr, value); } public static void writeAbsoluteLongVolatile(long addr, long value) {
/** * Reads from "addr" to "bytes". Number of bytes read/written is provided as * argument. */ public static void readUnsafeBytes(final long addr, final byte[] bytes, final int length) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, length); Platform.copyMemory(null, addr, bytes, Platform.BYTE_ARRAY_OFFSET, length); }
public static boolean writeAbsoluteIntVolatile(long addr, int expected, int value) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Integer.SIZE/Byte.SIZE); return unsafe.compareAndSwapInt(null, addr, expected, value); } public static void writeAbsoluteLong(long addr, long value) {
public static void clearAbsolute(long addr, int size) { assert size >= 0: "Size=" + size + ", but size must be >= 0"; assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, size); unsafe.setMemory(addr, size, (byte) 0); }
public static long readAbsoluteLong(long addr) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Long.SIZE/Byte.SIZE); return unsafe.getLong(addr); } public static long readAbsoluteLongVolatile(long addr) {
public static void writeAbsoluteInt(long addr, int value) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Integer.SIZE/Byte.SIZE); unsafe.putInt(null, addr, value); } public static void writeAbsoluteIntVolatile(long addr, int value) {
public static void writeAbsoluteLongVolatile(long addr, long value) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Long.SIZE/Byte.SIZE); unsafe.putLongVolatile(null, addr, value); } public static boolean writeAbsoluteLongVolatile(long addr, long expected, long value) {
public static byte readAbsoluteByte(long addr) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, 1); return unsafe.getByte(addr); }
public static void writeAbsoluteByte(long addr, byte value) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, 1); unsafe.putByte(addr, value); }
public static long readAbsoluteLongVolatile(long addr) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Long.SIZE/Byte.SIZE); return unsafe.getLongVolatile(null, addr); }
public static boolean writeAbsoluteLongVolatile(long addr, long expected, long value) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Long.SIZE/Byte.SIZE); return unsafe.compareAndSwapLong(null, addr, expected, value); }
/** * Reads from "offset" bytes after "addr" to "bytes". Number of bytes * read/written is provided as argument. The "offset" argument is being sent * separately instead of added in addr itself to workaround JDK bug in #51350 * (see https://reviewboard.gemstone.com/r/3246 for more details). */ public static void readUnsafeBytes(long addr, int offset, final byte[] bytes, int bytesOffset, int length) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, length + offset); Platform.copyMemory(null, addr + offset, bytes, Platform.BYTE_ARRAY_OFFSET + bytesOffset, length); }
public static void writeAbsoluteBytes(long addr, byte[] bytes, int bytesOffset, int size) { // Throwing an Error instead of using the "assert" keyword because passing < 0 to // copyMemory(...) can lead to a core dump with some JVMs and we don't want to // require the -ea JVM flag. if (size < 0) { throw new AssertionError("Size=" + size + ", but size must be >= 0"); } assert bytesOffset >= 0: "BytesOffset=" + bytesOffset + ", but bytesOffset must be >= 0"; assert bytesOffset + size <= bytes.length: "BytesOffset=" + bytesOffset + ",size=" + size + ",bytes.length=" + bytes.length + ", but bytesOffset + size must be <= " + bytes.length; if (size == 0) { return; // No point in wasting time copying 0 bytes } assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, size); Platform.copyMemory(bytes, Platform.BYTE_ARRAY_OFFSET + bytesOffset, null, addr, size); }
public static final int getDataSize(final UnsafeWrapper unsafe, final long addr) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(addr, Long.SIZE / Byte.SIZE); final int size = unsafe.getInt(addr + CHUNK_SIZE_OFFSET); int dataSizeDelta = unsafe.getInt(addr + REF_COUNT_OFFSET); dataSizeDelta &= DATA_SIZE_DELTA_MASK; dataSizeDelta >>= DATA_SIZE_SHIFT; return size - dataSizeDelta; }
/** * Returns an address that can be used with unsafe apis to access this chunks memory. * @param offset the offset from this chunk's first byte of the byte the returned address should point to. Must be >= 0. * @param size the number of bytes that will be read using the returned address. Assertion will use this to verify that all the memory accessed belongs to this chunk. Must be > 0. * @return a memory address that can be used with unsafe apis */ protected final long getUnsafeBaseAddress(int offset, int size) { assert offset >= 0 && offset + size <= getDataSize(): "Offset=" + offset + ",size=" + size + ",dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset + size must be <= " + getDataSize(); assert size > 0; long result = getBaseDataAddress() + offset; assert validateAddressAndSizeWithinSlab(result, size); return result; }