PooledByteBufAllocator跟踪调试
所属分类 netty
浏览量 1346
echo 例子
newDirectBuffer 和 newHeapBuffer 方法上 断点调试 ,观察线程堆栈
Channel
ByteBufAllocator alloc();
ByteBufAllocator
AbstractByteBufAllocator
PooledByteBufAllocator
UnpooledByteBufAllocator
ByteBufUtil
String allocType = SystemPropertyUtil.get("io.netty.allocator.type", "pooled").toLowerCase(Locale.US).trim();
默认分配器 PooledByteBufAllocator
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder) {
final ThreadLocal threadCache = new ThreadLocal() {
PoolThreadCache
final PoolArena heapArena;
final PoolArena directArena;
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity)
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity)
读取时分配内存 PooledByteBufAllocator.newDirectBuffer
Thread [nioEventLoopGroup-4-1] (Suspended)
PooledByteBufAllocator.newDirectBuffer(int, int) line: 247
PooledByteBufAllocator(AbstractByteBufAllocator).directBuffer(int, int) line: 155
PooledByteBufAllocator(AbstractByteBufAllocator).directBuffer(int) line: 146
PooledByteBufAllocator(AbstractByteBufAllocator).ioBuffer(int) line: 107
AbstractNioByteChannel$NioByteUnsafe.read() line: 119
NioEventLoop.processSelectedKey(SelectionKey, AbstractNioChannel) line: 494
NioEventLoop.processSelectedKeysOptimized(SelectionKey[]) line: 461
NioEventLoop.processSelectedKeys() line: 378
NioEventLoop.run() line: 350
SingleThreadEventExecutor$2.run() line: 101
Thread.run() line: 745
写入时分配内存 PooledByteBufAllocator.newDirectBuffer
Thread [nioEventLoopGroup-4-1] (Suspended (breakpoint at line 233 in PooledByteBufAllocator))
PooledByteBufAllocator.newDirectBuffer(int, int) line: 233
PooledByteBufAllocator(AbstractByteBufAllocator).directBuffer(int, int) line: 155
PooledByteBufAllocator(AbstractByteBufAllocator).directBuffer(int) line: 146
PooledByteBufAllocator(AbstractByteBufAllocator).buffer(int) line: 83
ByteBufUtil.encodeString(ByteBufAllocator, CharBuffer, Charset) line: 338
StringEncoder.encode(ChannelHandlerContext, CharSequence, List
内存泄露检测
protected static ByteBuf toLeakAwareBuffer(ByteBuf buf) {
ResourceLeak leak;
switch (ResourceLeakDetector.getLevel()) {
case SIMPLE:
leak = AbstractByteBuf.leakDetector.open(buf);
if (leak != null) {
buf = new SimpleLeakAwareByteBuf(buf, leak);
}
break;
case ADVANCED:
case PARANOID:
leak = AbstractByteBuf.leakDetector.open(buf);
if (leak != null) {
buf = new AdvancedLeakAwareByteBuf(buf, leak);
}
break;
}
return buf;
}
上一篇
下一篇
select poll epoll 区别
netty ByteBuf vs java NIO ByteBuffer
netty高性能之道
netty代码debug切入点
java NIO selector
缓存雪崩穿透预热更新降级