From ddc901f7361af765aade8ae8b221344ebef69079 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 9 Mar 2015 12:30:15 +0100 Subject: [PATCH] Fixed MappedByteBufferPool.Tagged. The problem was that release uses ByteBuffer.isDirect() to know where to put the released buffer, and Tagged was always creating heap buffers. This leads to a very high miss ratio in the pool, which causes OOME in some tests. --- .../jetty/io/MappedByteBufferPool.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java b/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java index 9b43660531a..7fd9471140f 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java @@ -57,23 +57,19 @@ public class MappedByteBufferPool implements ByteBufferPool if (result == null) { int capacity = bucket * factor; - result = direct ? createDirect(capacity) : createIndirect(capacity); + result = newByteBuffer(capacity, direct); } BufferUtil.clear(result); return result; } - protected ByteBuffer createDirect(int capacity) + protected ByteBuffer newByteBuffer(int capacity, boolean direct) { - return BufferUtil.allocateDirect(capacity); + return direct ? BufferUtil.allocateDirect(capacity) + : BufferUtil.allocate(capacity); } - public ByteBuffer createIndirect(int capacity) - { - return BufferUtil.allocate(capacity); - } - @Override public void release(ByteBuffer buffer) { @@ -124,21 +120,15 @@ public class MappedByteBufferPool implements ByteBufferPool { private final AtomicInteger tag = new AtomicInteger(); - public ByteBuffer createIndirect(int capacity) + @Override + protected ByteBuffer newByteBuffer(int capacity, boolean direct) { - ByteBuffer buffer = BufferUtil.allocate(capacity + 4); - buffer.limit(4); - buffer.putInt(0, tag.incrementAndGet()); - buffer.position(4); + ByteBuffer buffer = super.newByteBuffer(capacity + 4, direct); buffer.limit(buffer.capacity()); + buffer.putInt(tag.incrementAndGet()); ByteBuffer slice = buffer.slice(); BufferUtil.clear(slice); return slice; } - - protected ByteBuffer createDirect(int capacity) - { - return createIndirect(capacity); - } } }