@Override public DirectMemory slice(long startAddress, long sliceLength) { if (startAddress < 0) throw new IllegalArgumentException("startAddress must be >= 0"); if (sliceLength < 0) throw new IllegalArgumentException("sliceLength must be >= 0"); if (startAddress+sliceLength > length) throw new IllegalArgumentException("startAddress+sliceLength must be <= length"); return new DirectMemory(address+startAddress, sliceLength, order); }
private NativeBuffer realloc0(long newLength) { if (mmapped) throw new UnsupportedOperationException(); if (newLength >= MMAP_THRESHOLD) throw new UnsupportedOperationException(); if (newLength <= 0) throw new IllegalArgumentException("length must be > 0"); final long newAddress = UNSAFE.reallocateMemory(address, newLength); if (address == 0) throw new OutOfMemoryError(); closed = true; return new NativeBuffer(newAddress, new DirectMemory(newAddress, newLength, memory.getOrder()), false); }
if (length < 0) throw new IllegalArgumentException("error mapping [" + path + "]: length must be >= 0"); address = 0; memory = new DirectMemory(0, 0, order); } else { final int prot; throw new IOException("mmap(" + path + ", " + offset + ", " + length + ", " + mapMode + ") failed [Errno " + errno + "]"); memory = new DirectMemory(address, length, order);
throw new IllegalArgumentException("length must be >= 0"); address = 0; memory = new DirectMemory(0, 0, order); mmapped = false; } else if (length >= MMAP_THRESHOLD) { throw new RuntimeException("mmap /dev/zero failed with error "+MMapBuffer.errno()); memory = new DirectMemory(address, length, order); } catch (IOException e) { throw Throwables.propagate(e); throw new RuntimeException("anonymous mmap failed with error "+MMapBuffer.errno()); memory = new DirectMemory(address, length, order); memory = new DirectMemory(address, length, order); mmapped = false;
public NativeBuffer realloc(long newSize) { if (mmapped && newSize >= MMAP_THRESHOLD) { if (OS_TYPE_IS_MAC) { // MAC does not support mremap return createNewAndClose(newSize); } else { final long newAddress = MMapBuffer.mremap(address, memory.length(), newSize); if (newAddress == MMapBuffer.MAP_FAILED) { throw new RuntimeException("anonymous mremap failed with error " + MMapBuffer.errno()); } return new NativeBuffer(newAddress, new DirectMemory(newAddress, newSize, memory.getOrder()), true); } } else if (!mmapped && newSize < MMAP_THRESHOLD) { return realloc0(newSize); } else { return createNewAndClose(newSize); } }