Home / Class/ IoUringBufferRing Class — netty Architecture

IoUringBufferRing Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f317c5ef_c638_0e8e_3895_73aa2a88fdad["IoUringBufferRing"]
  5d4aee7d_36d0_49fe_12b4_659d1b69d7b2["IoUringBufferRing.java"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|defined in| 5d4aee7d_36d0_49fe_12b4_659d1b69d7b2
  a2179240_8e02_3c1f_f055_16f3c94f7339["IoUringBufferRing()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| a2179240_8e02_3c1f_f055_16f3c94f7339
  75e14d25_5866_d84f_1513_c4b4e38d4a5f["isUsable()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| 75e14d25_5866_d84f_1513_c4b4e38d4a5f
  576641a8_9ec2_1ba1_bd3c_0c4c7428e020["initialize()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| 576641a8_9ec2_1ba1_bd3c_0c4c7428e020
  8ba7f24e_27ea_7439_d80e_dee6cd7097da["expand()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| 8ba7f24e_27ea_7439_d80e_dee6cd7097da
  d66ab72f_36b1_f061_59f8_5e5807458880["fill()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| d66ab72f_36b1_f061_59f8_5e5807458880
  f9974b69_9bd4_1480_eb91_1ae92b4b366e["IoUringBufferRingExhaustedEvent()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| f9974b69_9bd4_1480_eb91_1ae92b4b366e
  f7b8a564_0673_e0f1_5572_ee168eb52064["attemptedBytesRead()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| f7b8a564_0673_e0f1_5572_ee168eb52064
  87db609e_20fd_3805_6364_ac492e213003["calculateNextBufferBatch()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| 87db609e_20fd_3805_6364_ac492e213003
  7239275a_8363_2f7a_8f34_d001615b1b74["ByteBuf()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| 7239275a_8363_2f7a_8f34_d001615b1b74
  bd01e258_896e_89a8_ff5d_a62913790642["nextBid()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| bd01e258_896e_89a8_ff5d_a62913790642
  f443b13f_acf6_77d8_a3ed_a2f406932f29["bufferGroupId()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| f443b13f_acf6_77d8_a3ed_a2f406932f29
  cb0557ed_6a1f_a599_3812_be5d52d1b2db["close()"]
  f317c5ef_c638_0e8e_3895_73aa2a88fdad -->|method| cb0557ed_6a1f_a599_3812_be5d52d1b2db

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringBufferRing.java lines 28–296

final class IoUringBufferRing {
    private static final VarHandle SHORT_HANDLE =
            MethodHandles.byteBufferViewVarHandle(short[].class, ByteOrder.nativeOrder());
    private final ByteBuffer ioUringBufRing;
    private final int tailFieldPosition;
    private final short entries;
    private final short mask;
    private final short bufferGroupId;
    private final int ringFd;
    private final ByteBuf[] buffers;
    private final IoUringBufferRingAllocator allocator;
    private final boolean batchAllocation;
    private final IoUringBufferRingExhaustedEvent exhaustedEvent;
    private final RingConsumer ringConsumer;
    private final boolean incremental;
    private final int batchSize;
    private boolean corrupted;
    private boolean closed;
    private int usableBuffers;
    private int allocatedBuffers;
    private boolean needExpand;
    private short lastGeneratedBid;

    IoUringBufferRing(int ringFd, ByteBuffer ioUringBufRing,
                      short entries, int batchSize, short bufferGroupId, boolean incremental,
                      IoUringBufferRingAllocator allocator, boolean batchAllocation) {
        assert entries % 2 == 0;
        assert batchSize % 2 == 0;
        this.batchSize = batchSize;
        this.ioUringBufRing = ioUringBufRing;
        this.tailFieldPosition = Native.IO_URING_BUFFER_RING_TAIL;
        this.entries = entries;
        this.mask = (short) (entries - 1);
        this.bufferGroupId = bufferGroupId;
        this.ringFd = ringFd;
        this.buffers = new ByteBuf[entries];
        this.incremental = incremental;
        this.allocator = allocator;
        this.batchAllocation = batchAllocation;
        this.ringConsumer  = new RingConsumer();
        this.exhaustedEvent = new IoUringBufferRingExhaustedEvent(bufferGroupId);
    }

    boolean isUsable() {
        return !closed && !corrupted;
    }

    void initialize() {
        // We already validated that batchSize is <= ring length.
        fill((short) 0, batchSize);
        allocatedBuffers = batchSize;
    }

    private final class RingConsumer implements Consumer<ByteBuf> {
        private int expectedBuffers;
        private short num;
        private short bid;
        private short oldTail;

        short fill(short startBid, int numBuffers) {
            // Fetch the tail once before allocate the batch.
            oldTail = (short) SHORT_HANDLE.get(ioUringBufRing, tailFieldPosition);

            // At the moment we always start with bid 0 and so num and bid is the same. As this is more of an
            // implementation detail it is better to still keep both separated.
            this.num = 0;
            this.bid = startBid;
            this.expectedBuffers = numBuffers;
            try {
                if (batchAllocation) {
                    allocator.allocateBatch(this, numBuffers);
                } else {
                    for (int i = 0; i < numBuffers; i++) {
                        add(oldTail, bid++, num++, allocator.allocate());
                    }
                }
            } catch (Throwable t) {
                corrupted = true;
                for (int i = 0; i < buffers.length; i++) {
                    ByteBuf buffer = buffers[i];
                    if (buffer != null) {

Frequently Asked Questions

What is the IoUringBufferRing class?
IoUringBufferRing is a class in the netty codebase, defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringBufferRing.java.
Where is IoUringBufferRing defined?
IoUringBufferRing is defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringBufferRing.java at line 28.

Analyze Your Own Codebase

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

Try Supermodel Free