Home / Class/ UnpooledUnsafeDirectByteBuf Class — netty Architecture

UnpooledUnsafeDirectByteBuf Class — netty Architecture

Architecture documentation for the UnpooledUnsafeDirectByteBuf class in UnpooledUnsafeDirectByteBuf.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9f14a290_800b_9471_7875_152ee8d088b6["UnpooledUnsafeDirectByteBuf"]
  498ec813_b05a_59ce_1123_ac567f19e651["UnpooledUnsafeDirectByteBuf.java"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|defined in| 498ec813_b05a_59ce_1123_ac567f19e651
  48faaead_7130_156c_c8b2_4084ff9a5585["UnpooledUnsafeDirectByteBuf()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| 48faaead_7130_156c_c8b2_4084ff9a5585
  a27712e5_4050_abfc_8907_0a87e20ec75c["setByteBuffer()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| a27712e5_4050_abfc_8907_0a87e20ec75c
  ac533839_addc_00f1_319b_9e9dd4ad3cdc["hasMemoryAddress()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| ac533839_addc_00f1_319b_9e9dd4ad3cdc
  1e5b552a_62d3_f0a9_c031_6ce6256f68c8["memoryAddress()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| 1e5b552a_62d3_f0a9_c031_6ce6256f68c8
  eea359e2_03ff_da71_2069_1700ba0bc562["getByte()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| eea359e2_03ff_da71_2069_1700ba0bc562
  18d18ebe_f955_a14d_8124_8e70fc17ce21["_getByte()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| 18d18ebe_f955_a14d_8124_8e70fc17ce21
  0ff6ef30_7bbe_6967_cf1e_736cb6ec851a["getShort()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| 0ff6ef30_7bbe_6967_cf1e_736cb6ec851a
  50496980_8eab_dba8_248d_f480e591cd32["_getShort()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| 50496980_8eab_dba8_248d_f480e591cd32
  a4bac381_5837_efe6_eb07_96002f094648["_getShortLE()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| a4bac381_5837_efe6_eb07_96002f094648
  ef494150_4810_f41e_52b3_671c08857a27["getUnsignedMedium()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| ef494150_4810_f41e_52b3_671c08857a27
  e503e4d7_a581_8fcc_70c5_99031e87ee63["_getUnsignedMedium()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| e503e4d7_a581_8fcc_70c5_99031e87ee63
  6ca97f95_6b54_bfd8_5419_6c7fa0499748["_getUnsignedMediumLE()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| 6ca97f95_6b54_bfd8_5419_6c7fa0499748
  3deb84e3_b71b_29f4_9a9a_3bd0f0e989cd["getInt()"]
  9f14a290_800b_9471_7875_152ee8d088b6 -->|method| 3deb84e3_b71b_29f4_9a9a_3bd0f0e989cd

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java lines 32–342

public class UnpooledUnsafeDirectByteBuf extends UnpooledDirectByteBuf {

    long memoryAddress;

    /**
     * Creates a new direct buffer.
     *
     * @param initialCapacity the initial capacity of the underlying direct buffer
     * @param maxCapacity     the maximum capacity of the underlying direct buffer
     */
    public UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
        super(alloc, initialCapacity, maxCapacity);
    }

    /**
     * Creates a new direct buffer by wrapping the specified initial buffer.
     *
     * @param maxCapacity the maximum capacity of the underlying direct buffer
     */
    protected UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity) {
        // We never try to free the buffer if it was provided by the end-user as we don't know if this is a duplicate or
        // a slice. This is done to prevent an IllegalArgumentException when using Java9 as Unsafe.invokeCleaner(...)
        // will check if the given buffer is either a duplicate or slice and in this case throw an
        // IllegalArgumentException.
        //
        // See https://hg.openjdk.java.net/jdk9/hs-demo/jdk/file/0d2ab72ba600/src/jdk.unsupported/share/classes/
        // sun/misc/Unsafe.java#l1250
        //
        // We also call slice() explicitly here to preserve behaviour with previous netty releases.
        super(alloc, initialBuffer, maxCapacity, /* doFree = */ false, /* slice = */ true);
    }

    /**
     * Creates a new direct ByteBuf by wrapping the specified initial buffer.
     * Allows subclasses to control if initialBuffer.slice() should be invoked.
     *
     *  Attention: this is a dangerous API and should only be used by someone
     *  who really knows the possible consequences.
     *  It allows to disable a protective slicing for the provided ByteBuffer instance
     *  and can cause sharing of this ByteBuffer instance between several UnpooledUnsafeDirectByteBuf objects,
     *  as a result modifications would be racy and unsafe.
     *
     * @param slice true means slice() should be called for the provided initialBuffer
     * @param maxCapacity the maximum capacity of the underlying direct buffer
     */
    @UnstableApi
    protected UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, boolean slice,
                                          ByteBuffer initialBuffer, int maxCapacity) {
        super(alloc, initialBuffer, maxCapacity, /* doFree = */ false, slice);
    }

    UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity, boolean doFree) {
        super(alloc, initialBuffer, maxCapacity, doFree, false);
    }

    @Override
    final void setByteBuffer(ByteBuffer buffer, boolean tryFree) {
        super.setByteBuffer(buffer, tryFree);
        memoryAddress = PlatformDependent.directBufferAddress(buffer);
    }

    @Override
    final void setByteBuffer(CleanableDirectBuffer cleanableDirectBuffer, boolean tryFree) {
        super.setByteBuffer(cleanableDirectBuffer, tryFree);
        memoryAddress = PlatformDependent.directBufferAddress(cleanableDirectBuffer.buffer());
    }

    @Override
    public boolean hasMemoryAddress() {
        return true;
    }

    @Override
    public long memoryAddress() {
        ensureAccessible();
        return memoryAddress;
    }

    @Override
    public byte getByte(int index) {
        checkIndex(index);

Frequently Asked Questions

What is the UnpooledUnsafeDirectByteBuf class?
UnpooledUnsafeDirectByteBuf is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java.
Where is UnpooledUnsafeDirectByteBuf defined?
UnpooledUnsafeDirectByteBuf is defined in buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java at line 32.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free