Home / Class/ CompletionQueue Class — netty Architecture

CompletionQueue Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613["CompletionQueue"]
  38945a3b_703b_2386_3933_cbb8e5d31f1f["CompletionQueue.java"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|defined in| 38945a3b_703b_2386_3933_cbb8e5d31f1f
  4ec6e1f8_0508_9d31_2201_1d63f5a25670["CompletionQueue()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| 4ec6e1f8_0508_9d31_2201_1d63f5a25670
  b767b858_efff_a352_6364_df74faf324a6["close()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| b767b858_efff_a352_6364_df74faf324a6
  31f72b00_38ec_9fa8_f224_421becc8b06a["flags()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| 31f72b00_38ec_9fa8_f224_421becc8b06a
  94686de2_5848_8ca1_1b8a_c6ea2b6b5041["hasCompletions()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| 94686de2_5848_8ca1_1b8a_c6ea2b6b5041
  4bf21a59_f9a3_cb07_8403_6e3b200caf7b["count()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| 4bf21a59_f9a3_cb07_8403_6e3b200caf7b
  d9b73f6d_bcee_b6c3_41c1_0cc0d26a184d["process()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| d9b73f6d_bcee_b6c3_41c1_0cc0d26a184d
  56b4528e_8092_baf8_d7b9_58c95eb1133f["ByteBuffer()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| 56b4528e_8092_baf8_d7b9_58c95eb1133f
  c107c6b9_e1f7_f089_9609_23bd1c305d58["String()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| c107c6b9_e1f7_f089_9609_23bd1c305d58
  04ea1afd_83d6_fa0b_816d_7f9913fa27ea["cqeIdx()"]
  af6dd3bb_1c78_efaf_ac7c_5f13fef08613 -->|method| 04ea1afd_83d6_fa0b_816d_7f9913fa27ea

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/CompletionQueue.java lines 27–201

final class CompletionQueue {
    private static final VarHandle INT_HANDLE =
            MethodHandles.byteBufferViewVarHandle(int[].class, ByteOrder.nativeOrder());

    //these offsets are used to access specific properties
    //CQE (https://github.com/axboe/liburing/blob/master/src/include/liburing/io_uring.h#L162)
    private static final int CQE_USER_DATA_FIELD = 0;
    private static final int CQE_RES_FIELD = 8;
    private static final int CQE_FLAGS_FIELD = 12;

    //these unsigned integer pointers(shared with the kernel) will be changed by the kernel and us
    // using a VarHandle.
    private final ByteBuffer khead;
    private final ByteBuffer ktail;
    private final ByteBuffer kflags;
    private final ByteBuffer completionQueueArray;
    private final ByteBuffer[] extraCqeData;

    final int ringSize;
    final long ringAddress;
    final int ringFd;
    final int ringEntries;
    final int ringCapacity;
    private final int cqeLength;

    private final int ringMask;
    private int ringHead;
    private boolean closed;

    CompletionQueue(ByteBuffer kHead, ByteBuffer kTail, int ringMask, int ringEntries, ByteBuffer kflags,
                    ByteBuffer completionQueueArray, int ringSize, long ringAddress,
                    int ringFd, int ringCapacity, int cqeLength, boolean extraCqeDataNeeded) {
        this.khead = kHead;
        this.ktail = kTail;
        this.completionQueueArray = completionQueueArray;
        this.ringSize = ringSize;
        this.ringAddress = ringAddress;
        this.ringFd = ringFd;
        this.ringCapacity = ringCapacity;
        this.cqeLength = cqeLength;
        this.ringEntries = ringEntries;
        this.kflags = kflags;
        this.ringMask = ringMask;
        ringHead = (int) INT_HANDLE.getVolatile(kHead, 0);

        if (extraCqeDataNeeded) {
            // Let's create the slices up front to reduce GC-pressure and also ensure that the user
            // can not escape the memory range.
            // We slice every Native.CQE_SIZE to support IORING_SETUP_CQE32 and IORING_SETUP_CQE_MIXED.
            this.extraCqeData = new ByteBuffer[ringEntries];
            for (int i = 0; i < ringEntries; i++) {
                int position = i * cqeLength;
                completionQueueArray.position(position).limit(position + Native.CQE_SIZE);
                extraCqeData[i] = completionQueueArray.slice();
                completionQueueArray.clear();
            }
        } else {
            this.extraCqeData = null;
        }
    }

    void close() {
        closed = true;
    }

    int flags() {
        if (closed) {
            return 0;
        }
        // we only need memory_order_relaxed
        return (int) INT_HANDLE.getOpaque(kflags, 0);
    }

    /**
     * Returns {@code true} if any completion event is ready to be processed by
     * {@link #process(CompletionCallback)}, {@code false} otherwise.
     */
    boolean hasCompletions() {
        return !closed && ringHead != (int) INT_HANDLE.getVolatile(ktail, 0);
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free