Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit d40989d

Browse files
committed
Add toString implementations to all Drop implementations
This is helpful when debugging.
1 parent 0ccb34c commit d40989d

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

src/main/java/io/netty/buffer/api/CleanerPooledDrop.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public void attach(Buffer buf) {
6464
cleanable = new GatedCleanable(gate, CLEANER.register(this, new CleanAction(pool, mem, ref, gate)));
6565
}
6666

67+
@Override
68+
public String toString() {
69+
return "CleanerPooledDrop(" + delegate + ')';
70+
}
71+
6772
private static final class CleanAction implements Runnable {
6873
private final SizeClassedMemoryPool pool;
6974
private final Object mem;

src/main/java/io/netty/buffer/api/CompositeBuffer.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ final class CompositeBuffer extends RcSupport<Buffer, CompositeBuffer> implement
3131
* non-composite copy of the buffer.
3232
*/
3333
private static final int MAX_CAPACITY = Integer.MAX_VALUE - 8;
34-
private static final Drop<CompositeBuffer> COMPOSITE_DROP = buf -> {
35-
for (Buffer b : buf.bufs) {
36-
b.close();
34+
private static final Drop<CompositeBuffer> COMPOSITE_DROP = new Drop<CompositeBuffer>() {
35+
@Override
36+
public void drop(CompositeBuffer buf) {
37+
for (Buffer b : buf.bufs) {
38+
b.close();
39+
}
40+
buf.makeInaccessible();
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "COMPOSITE_DROP";
3746
}
38-
buf.makeInaccessible();
3947
};
4048

4149
private final BufferAllocator allocator;

src/main/java/io/netty/buffer/api/SizeClassedMemoryPool.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ public void drop(Buffer buf) {
105105
}
106106
}
107107

108+
@Override
109+
public String toString() {
110+
return "SizeClassedMemoryPool";
111+
}
112+
108113
@Override
109114
public Object allocateUntethered(Buffer originator, int size) {
110115
var sizeClassPool = getSizeClassPool(size);

src/main/java/io/netty/buffer/api/Statics.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121

2222
interface Statics {
2323
Cleaner CLEANER = Cleaner.create();
24-
Drop<Buffer> NO_OP_DROP = buf -> {
24+
Drop<Buffer> NO_OP_DROP = new Drop<Buffer>() {
25+
@Override
26+
public void drop(Buffer obj) {
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return "NO_OP_DROP";
32+
}
2533
};
2634

2735
static VarHandle findVarHandle(Lookup lookup, Class<?> recv, String name, Class<?> type) {

src/main/java/io/netty/buffer/api/memseg/ArcDrop.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ Drop<MemSegBuffer> unwrap() {
9494
return delegate;
9595
}
9696

97+
@Override
98+
public String toString() {
99+
StringBuilder builder = new StringBuilder().append("ArcDrop(").append(count).append(", ");
100+
Drop<MemSegBuffer> drop = this;
101+
while ((drop = ((ArcDrop) drop).unwrap()) instanceof ArcDrop) {
102+
builder.append(((ArcDrop) drop).count).append(", ");
103+
}
104+
return builder.append(drop).append(')').toString();
105+
}
106+
97107
private static void checkValidState(int count) {
98108
if (count == 0) {
99109
throw new IllegalStateException("Underlying resources have already been freed.");

src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ class MemSegBuffer extends RcSupport<Buffer, MemSegBuffer> implements Buffer, Re
5858
static {
5959
CLOSED_SEGMENT = MemorySegment.ofArray(new byte[0]);
6060
CLOSED_SEGMENT.close();
61-
SEGMENT_CLOSE = buf -> {
62-
buf.base.close();
61+
SEGMENT_CLOSE = new Drop<MemSegBuffer>() {
62+
@Override
63+
public void drop(MemSegBuffer buf) {
64+
buf.base.close();
65+
}
66+
67+
@Override
68+
public String toString() {
69+
return "SEGMENT_CLOSE";
70+
}
6371
};
6472
}
6573

@@ -100,6 +108,11 @@ public void drop(MemSegBuffer buf) {
100108
public void attach(MemSegBuffer buf) {
101109
delegate.attach(buf);
102110
}
111+
112+
@Override
113+
public String toString() {
114+
return "MemSegDrop(" + delegate + ')';
115+
}
103116
}
104117

105118
@Override

0 commit comments

Comments
 (0)