protected Memory(long bytes) { if (bytes <= 0) throw new AssertionError(); size = bytes; peer = MemoryUtil.allocate(size); // we permit a 0 peer iff size is zero, since such an allocation makes no sense, and an allocator would be // justified in returning a null pointer (and permitted to do so: http://www.cplusplus.com/reference/cstdlib/malloc) if (peer == 0) throw new OutOfMemoryError(); }
protected Memory(long bytes) { if (bytes <= 0) throw new AssertionError(); size = bytes; peer = MemoryUtil.allocate(size); // we permit a 0 peer iff size is zero, since such an allocation makes no sense, and an allocator would be // justified in returning a null pointer (and permitted to do so: http://www.cplusplus.com/reference/cstdlib/malloc) if (peer == 0) throw new OutOfMemoryError(); }
protected Memory(long bytes) { if (bytes <= 0) throw new AssertionError(); size = bytes; peer = MemoryUtil.allocate(size); // we permit a 0 peer iff size is zero, since such an allocation makes no sense, and an allocator would be // justified in returning a null pointer (and permitted to do so: http://www.cplusplus.com/reference/cstdlib/malloc) if (peer == 0) throw new OutOfMemoryError(); }
protected Memory(long bytes) { if (bytes <= 0) throw new AssertionError(); size = bytes; peer = MemoryUtil.allocate(size); // we permit a 0 peer iff size is zero, since such an allocation makes no sense, and an allocator would be // justified in returning a null pointer (and permitted to do so: http://www.cplusplus.com/reference/cstdlib/malloc) if (peer == 0) throw new OutOfMemoryError(); }
private long allocateOversize(int size) { // satisfy large allocations directly from JVM since they don't cause fragmentation // as badly, and fill up our regions quickly Region region = new Region(MemoryUtil.allocate(size), size); regions.add(region); long peer; if ((peer = region.allocate(size)) == -1) throw new AssertionError(); return peer; }
private long allocateOversize(int size) { // satisfy large allocations directly from JVM since they don't cause fragmentation // as badly, and fill up our regions quickly Region region = new Region(MemoryUtil.allocate(size), size); regions.add(region); long peer; if ((peer = region.allocate(size)) == -1) throw new AssertionError(); return peer; }
private long allocateOversize(int size) { // satisfy large allocations directly from JVM since they don't cause fragmentation // as badly, and fill up our regions quickly Region region = new Region(MemoryUtil.allocate(size), size); regions.add(region); long peer; if ((peer = region.allocate(size)) == -1) throw new AssertionError(); return peer; }
private long allocateOversize(int size) { // satisfy large allocations directly from JVM since they don't cause fragmentation // as badly, and fill up our regions quickly Region region = new Region(MemoryUtil.allocate(size), size); regions.add(region); long peer; if ((peer = region.allocate(size)) == -1) throw new AssertionError(); return peer; }
private void trySwapRegion(Region current, int minSize) { // decide how big we want the new region to be: // * if there is no prior region, we set it to min size // * otherwise we double its size; if it's too small to fit the allocation, we round it up to 4-8x its size int size; if (current == null) size = MIN_REGION_SIZE; else size = current.capacity * 2; if (minSize > size) size = Integer.highestOneBit(minSize) << 3; size = Math.min(MAX_REGION_SIZE, size); // first we try and repurpose a previously allocated region RaceAllocated raceAllocated = RACE_ALLOCATED.get(size); Region next = raceAllocated.poll(); // if there are none, we allocate one if (next == null) next = new Region(MemoryUtil.allocate(size), size); // we try to swap in the region we've obtained; // if we fail to swap the region, we try to stash it for repurposing later; if we're out of stash room, we free it if (currentRegion.compareAndSet(current, next)) regions.add(next); else if (!raceAllocated.stash(next)) MemoryUtil.free(next.peer); }
private void trySwapRegion(Region current, int minSize) { // decide how big we want the new region to be: // * if there is no prior region, we set it to min size // * otherwise we double its size; if it's too small to fit the allocation, we round it up to 4-8x its size int size; if (current == null) size = MIN_REGION_SIZE; else size = current.capacity * 2; if (minSize > size) size = Integer.highestOneBit(minSize) << 3; size = Math.min(MAX_REGION_SIZE, size); // first we try and repurpose a previously allocated region RaceAllocated raceAllocated = RACE_ALLOCATED.get(size); Region next = raceAllocated.poll(); // if there are none, we allocate one if (next == null) next = new Region(MemoryUtil.allocate(size), size); // we try to swap in the region we've obtained; // if we fail to swap the region, we try to stash it for repurposing later; if we're out of stash room, we free it if (currentRegion.compareAndSet(current, next)) regions.add(next); else if (!raceAllocated.stash(next)) MemoryUtil.free(next.peer); }
private void trySwapRegion(Region current, int minSize) { // decide how big we want the new region to be: // * if there is no prior region, we set it to min size // * otherwise we double its size; if it's too small to fit the allocation, we round it up to 4-8x its size int size; if (current == null) size = MIN_REGION_SIZE; else size = current.capacity * 2; if (minSize > size) size = Integer.highestOneBit(minSize) << 3; size = Math.min(MAX_REGION_SIZE, size); // first we try and repurpose a previously allocated region RaceAllocated raceAllocated = RACE_ALLOCATED.get(size); Region next = raceAllocated.poll(); // if there are none, we allocate one if (next == null) next = new Region(MemoryUtil.allocate(size), size); // we try to swap in the region we've obtained; // if we fail to swap the region, we try to stash it for repurposing later; if we're out of stash room, we free it if (currentRegion.compareAndSet(current, next)) regions.add(next); else if (!raceAllocated.stash(next)) MemoryUtil.free(next.peer); }
private void trySwapRegion(Region current, int minSize) { // decide how big we want the new region to be: // * if there is no prior region, we set it to min size // * otherwise we double its size; if it's too small to fit the allocation, we round it up to 4-8x its size int size; if (current == null) size = MIN_REGION_SIZE; else size = current.capacity * 2; if (minSize > size) size = Integer.highestOneBit(minSize) << 3; size = Math.min(MAX_REGION_SIZE, size); // first we try and repurpose a previously allocated region RaceAllocated raceAllocated = RACE_ALLOCATED.get(size); Region next = raceAllocated.poll(); // if there are none, we allocate one if (next == null) next = new Region(MemoryUtil.allocate(size), size); // we try to swap in the region we've obtained; // if we fail to swap the region, we try to stash it for repurposing later; if we're out of stash room, we free it if (currentRegion.compareAndSet(current, next)) regions.add(next); else if (!raceAllocated.stash(next)) MemoryUtil.free(next.peer); }