/** * @param size the initial capacity * @param max the max capacity * @return allocated ByteBuf from pool */ public static ByteBuf directBuffer(int size, int max) { return directBuffer(size, max, ByteOrder.LITTLE_ENDIAN); }
/** * get the specified mapped memory bean */ public static BufferPoolMXBean getMappedBufferPool() { for (BufferPoolMXBean pool : getBufferPools()) { if (pool.getName().equals("mapped")) { return pool; } } return null; }
/** * borrowed from Spark */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
public ResizableMemoryBlock(ResizableLimitSpec limitSpec, boolean isDirect) { if (isDirect) { this.buffer = BufferPool.directBuffer((int) limitSpec.initialSize(), (int) limitSpec.limit()); this.memoryAddress = buffer.memoryAddress(); } else { this.buffer = BufferPool.heapBuffer((int) limitSpec.initialSize(), (int) limitSpec.limit()); } this.limitSpec = limitSpec; }
private void resize(int newSize) { Preconditions.checkArgument(newSize > 0, "Size must be greater than 0 bytes"); if (newSize > limitSpec.limit()) { throw new ValueOutOfRangeException("Resize cannot exceed the capacity limit"); } if (newSize < buffer.writableBytes()) { LOG.warn("The capacity reduction is ignored."); } int newBlockSize = UnsafeUtil.alignedSize(newSize); buffer = BufferPool.ensureWritable(buffer, newBlockSize); memoryAddress = buffer.memoryAddress(); }
@Before public void printTestName() { /* protect a travis stalled build */ BufferPoolMXBean direct = BufferPool.getDirectBufferPool(); BufferPoolMXBean mapped = BufferPool.getMappedBufferPool(); System.out.println(String.format("Used heap: %s/%s, direct:%s/%s, mapped:%s/%s, Active Threads: %d, Run: %s.%s", FileUtil.humanReadableByteCount(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(), false), FileUtil.humanReadableByteCount(Runtime.getRuntime().maxMemory(), false), FileUtil.humanReadableByteCount(direct.getMemoryUsed(), false), FileUtil.humanReadableByteCount(direct.getTotalCapacity(), false), FileUtil.humanReadableByteCount(mapped.getMemoryUsed(), false), FileUtil.humanReadableByteCount(mapped.getTotalCapacity(), false), Thread.activeCount(), getClass().getSimpleName(), name.getMethodName())); }
public ResizableMemoryBlock(ResizableLimitSpec limitSpec, boolean isDirect) { if (isDirect) { this.buffer = BufferPool.directBuffer((int) limitSpec.initialSize(), (int) limitSpec.limit()); this.memoryAddress = buffer.memoryAddress(); } else { this.buffer = BufferPool.heapBuffer((int) limitSpec.initialSize(), (int) limitSpec.limit()); } this.limitSpec = limitSpec; }
private void resize(int newSize) { Preconditions.checkArgument(newSize > 0, "Size must be greater than 0 bytes"); if (newSize > limitSpec.limit()) { throw new ValueOutOfRangeException("Resize cannot exceed the capacity limit"); } if (newSize < buffer.writableBytes()) { LOG.warn("The capacity reduction is ignored."); } int newBlockSize = UnsafeUtil.alignedSize(newSize); buffer = BufferPool.ensureWritable(buffer, newBlockSize); memoryAddress = buffer.memoryAddress(); }
/** * @param size the initial capacity * @param max the max capacity * @return allocated ByteBuf from pool */ public static ByteBuf directBuffer(int size, int max) { return directBuffer(size, max, ByteOrder.LITTLE_ENDIAN); }
if (!this.buffer.isWritable()) { this.buffer = BufferPool.ensureWritable(buffer, bufferSize * 2); this.bufferSize = buffer.capacity();
/** * get the specified direct memory bean */ public static BufferPoolMXBean getDirectBufferPool() { for (BufferPoolMXBean pool : getBufferPools()) { if (pool.getName().equals("direct")) { return pool; } } return null; }
/** * borrowed from Spark */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
public static ByteBuf directBuffer(int size) { return directBuffer(size, ByteOrder.LITTLE_ENDIAN); }
if (!this.buffer.isWritable()) { this.buffer = BufferPool.ensureWritable(buffer, bufferSize * 2); this.bufferSize = buffer.capacity();
/** * get the specified direct memory bean */ public static BufferPoolMXBean getDirectBufferPool() { for (BufferPoolMXBean pool : getBufferPools()) { if (pool.getName().equals("direct")) { return pool; } } return null; }
public ByteBufLineReader(InputChannel channel) { this(channel, BufferPool.directBuffer(DEFAULT_BUFFER)); }
/** * get the specified mapped memory bean */ public static BufferPoolMXBean getMappedBufferPool() { for (BufferPoolMXBean pool : getBufferPools()) { if (pool.getName().equals("mapped")) { return pool; } } return null; }
public ByteBufLineReader(InputChannel channel) { this(channel, BufferPool.directBuffer(DEFAULT_BUFFER)); }
public static ByteBuf directBuffer(int size) { return directBuffer(size, ByteOrder.LITTLE_ENDIAN); }
public static ByteBuf getNullChars(TableMeta meta) { byte[] nullCharByteArray = getNullCharsAsBytes(meta); ByteBuf nullChars = BufferPool.directBuffer(nullCharByteArray.length, nullCharByteArray.length); nullChars.writeBytes(nullCharByteArray); return nullChars; }