private ByteBuffer allocate(int size, boolean onHeap) { metrics.misses.mark(); return BufferPool.allocate(size, onHeap); }
private static ByteBuffer maybeTakeFromPool(int size, boolean allocateOnHeapWhenExhausted) { if (size < 0) throw new IllegalArgumentException("Size must be positive (" + size + ")"); if (size == 0) return EMPTY_BUFFER; if (size > CHUNK_SIZE) { if (logger.isTraceEnabled()) logger.trace("Requested buffer size {} is bigger than {}, allocating directly", FBUtilities.prettyPrintMemory(size), FBUtilities.prettyPrintMemory(CHUNK_SIZE)); return localPool.get().allocate(size, allocateOnHeapWhenExhausted); } return localPool.get().get(size); }
public static void put(ByteBuffer buffer) { if (!(DISABLED || buffer.hasArray())) localPool.get().put(buffer); }
public void put(ByteBuffer buffer) { Chunk chunk = Chunk.getParentChunk(buffer); if (chunk == null) { FileUtils.clean(buffer); return; } LocalPool owner = chunk.owner; // ask the free method to take exclusive ownership of the act of recycling // if we are either: already not owned by anyone, or owned by ourselves long free = chunk.free(buffer, owner == null | owner == this); if (free == 0L) { // 0L => we own recycling responsibility, so must recycle; chunk.recycle(); // if we are also the owner, we must remove the Chunk from our local queue if (owner == this) removeFromLocalQueue(chunk); } else if (((free == -1L) && owner != this) && chunk.owner == null) { // although we try to take recycle ownership cheaply, it is not always possible to do so if the owner is racing to unset. // we must also check after completely freeing if the owner has since been unset, and try to recycle chunk.tryRecycle(); } }
public void put(ByteBuffer buffer) { Chunk chunk = Chunk.getParentChunk(buffer); if (chunk == null) { FileUtils.clean(buffer); return; } LocalPool owner = chunk.owner; // ask the free method to take exclusive ownership of the act of recycling // if we are either: already not owned by anyone, or owned by ourselves long free = chunk.free(buffer, owner == null | owner == this); if (free == 0L) { // 0L => we own recycling responsibility, so must recycle; chunk.recycle(); // if we are also the owner, we must remove the Chunk from our local queue if (owner == this) removeFromLocalQueue(chunk); } else if (((free == -1L) && owner != this) && chunk.owner == null) { // although we try to take recycle ownership cheaply, it is not always possible to do so if the owner is racing to unset. // we must also check after completely freeing if the owner has since been unset, and try to recycle chunk.tryRecycle(); } }
public void put(ByteBuffer buffer) { Chunk chunk = Chunk.getParentChunk(buffer); if (chunk == null) { FileUtils.clean(buffer); return; } LocalPool owner = chunk.owner; // ask the free method to take exclusive ownership of the act of recycling // if we are either: already not owned by anyone, or owned by ourselves long free = chunk.free(buffer, owner == null | owner == this); if (free == 0L) { // 0L => we own recycling responsibility, so must recycle; chunk.recycle(); // if we are also the owner, we must remove the Chunk from our local queue if (owner == this) removeFromLocalQueue(chunk); } else if (((free == -1L) && owner != this) && chunk.owner == null) { // although we try to take recycle ownership cheaply, it is not always possible to do so if the owner is racing to unset. // we must also check after completely freeing if the owner has since been unset, and try to recycle chunk.tryRecycle(); } }
public void put(ByteBuffer buffer) { Chunk chunk = Chunk.getParentChunk(buffer); if (chunk == null) { FileUtils.clean(buffer); return; } LocalPool owner = chunk.owner; // ask the free method to take exclusive ownership of the act of recycling // if we are either: already not owned by anyone, or owned by ourselves long free = chunk.free(buffer, owner == null | owner == this); if (free == 0L) { // 0L => we own recycling responsibility, so must recycle; chunk.recycle(); // if we are also the owner, we must remove the Chunk from our local queue if (owner == this) removeFromLocalQueue(chunk); } else if (((free == -1L) && owner != this) && chunk.owner == null) { // although we try to take recycle ownership cheaply, it is not always possible to do so if the owner is racing to unset. // we must also check after completely freeing if the owner has since been unset, and try to recycle chunk.tryRecycle(); } }
private static ByteBuffer maybeTakeFromPool(int size, boolean allocateOnHeapWhenExhausted) { if (size < 0) throw new IllegalArgumentException("Size must be positive (" + size + ")"); if (size == 0) return EMPTY_BUFFER; if (size > CHUNK_SIZE) { if (logger.isTraceEnabled()) logger.trace("Requested buffer size {} is bigger than {}, allocating directly", FBUtilities.prettyPrintMemory(size), FBUtilities.prettyPrintMemory(CHUNK_SIZE)); return localPool.get().allocate(size, allocateOnHeapWhenExhausted); } return localPool.get().get(size); }
public ByteBuffer get(int size) { for (Chunk chunk : chunks) { // first see if our own chunks can serve this buffer if (chunk == null) break; ByteBuffer buffer = chunk.get(size); if (buffer != null) return buffer; } // else ask the global pool Chunk chunk = addChunkFromGlobalPool(); if (chunk != null) return chunk.get(size); return null; }
private static ByteBuffer maybeTakeFromPool(int size, boolean allocateOnHeapWhenExhausted) { if (size < 0) throw new IllegalArgumentException("Size must be positive (" + size + ")"); if (size == 0) return EMPTY_BUFFER; if (size > CHUNK_SIZE) { if (logger.isTraceEnabled()) logger.trace("Requested buffer size {} is bigger than {}, allocating directly", FBUtilities.prettyPrintMemory(size), FBUtilities.prettyPrintMemory(CHUNK_SIZE)); return localPool.get().allocate(size, allocateOnHeapWhenExhausted); } return localPool.get().get(size); }
public ByteBuffer get(int size) { for (Chunk chunk : chunks) { // first see if our own chunks can serve this buffer if (chunk == null) break; ByteBuffer buffer = chunk.get(size); if (buffer != null) return buffer; } // else ask the global pool Chunk chunk = addChunkFromGlobalPool(); if (chunk != null) return chunk.get(size); return null; }
public ByteBuffer get(int size) { for (Chunk chunk : chunks) { // first see if our own chunks can serve this buffer if (chunk == null) break; ByteBuffer buffer = chunk.get(size); if (buffer != null) return buffer; } // else ask the global pool Chunk chunk = addChunkFromGlobalPool(); if (chunk != null) return chunk.get(size); return null; }
private static ByteBuffer maybeTakeFromPool(int size, boolean allocateOnHeapWhenExhausted) { if (size < 0) throw new IllegalArgumentException("Size must be positive (" + size + ")"); if (size == 0) return EMPTY_BUFFER; if (size > CHUNK_SIZE) { if (logger.isTraceEnabled()) logger.trace("Requested buffer size {} is bigger than {}, allocating directly", FBUtilities.prettyPrintMemory(size), FBUtilities.prettyPrintMemory(CHUNK_SIZE)); return localPool.get().allocate(size, allocateOnHeapWhenExhausted); } return localPool.get().get(size); }
public ByteBuffer get(int size) { for (Chunk chunk : chunks) { // first see if our own chunks can serve this buffer if (chunk == null) break; ByteBuffer buffer = chunk.get(size); if (buffer != null) return buffer; } // else ask the global pool Chunk chunk = addChunkFromGlobalPool(); if (chunk != null) return chunk.get(size); return null; }
private Chunk addChunkFromGlobalPool() { Chunk chunk = globalPool.get(); if (chunk == null) return null; addChunk(chunk); return chunk; }
/** This is not thread safe and should only be used for unit testing. */ @VisibleForTesting static void reset() { localPool.get().reset(); globalPool.reset(); }
@Override protected LocalPool initialValue() { return new LocalPool(); } };
/** This is not thread safe and should only be used for unit testing. */ @VisibleForTesting static void reset() { localPool.get().reset(); globalPool.reset(); }
private Chunk addChunkFromGlobalPool() { Chunk chunk = globalPool.get(); if (chunk == null) return null; addChunk(chunk); return chunk; }
/** This is not thread safe and should only be used for unit testing. */ @VisibleForTesting static void reset() { localPool.get().reset(); globalPool.reset(); }