Add toString implementations to all Drop implementations

This is helpful when debugging.
This commit is contained in:
Chris Vest 2021-03-16 17:20:12 +01:00
parent 0ccb34ca08
commit d40989da78
6 changed files with 56 additions and 7 deletions

View File

@ -64,6 +64,11 @@ class CleanerPooledDrop implements Drop<Buffer> {
cleanable = new GatedCleanable(gate, CLEANER.register(this, new CleanAction(pool, mem, ref, gate)));
}
@Override
public String toString() {
return "CleanerPooledDrop(" + delegate + ')';
}
private static final class CleanAction implements Runnable {
private final SizeClassedMemoryPool pool;
private final Object mem;

View File

@ -31,11 +31,19 @@ final class CompositeBuffer extends RcSupport<Buffer, CompositeBuffer> implement
* non-composite copy of the buffer.
*/
private static final int MAX_CAPACITY = Integer.MAX_VALUE - 8;
private static final Drop<CompositeBuffer> COMPOSITE_DROP = buf -> {
for (Buffer b : buf.bufs) {
b.close();
private static final Drop<CompositeBuffer> COMPOSITE_DROP = new Drop<CompositeBuffer>() {
@Override
public void drop(CompositeBuffer buf) {
for (Buffer b : buf.bufs) {
b.close();
}
buf.makeInaccessible();
}
@Override
public String toString() {
return "COMPOSITE_DROP";
}
buf.makeInaccessible();
};
private final BufferAllocator allocator;

View File

@ -105,6 +105,11 @@ class SizeClassedMemoryPool implements BufferAllocator, AllocatorControl, Drop<B
}
}
@Override
public String toString() {
return "SizeClassedMemoryPool";
}
@Override
public Object allocateUntethered(Buffer originator, int size) {
var sizeClassPool = getSizeClassPool(size);

View File

@ -21,7 +21,15 @@ import java.lang.ref.Cleaner;
interface Statics {
Cleaner CLEANER = Cleaner.create();
Drop<Buffer> NO_OP_DROP = buf -> {
Drop<Buffer> NO_OP_DROP = new Drop<Buffer>() {
@Override
public void drop(Buffer obj) {
}
@Override
public String toString() {
return "NO_OP_DROP";
}
};
static VarHandle findVarHandle(Lookup lookup, Class<?> recv, String name, Class<?> type) {

View File

@ -94,6 +94,16 @@ final class ArcDrop implements Drop<MemSegBuffer> {
return delegate;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder().append("ArcDrop(").append(count).append(", ");
Drop<MemSegBuffer> drop = this;
while ((drop = ((ArcDrop) drop).unwrap()) instanceof ArcDrop) {
builder.append(((ArcDrop) drop).count).append(", ");
}
return builder.append(drop).append(')').toString();
}
private static void checkValidState(int count) {
if (count == 0) {
throw new IllegalStateException("Underlying resources have already been freed.");

View File

@ -58,8 +58,16 @@ class MemSegBuffer extends RcSupport<Buffer, MemSegBuffer> implements Buffer, Re
static {
CLOSED_SEGMENT = MemorySegment.ofArray(new byte[0]);
CLOSED_SEGMENT.close();
SEGMENT_CLOSE = buf -> {
buf.base.close();
SEGMENT_CLOSE = new Drop<MemSegBuffer>() {
@Override
public void drop(MemSegBuffer buf) {
buf.base.close();
}
@Override
public String toString() {
return "SEGMENT_CLOSE";
}
};
}
@ -100,6 +108,11 @@ class MemSegBuffer extends RcSupport<Buffer, MemSegBuffer> implements Buffer, Re
public void attach(MemSegBuffer buf) {
delegate.attach(buf);
}
@Override
public String toString() {
return "MemSegDrop(" + delegate + ')';
}
}
@Override