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"); } }