ByteBuffer (int bufferSize) { while (true) { long used = nativeBytesUsed.get(); if (used + bufferSize > nativeCapacityBytes) { return null; } if (nativeBytesUsed.compareAndSet(used, used + bufferSize)) { ByteBuffer directByteBuffer = directBufferAllocator.allocate(bufferSize); statistics.pageAllocatedNative(bufferSize); return directByteBuffer; } } }