Chunk(ByteBuffer slab) { assert !slab.hasArray(); this.slab = slab; this.baseAddress = MemoryUtil.getAddress(slab); // The number of bits by which we need to shift to obtain a unit // "31 &" is because numberOfTrailingZeros returns 32 when the capacity is zero this.shift = 31 & (Integer.numberOfTrailingZeros(slab.capacity() / 64)); // -1 means all free whilst 0 means all in use this.freeSlots = slab.capacity() == 0 ? 0L : -1L; this.original = DEBUG ? this : null; }
Chunk(ByteBuffer slab) { assert !slab.hasArray(); this.slab = slab; this.baseAddress = MemoryUtil.getAddress(slab); // The number of bits by which we need to shift to obtain a unit // "31 &" is because numberOfTrailingZeros returns 32 when the capacity is zero this.shift = 31 & (Integer.numberOfTrailingZeros(slab.capacity() / 64)); // -1 means all free whilst 0 means all in use this.freeSlots = slab.capacity() == 0 ? 0L : -1L; this.original = DEBUG ? this : null; }
Chunk(ByteBuffer slab) { assert !slab.hasArray(); this.slab = slab; this.baseAddress = MemoryUtil.getAddress(slab); // The number of bits by which we need to shift to obtain a unit // "31 &" is because numberOfTrailingZeros returns 32 when the capacity is zero this.shift = 31 & (Integer.numberOfTrailingZeros(slab.capacity() / 64)); // -1 means all free whilst 0 means all in use this.freeSlots = slab.capacity() == 0 ? 0L : -1L; this.original = DEBUG ? this : null; }
Chunk(ByteBuffer slab) { assert !slab.hasArray(); this.slab = slab; this.baseAddress = MemoryUtil.getAddress(slab); // The number of bits by which we need to shift to obtain a unit // "31 &" is because numberOfTrailingZeros returns 32 when the capacity is zero this.shift = 31 & (Integer.numberOfTrailingZeros(slab.capacity() / 64)); // -1 means all free whilst 0 means all in use this.freeSlots = slab.capacity() == 0 ? 0L : -1L; this.original = DEBUG ? this : null; }
private static ByteBuffer allocateDirectAligned(int capacity) { int align = MemoryUtil.pageSize(); if (Integer.bitCount(align) != 1) throw new IllegalArgumentException("Alignment must be a power of 2"); ByteBuffer buffer = ByteBuffer.allocateDirect(capacity + align); long address = MemoryUtil.getAddress(buffer); long offset = address & (align -1); // (address % align) if (offset == 0) { // already aligned buffer.limit(capacity); } else { // shift by offset int pos = (int)(align - offset); buffer.position(pos); buffer.limit(pos + capacity); } return buffer.slice(); }
private static ByteBuffer allocateDirectAligned(int capacity) { int align = MemoryUtil.pageSize(); if (Integer.bitCount(align) != 1) throw new IllegalArgumentException("Alignment must be a power of 2"); ByteBuffer buffer = ByteBuffer.allocateDirect(capacity + align); long address = MemoryUtil.getAddress(buffer); long offset = address & (align -1); // (address % align) if (offset == 0) { // already aligned buffer.limit(capacity); } else { // shift by offset int pos = (int)(align - offset); buffer.position(pos); buffer.limit(pos + capacity); } return buffer.slice(); }
private static ByteBuffer allocateDirectAligned(int capacity) { int align = MemoryUtil.pageSize(); if (Integer.bitCount(align) != 1) throw new IllegalArgumentException("Alignment must be a power of 2"); ByteBuffer buffer = ByteBuffer.allocateDirect(capacity + align); long address = MemoryUtil.getAddress(buffer); long offset = address & (align -1); // (address % align) if (offset == 0) { // already aligned buffer.limit(capacity); } else { // shift by offset int pos = (int)(align - offset); buffer.position(pos); buffer.limit(pos + capacity); } return buffer.slice(); }
private static ByteBuffer allocateDirectAligned(int capacity) { int align = MemoryUtil.pageSize(); if (Integer.bitCount(align) != 1) throw new IllegalArgumentException("Alignment must be a power of 2"); ByteBuffer buffer = ByteBuffer.allocateDirect(capacity + align); long address = MemoryUtil.getAddress(buffer); long offset = address & (align -1); // (address % align) if (offset == 0) { // already aligned buffer.limit(capacity); } else { // shift by offset int pos = (int)(align - offset); buffer.position(pos); buffer.limit(pos + capacity); } return buffer.slice(); }
return 1L; long address = MemoryUtil.getAddress(buffer); assert (address >= baseAddress) & (address <= baseAddress + capacity());
return 1L; long address = MemoryUtil.getAddress(buffer); assert (address >= baseAddress) & (address <= baseAddress + capacity());
return 1L; long address = MemoryUtil.getAddress(buffer); assert (address >= baseAddress) & (address <= baseAddress + capacity());
return 1L; long address = MemoryUtil.getAddress(buffer); assert (address >= baseAddress) & (address <= baseAddress + capacity());