Files
javademos/unsafe-migration/tools/NettyProbe.java
T
2026-11-06 21:43:48 +05:30

16 lines
780 B
Java

import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.util.internal.PlatformDependent;
/** A real third-party library that uses Unsafe: allocate one direct Netty buffer and use it. Compile and run with netty-common + netty-buffer on the class path. */
public class NettyProbe {
public static void main(String[] args) {
System.out.println("netty sees Unsafe: " + PlatformDependent.hasUnsafe());
ByteBuf buf = UnpooledByteBufAllocator.DEFAULT.directBuffer(16);
buf.writeLong(0xCAFEBABEL);
System.out.println("direct=" + buf.isDirect() + " hasMemoryAddress=" + buf.hasMemoryAddress() + " readLong=" + Long.toHexString(buf.readLong()));
buf.release();
System.out.println("done");
}
}