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(allocator.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)) allocator.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); }