Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enable a user specify an arbitrary information with ReferenceCounted.…

…touch()

- Related: #2163
- Add ResourceLeakHint to allow a user to provide a meaningful information about the leak when touching it
- DefaultChannelHandlerContext now implements ResourceLeakHint to tell where the message is going.
- Cleaner resource leak report by excluding noisy stack trace elements
  • Loading branch information...
commit 0f1b1be0aa008d6fc227e3af622d71062227d5ae 1 parent 3061b15
@trustin trustin authored
Showing with 493 additions and 18 deletions.
  1. +6 −0 buffer/src/main/java/io/netty/buffer/AbstractDerivedByteBuf.java
  2. +6 −1 buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java
  3. +6 −0 buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareByteBuf.java
  4. +3 −0  buffer/src/main/java/io/netty/buffer/ByteBuf.java
  5. +3 −0  buffer/src/main/java/io/netty/buffer/ByteBufHolder.java
  6. +10 −0 buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java
  7. +6 −0 buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java
  8. +5 −0 buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java
  9. +5 −0 buffer/src/main/java/io/netty/buffer/SimpleLeakAwareByteBuf.java
  10. +6 −0 buffer/src/main/java/io/netty/buffer/SwappedByteBuf.java
  11. +5 −0 buffer/src/main/java/io/netty/buffer/UnreleasableByteBuf.java
  12. +6 −0 buffer/src/main/java/io/netty/buffer/WrappedByteBuf.java
  13. +5 −0 codec-http/src/main/java/io/netty/handler/codec/http/ComposedLastHttpContent.java
  14. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpRequest.java
  15. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpResponse.java
  16. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java
  17. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/DefaultLastHttpContent.java
  18. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java
  19. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/FullHttpRequest.java
  20. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/FullHttpResponse.java
  21. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/HttpContent.java
  22. +8 −0 codec-http/src/main/java/io/netty/handler/codec/http/LastHttpContent.java
  23. +5 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java
  24. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractHttpData.java
  25. +6 −1 codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java
  26. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/multipart/Attribute.java
  27. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/DiskAttribute.java
  28. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/DiskFileUpload.java
  29. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/multipart/FileUpload.java
  30. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpData.java
  31. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java
  32. +3 −0  codec-http/src/main/java/io/netty/handler/codec/http/multipart/InterfaceHttpData.java
  33. +8 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/InternalAttribute.java
  34. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MemoryAttribute.java
  35. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MemoryFileUpload.java
  36. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MixedAttribute.java
  37. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MixedFileUpload.java
  38. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/BinaryWebSocketFrame.java
  39. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/CloseWebSocketFrame.java
  40. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/ContinuationWebSocketFrame.java
  41. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/PingWebSocketFrame.java
  42. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/PongWebSocketFrame.java
  43. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/TextWebSocketFrame.java
  44. +6 −0 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrame.java
  45. +6 −0 codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java
  46. +3 −0  codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyDataFrame.java
  47. +6 −0 codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultLastMemcacheContent.java
  48. +6 −0 codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultMemcacheContent.java
  49. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/FullMemcacheMessage.java
  50. +8 −0 codec-memcache/src/main/java/io/netty/handler/codec/memcache/LastMemcacheContent.java
  51. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheContent.java
  52. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheMessage.java
  53. +6 −1 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/AbstractBinaryMemcacheMessage.java
  54. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheMessage.java
  55. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheRequest.java
  56. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheResponse.java
  57. +6 −0 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheRequest.java
  58. +6 −0 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheResponse.java
  59. +6 −0 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultFullBinaryMemcacheRequest.java
  60. +6 −0 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultFullBinaryMemcacheResponse.java
  61. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/FullBinaryMemcacheRequest.java
  62. +3 −0  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/FullBinaryMemcacheResponse.java
  63. +6 −0 codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java
  64. +5 −0 common/src/main/java/io/netty/util/AbstractReferenceCounted.java
  65. +13 −0 common/src/main/java/io/netty/util/ReferenceCountUtil.java
  66. +8 −1 common/src/main/java/io/netty/util/ReferenceCounted.java
  67. +7 −1 common/src/main/java/io/netty/util/ResourceLeak.java
  68. +49 −8 common/src/main/java/io/netty/util/ResourceLeakDetector.java
  69. +27 −0 common/src/main/java/io/netty/util/ResourceLeakHint.java
  70. +6 −0 transport-sctp/src/main/java/io/netty/channel/sctp/SctpMessage.java
  71. +6 −0 transport-udt/src/main/java/io/netty/channel/udt/UdtMessage.java
  72. +12 −0 transport/src/main/java/io/netty/channel/AddressedEnvelope.java
  73. +6 −0 transport/src/main/java/io/netty/channel/DefaultAddressedEnvelope.java
  74. +16 −4 transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java
  75. +5 −0 transport/src/main/java/io/netty/channel/DefaultFileRegion.java
  76. +3 −0  transport/src/main/java/io/netty/channel/FileRegion.java
  77. +6 −0 transport/src/main/java/io/netty/channel/socket/DatagramPacket.java
  78. +1 −1  transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java
View
6 buffer/src/main/java/io/netty/buffer/AbstractDerivedByteBuf.java
@@ -52,6 +52,12 @@ public final ByteBuf touch() {
}
@Override
+ public final ByteBuf touch(Object hint) {
+ unwrap().touch(hint);
+ return this;
+ }
+
+ @Override
public final boolean release() {
return unwrap().release();
}
View
7 buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java
@@ -108,7 +108,12 @@ public ByteBuf retain(int increment) {
}
@Override
- public final ByteBuf touch() {
+ public ByteBuf touch() {
+ return this;
+ }
+
+ @Override
+ public ByteBuf touch(Object hint) {
return this;
}
View
6 buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareByteBuf.java
@@ -723,6 +723,12 @@ public ByteBuf touch() {
}
@Override
+ public ByteBuf touch(Object hint) {
+ leak.record(hint);
+ return this;
+ }
+
+ @Override
public ByteBuf capacity(int newCapacity) {
leak.record();
return super.capacity(newCapacity);
View
3  buffer/src/main/java/io/netty/buffer/ByteBuf.java
@@ -1880,4 +1880,7 @@
@Override
public abstract ByteBuf touch();
+
+ @Override
+ public abstract ByteBuf touch(Object hint);
}
View
3  buffer/src/main/java/io/netty/buffer/ByteBufHolder.java
@@ -45,4 +45,7 @@
@Override
ByteBufHolder touch();
+
+ @Override
+ ByteBufHolder touch(Object hint);
}
View
10 buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java
@@ -1571,6 +1571,16 @@ public CompositeByteBuf retain() {
}
@Override
+ public CompositeByteBuf touch() {
+ return (CompositeByteBuf) super.touch();
+ }
+
+ @Override
+ public CompositeByteBuf touch(Object hint) {
+ return (CompositeByteBuf) super.touch(hint);
+ }
+
+ @Override
public ByteBuffer[] nioBuffers() {
return nioBuffers(readerIndex(), readableBytes());
}
View
6 buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java
@@ -75,6 +75,12 @@ public ByteBufHolder touch() {
}
@Override
+ public ByteBufHolder touch(Object hint) {
+ data.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return data.release();
}
View
5 buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java
@@ -837,6 +837,11 @@ public ByteBuf touch() {
}
@Override
+ public ByteBuf touch(Object hint) {
+ return this;
+ }
+
+ @Override
public boolean release() {
return false;
}
View
5 buffer/src/main/java/io/netty/buffer/SimpleLeakAwareByteBuf.java
@@ -35,6 +35,11 @@ public ByteBuf touch() {
}
@Override
+ public ByteBuf touch(Object hint) {
+ return this;
+ }
+
+ @Override
public boolean release() {
boolean deallocated = super.release();
if (deallocated) {
View
6 buffer/src/main/java/io/netty/buffer/SwappedByteBuf.java
@@ -821,6 +821,12 @@ public ByteBuf touch() {
}
@Override
+ public ByteBuf touch(Object hint) {
+ buf.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return buf.release();
}
View
5 buffer/src/main/java/io/netty/buffer/UnreleasableByteBuf.java
@@ -81,6 +81,11 @@ public ByteBuf touch() {
}
@Override
+ public ByteBuf touch(Object hint) {
+ return this;
+ }
+
+ @Override
public boolean release() {
return false;
}
View
6 buffer/src/main/java/io/netty/buffer/WrappedByteBuf.java
@@ -806,6 +806,12 @@ public ByteBuf touch() {
}
@Override
+ public ByteBuf touch(Object hint) {
+ buf.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean isReadable(int size) {
return buf.isReadable(size);
}
View
5 codec-http/src/main/java/io/netty/handler/codec/http/ComposedLastHttpContent.java
@@ -55,6 +55,11 @@ public LastHttpContent touch() {
}
@Override
+ public LastHttpContent touch(Object hint) {
+ return this;
+ }
+
+ @Override
public LastHttpContent duplicate() {
return copy();
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpRequest.java
@@ -79,6 +79,12 @@ public FullHttpRequest touch() {
}
@Override
+ public FullHttpRequest touch(Object hint) {
+ content.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return content.release();
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpResponse.java
@@ -82,6 +82,12 @@ public FullHttpResponse touch() {
}
@Override
+ public FullHttpResponse touch(Object hint) {
+ content.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return content.release();
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java
@@ -74,6 +74,12 @@ public HttpContent touch() {
}
@Override
+ public HttpContent touch(Object hint) {
+ content.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return content.release();
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/DefaultLastHttpContent.java
@@ -76,6 +76,12 @@ public LastHttpContent touch() {
}
@Override
+ public LastHttpContent touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
+
+ @Override
public HttpHeaders trailingHeaders() {
return trailingHeaders;
}
View
3  codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java
@@ -33,5 +33,8 @@
FullHttpMessage touch();
@Override
+ FullHttpMessage touch(Object hint);
+
+ @Override
FullHttpMessage duplicate();
}
View
3  codec-http/src/main/java/io/netty/handler/codec/http/FullHttpRequest.java
@@ -33,6 +33,9 @@
FullHttpRequest touch();
@Override
+ FullHttpRequest touch(Object hint);
+
+ @Override
FullHttpRequest duplicate();
@Override
View
3  codec-http/src/main/java/io/netty/handler/codec/http/FullHttpResponse.java
@@ -33,6 +33,9 @@
FullHttpResponse touch();
@Override
+ FullHttpResponse touch(Object hint);
+
+ @Override
FullHttpResponse duplicate();
@Override
View
3  codec-http/src/main/java/io/netty/handler/codec/http/HttpContent.java
@@ -41,4 +41,7 @@
@Override
HttpContent touch();
+
+ @Override
+ HttpContent touch(Object hint);
}
View
8 codec-http/src/main/java/io/netty/handler/codec/http/LastHttpContent.java
@@ -80,6 +80,11 @@ public LastHttpContent touch() {
}
@Override
+ public LastHttpContent touch(Object hint) {
+ return this;
+ }
+
+ @Override
public boolean release() {
return false;
}
@@ -110,5 +115,8 @@ public String toString() {
LastHttpContent touch();
@Override
+ LastHttpContent touch(Object hint);
+
+ @Override
LastHttpContent duplicate();
}
View
5 codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java
@@ -401,4 +401,9 @@ public File getFile() throws IOException {
public HttpData touch() {
return this;
}
+
+ @Override
+ public HttpData touch(Object hint) {
+ return this;
+ }
}
View
3  codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractHttpData.java
@@ -133,4 +133,7 @@ public HttpData retain(int increment) {
@Override
public abstract HttpData touch();
+
+ @Override
+ public abstract HttpData touch(Object hint);
}
View
7 codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java
@@ -260,8 +260,13 @@ public File getFile() throws IOException {
@Override
public HttpData touch() {
+ return touch(null);
+ }
+
+ @Override
+ public HttpData touch(Object hint) {
if (byteBuf != null) {
- byteBuf.touch();
+ byteBuf.touch(hint);
}
return this;
}
View
3  codec-http/src/main/java/io/netty/handler/codec/http/multipart/Attribute.java
@@ -45,4 +45,7 @@
@Override
Attribute touch();
+
+ @Override
+ Attribute touch(Object hint);
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/multipart/DiskAttribute.java
@@ -198,4 +198,10 @@ public Attribute touch() {
super.touch();
return this;
}
+
+ @Override
+ public Attribute touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/multipart/DiskFileUpload.java
@@ -217,4 +217,10 @@ public FileUpload touch() {
super.touch();
return this;
}
+
+ @Override
+ public FileUpload touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
3  codec-http/src/main/java/io/netty/handler/codec/http/multipart/FileUpload.java
@@ -70,4 +70,7 @@
@Override
FileUpload touch();
+
+ @Override
+ FileUpload touch(Object hint);
}
View
3  codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpData.java
@@ -211,4 +211,7 @@
@Override
HttpData touch();
+
+ @Override
+ HttpData touch(Object hint);
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java
@@ -1222,6 +1222,12 @@ public FullHttpRequest touch() {
}
@Override
+ public FullHttpRequest touch(Object hint) {
+ content.touch(hint);
+ return this;
+ }
+
+ @Override
public ByteBuf content() {
return content.content();
}
View
3  codec-http/src/main/java/io/netty/handler/codec/http/multipart/InterfaceHttpData.java
@@ -44,4 +44,7 @@
@Override
InterfaceHttpData touch();
+
+ @Override
+ InterfaceHttpData touch(Object hint);
}
View
8 codec-http/src/main/java/io/netty/handler/codec/http/multipart/InternalAttribute.java
@@ -149,4 +149,12 @@ public InterfaceHttpData touch() {
}
return this;
}
+
+ @Override
+ public InterfaceHttpData touch(Object hint) {
+ for (ByteBuf buf: value) {
+ buf.touch(hint);
+ }
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MemoryAttribute.java
@@ -159,4 +159,10 @@ public Attribute touch() {
super.touch();
return this;
}
+
+ @Override
+ public Attribute touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MemoryFileUpload.java
@@ -177,4 +177,10 @@ public FileUpload touch() {
super.touch();
return this;
}
+
+ @Override
+ public FileUpload touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MixedAttribute.java
@@ -286,6 +286,12 @@ public Attribute touch() {
}
@Override
+ public Attribute touch(Object hint) {
+ attribute.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return attribute.release();
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/multipart/MixedFileUpload.java
@@ -317,6 +317,12 @@ public FileUpload touch() {
}
@Override
+ public FileUpload touch(Object hint) {
+ fileUpload.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return fileUpload.release();
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/BinaryWebSocketFrame.java
@@ -81,4 +81,10 @@ public BinaryWebSocketFrame touch() {
super.touch();
return this;
}
+
+ @Override
+ public BinaryWebSocketFrame touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/CloseWebSocketFrame.java
@@ -165,4 +165,10 @@ public CloseWebSocketFrame touch() {
super.touch();
return this;
}
+
+ @Override
+ public CloseWebSocketFrame touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/ContinuationWebSocketFrame.java
@@ -146,4 +146,10 @@ public ContinuationWebSocketFrame touch() {
super.touch();
return this;
}
+
+ @Override
+ public ContinuationWebSocketFrame touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/PingWebSocketFrame.java
@@ -81,4 +81,10 @@ public PingWebSocketFrame touch() {
super.touch();
return this;
}
+
+ @Override
+ public PingWebSocketFrame touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/PongWebSocketFrame.java
@@ -81,4 +81,10 @@ public PongWebSocketFrame touch() {
super.touch();
return this;
}
+
+ @Override
+ public PongWebSocketFrame touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/TextWebSocketFrame.java
@@ -121,4 +121,10 @@ public TextWebSocketFrame touch() {
super.touch();
return this;
}
+
+ @Override
+ public TextWebSocketFrame touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrame.java
@@ -88,4 +88,10 @@ public WebSocketFrame touch() {
super.touch();
return this;
}
+
+ @Override
+ public WebSocketFrame touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java
@@ -116,6 +116,12 @@ public SpdyDataFrame touch() {
}
@Override
+ public SpdyDataFrame touch(Object hint) {
+ data.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return data.release();
}
View
3  codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyDataFrame.java
@@ -53,4 +53,7 @@
@Override
SpdyDataFrame touch();
+
+ @Override
+ SpdyDataFrame touch(Object hint);
}
View
6 codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultLastMemcacheContent.java
@@ -51,6 +51,12 @@ public LastMemcacheContent touch() {
}
@Override
+ public LastMemcacheContent touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
+
+ @Override
public LastMemcacheContent copy() {
return new DefaultLastMemcacheContent(content().copy());
}
View
6 codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultMemcacheContent.java
@@ -74,6 +74,12 @@ public MemcacheContent touch() {
}
@Override
+ public MemcacheContent touch(Object hint) {
+ content.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return content.release();
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/FullMemcacheMessage.java
@@ -34,5 +34,8 @@
FullMemcacheMessage touch();
@Override
+ FullMemcacheMessage touch(Object hint);
+
+ @Override
FullMemcacheMessage duplicate();
}
View
8 codec-memcache/src/main/java/io/netty/handler/codec/memcache/LastMemcacheContent.java
@@ -51,6 +51,11 @@ public LastMemcacheContent touch() {
}
@Override
+ public LastMemcacheContent touch(Object hint) {
+ return this;
+ }
+
+ @Override
public LastMemcacheContent duplicate() {
return this;
}
@@ -99,5 +104,8 @@ public boolean release(int decrement) {
LastMemcacheContent touch();
@Override
+ LastMemcacheContent touch(Object hint);
+
+ @Override
LastMemcacheContent duplicate();
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheContent.java
@@ -42,4 +42,7 @@
@Override
MemcacheContent touch();
+
+ @Override
+ MemcacheContent touch(Object hint);
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheMessage.java
@@ -36,4 +36,7 @@
@Override
MemcacheMessage touch();
+
+ @Override
+ MemcacheMessage touch(Object hint);
}
View
7 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/AbstractBinaryMemcacheMessage.java
@@ -110,8 +110,13 @@ public boolean release(int decrement) {
@Override
public BinaryMemcacheMessage<H> touch() {
+ return touch(null);
+ }
+
+ @Override
+ public BinaryMemcacheMessage<H> touch(Object hint) {
if (extras != null) {
- extras.touch();
+ extras.touch(hint);
}
return this;
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheMessage.java
@@ -66,4 +66,7 @@
@Override
BinaryMemcacheMessage<H> touch();
+
+ @Override
+ BinaryMemcacheMessage<H> touch(Object hint);
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheRequest.java
@@ -36,4 +36,7 @@
@Override
BinaryMemcacheRequest touch();
+
+ @Override
+ BinaryMemcacheRequest touch(Object hint);
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheResponse.java
@@ -36,4 +36,7 @@
@Override
BinaryMemcacheResponse touch();
+
+ @Override
+ BinaryMemcacheResponse touch(Object hint);
}
View
6 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheRequest.java
@@ -80,4 +80,10 @@ public BinaryMemcacheRequest touch() {
super.touch();
return this;
}
+
+ @Override
+ public BinaryMemcacheRequest touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheResponse.java
@@ -80,4 +80,10 @@ public BinaryMemcacheResponse touch() {
super.touch();
return this;
}
+
+ @Override
+ public BinaryMemcacheResponse touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
6 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultFullBinaryMemcacheRequest.java
@@ -84,6 +84,12 @@ public FullBinaryMemcacheRequest touch() {
}
@Override
+ public FullBinaryMemcacheRequest touch(Object hint) {
+ content.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return content.release();
}
View
6 codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultFullBinaryMemcacheResponse.java
@@ -84,6 +84,12 @@ public FullBinaryMemcacheResponse touch() {
}
@Override
+ public FullBinaryMemcacheResponse touch(Object hint) {
+ content.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
return content.release();
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/FullBinaryMemcacheRequest.java
@@ -35,5 +35,8 @@
FullBinaryMemcacheRequest touch();
@Override
+ FullBinaryMemcacheRequest touch(Object hint);
+
+ @Override
FullBinaryMemcacheRequest duplicate();
}
View
3  codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/FullBinaryMemcacheResponse.java
@@ -35,5 +35,8 @@
FullBinaryMemcacheResponse touch();
@Override
+ FullBinaryMemcacheResponse touch(Object hint);
+
+ @Override
FullBinaryMemcacheResponse duplicate();
}
View
6 codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java
@@ -979,6 +979,12 @@ public ByteBuf touch() {
}
@Override
+ public ByteBuf touch(Object hint) {
+ buffer.touch(hint);
+ return this;
+ }
+
+ @Override
public boolean release() {
reject();
return false;
View
5 common/src/main/java/io/netty/util/AbstractReferenceCounted.java
@@ -102,6 +102,11 @@ public ReferenceCounted retain(int increment) {
}
@Override
+ public ReferenceCounted touch() {
+ return touch(null);
+ }
+
+ @Override
public final boolean release() {
for (;;) {
int refCnt = this.refCnt;
View
13 common/src/main/java/io/netty/util/ReferenceCountUtil.java
@@ -72,6 +72,19 @@
}
/**
+ * Tries to call {@link ReferenceCounted#touch(Object)} if the specified message implements
+ * {@link ReferenceCounted}. If the specified message doesn't implement {@link ReferenceCounted},
+ * this method does nothing.
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T touch(T msg, Object hint) {
+ if (msg instanceof ReferenceCounted) {
+ return (T) ((ReferenceCounted) msg).touch(hint);
+ }
+ return msg;
+ }
+
+ /**
* Try to call {@link ReferenceCounted#release()} if the specified message implements {@link ReferenceCounted}.
* If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing.
*/
View
9 common/src/main/java/io/netty/util/ReferenceCounted.java
@@ -48,11 +48,18 @@
/**
* Records the current access location of this object for debugging purposes.
* If this object is determined to be leaked, the information recorded by this operation will be provided to you
- * via {@link ResourceLeakDetector}.
+ * via {@link ResourceLeakDetector}. This method is a shortcut to {@link #touch(Object) touch(null)}.
*/
ReferenceCounted touch();
/**
+ * Records the current access location of this object with an additonal arbitrary information for debugging
+ * purposes. If this object is determined to be leaked, the information recorded by this operation will be
+ * provided to you via {@link ResourceLeakDetector}.
+ */
+ ReferenceCounted touch(Object hint);
+
+ /**
* Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at
* {@code 0}.
*
View
8 common/src/main/java/io/netty/util/ResourceLeak.java
@@ -19,11 +19,17 @@
public interface ResourceLeak {
/**
* Records the caller's current stack trace so that the {@link ResourceLeakDetector} can tell where the leaked
- * resource was accessed lastly.
+ * resource was accessed lastly. This method is a shortcut to {@link #record(Object) record(null)}.
*/
void record();
/**
+ * Records the caller's current stack trace and the specified additional arbitrary information
+ * so that the {@link ResourceLeakDetector} can tell where the leaked resource was accessed lastly.
+ */
+ void record(Object hint);
+
+ /**
* Close the leak so that {@link ResourceLeakDetector} does not warn about leaked resources.
*
* @return {@code true} if called first time, {@code false} if called already
View
57 common/src/main/java/io/netty/util/ResourceLeakDetector.java
@@ -232,13 +232,13 @@ private void reportLeak(Level level) {
private DefaultResourceLeak prev;
private DefaultResourceLeak next;
- private DefaultResourceLeak(Object referent) {
+ DefaultResourceLeak(Object referent) {
super(referent, referent != null? refQueue : null);
if (referent != null) {
Level level = getLevel();
if (level.ordinal() >= Level.ADVANCED.ordinal()) {
- creationRecord = newRecord();
+ creationRecord = newRecord(null, 3);
} else {
creationRecord = null;
}
@@ -260,8 +260,17 @@ private DefaultResourceLeak(Object referent) {
@Override
public void record() {
+ record0(null, 3);
+ }
+
+ @Override
+ public void record(Object hint) {
+ record0(hint, 3);
+ }
+
+ private void record0(Object hint, int recordsToSkip) {
if (creationRecord != null) {
- String value = newRecord();
+ String value = newRecord(hint, recordsToSkip);
synchronized (lastRecords) {
int size = lastRecords.size();
@@ -325,17 +334,49 @@ public String toString() {
}
}
- private static String newRecord() {
+ private static final String[] STACK_TRACE_ELEMENT_EXCLUSIONS = {
+ "io.netty.util.ReferenceCountUtil.touch(",
+ "io.netty.buffer.AdvancedLeakAwareByteBuf.touch(",
+ "io.netty.buffer.AbstractByteBufAllocator.toLeakAwareBuffer(",
+ };
+
+ static String newRecord(Object hint, int recordsToSkip) {
StringBuilder buf = new StringBuilder(4096);
+
+ // Append the hint first if available.
+ if (hint != null) {
+ buf.append("\tHint: ");
+ // Prefer a hint string to a simple string form.
+ if (hint instanceof ResourceLeakHint) {
+ buf.append(((ResourceLeakHint) hint).toHintString());
+ } else {
+ buf.append(hint);
+ }
+ buf.append(NEWLINE);
+ }
+
+ // Append the stack trace.
StackTraceElement[] array = new Throwable().getStackTrace();
- int recordsToSkip = 3;
for (StackTraceElement e: array) {
if (recordsToSkip > 0) {
recordsToSkip --;
} else {
- buf.append('\t');
- buf.append(e);
- buf.append(NEWLINE);
+ String estr = e.toString();
+
+ // Strip the noisy stack trace elements.
+ boolean excluded = false;
+ for (String exclusion: STACK_TRACE_ELEMENT_EXCLUSIONS) {
+ if (estr.startsWith(exclusion)) {
+ excluded = true;
+ break;
+ }
+ }
+
+ if (!excluded) {
+ buf.append('\t');
+ buf.append(estr);
+ buf.append(NEWLINE);
+ }
}
}
View
27 common/src/main/java/io/netty/util/ResourceLeakHint.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2014 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License,
+ * version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.netty.util;
+
+/**
+ * A hint object that provides human-readable message for easier resource leak tracking.
+ */
+public interface ResourceLeakHint {
+ /**
+ * Returns a human-readable message that potentially enables easier resource leak tracking.
+ */
+ String toHintString();
+}
View
6 transport-sctp/src/main/java/io/netty/channel/sctp/SctpMessage.java
@@ -159,6 +159,12 @@ public SctpMessage touch() {
}
@Override
+ public SctpMessage touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
+
+ @Override
public String toString() {
if (refCnt() == 0) {
return "SctpFrame{" +
View
6 transport-udt/src/main/java/io/netty/channel/udt/UdtMessage.java
@@ -58,4 +58,10 @@ public UdtMessage touch() {
super.touch();
return this;
}
+
+ @Override
+ public UdtMessage touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
12 transport/src/main/java/io/netty/channel/AddressedEnvelope.java
@@ -41,4 +41,16 @@
* Returns the address of the recipient of this message.
*/
A recipient();
+
+ @Override
+ AddressedEnvelope<M, A> retain();
+
+ @Override
+ AddressedEnvelope<M, A> retain(int increment);
+
+ @Override
+ AddressedEnvelope<M, A> touch();
+
+ @Override
+ AddressedEnvelope<M, A> touch(Object hint);
}
View
6 transport/src/main/java/io/netty/channel/DefaultAddressedEnvelope.java
@@ -109,6 +109,12 @@ public boolean release(int decrement) {
}
@Override
+ public AddressedEnvelope<M, A> touch(Object hint) {
+ ReferenceCountUtil.touch(message, hint);
+ return this;
+ }
+
+ @Override
public String toString() {
if (sender != null) {
return StringUtil.simpleClassName(this) +
View
20 transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java
@@ -20,13 +20,15 @@
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import io.netty.util.ReferenceCountUtil;
+import io.netty.util.ResourceLeakHint;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.internal.PlatformDependent;
+import io.netty.util.internal.StringUtil;
import java.net.SocketAddress;
import java.util.WeakHashMap;
-final class DefaultChannelHandlerContext implements ChannelHandlerContext {
+final class DefaultChannelHandlerContext implements ChannelHandlerContext, ResourceLeakHint {
// This class keeps an integer member field 'skipFlags' whose each bit tells if the corresponding handler method
// is annotated with @Skip. 'skipFlags' is retrieved in runtime via the reflection API and is cached.
@@ -323,8 +325,8 @@ public ChannelHandlerContext fireUserEventTriggered(Object event) {
@Override
public ChannelHandlerContext fireChannelRead(Object msg) {
- ReferenceCountUtil.touch(msg);
DefaultChannelHandlerContext next = findContextInbound(MASK_CHANNEL_READ);
+ ReferenceCountUtil.touch(msg, next);
next.invoker.invokeChannelRead(next, msg);
return this;
}
@@ -419,8 +421,8 @@ public ChannelFuture write(Object msg) {
@Override
public ChannelFuture write(Object msg, ChannelPromise promise) {
- ReferenceCountUtil.touch(msg);
DefaultChannelHandlerContext next = findContextOutbound(MASK_WRITE);
+ ReferenceCountUtil.touch(msg, next);
next.invoker.invokeWrite(next, msg, promise);
return promise;
}
@@ -434,9 +436,9 @@ public ChannelHandlerContext flush() {
@Override
public ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) {
- ReferenceCountUtil.touch(msg);
DefaultChannelHandlerContext next;
next = findContextOutbound(MASK_WRITE);
+ ReferenceCountUtil.touch(msg, next);
next.invoker.invokeWrite(next, msg, promise);
next = findContextOutbound(MASK_FLUSH);
next.invoker.invokeFlush(next);
@@ -501,4 +503,14 @@ void setRemoved() {
public boolean isRemoved() {
return removed;
}
+
+ @Override
+ public String toHintString() {
+ return '\'' + name + "' will handle the message from this point.";
+ }
+
+ @Override
+ public String toString() {
+ return StringUtil.simpleClassName(ChannelHandlerContext.class) + '(' + name + ", " + channel + ')';
+ }
}
View
5 transport/src/main/java/io/netty/channel/DefaultFileRegion.java
@@ -121,4 +121,9 @@ public FileRegion retain(int increment) {
public FileRegion touch() {
return this;
}
+
+ @Override
+ public FileRegion touch(Object hint) {
+ return this;
+ }
}
View
3  transport/src/main/java/io/netty/channel/FileRegion.java
@@ -89,4 +89,7 @@
@Override
FileRegion touch();
+
+ @Override
+ FileRegion touch(Object hint);
}
View
6 transport/src/main/java/io/netty/channel/socket/DatagramPacket.java
@@ -69,4 +69,10 @@ public DatagramPacket touch() {
super.touch();
return this;
}
+
+ @Override
+ public DatagramPacket touch(Object hint) {
+ super.touch(hint);
+ return this;
+ }
}
View
2  transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java
@@ -107,7 +107,7 @@ protected void deallocate() {
}
@Override
- public ReferenceCounted touch() {
+ public ReferenceCounted touch(Object hint) {
return this;
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.