Home / Function/ unreserveMatchingBuddy() — netty Function Reference

unreserveMatchingBuddy() — netty Function Reference

Architecture documentation for the unreserveMatchingBuddy() function in AdaptivePoolingAllocator.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  dc83f7d4_74f8_e748_7e3b_3dcd31faa500["unreserveMatchingBuddy()"]
  fbf1f415_2f80_8493_e5fb_f8f9be5f99ee["BuddyChunk"]
  dc83f7d4_74f8_e748_7e3b_3dcd31faa500 -->|defined in| fbf1f415_2f80_8493_e5fb_f8f9be5f99ee
  e96d016e_b4f4_6b32_d223_e56596e9b1f1["accept()"]
  e96d016e_b4f4_6b32_d223_e56596e9b1f1 -->|calls| dc83f7d4_74f8_e748_7e3b_3dcd31faa500
  style dc83f7d4_74f8_e748_7e3b_3dcd31faa500 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java lines 1484–1524

        private boolean unreserveMatchingBuddy(int index, int size, int offset, int currOffset) {
            byte[] buddies = this.buddies;
            if (buddies.length <= index) {
                return false;
            }
            byte buddy = buddies[index];
            int currSize = MIN_BUDDY_SIZE << (buddy & SHIFT_MASK);

            if (currSize == size) {
                // We're at the right size level.
                if (currOffset == offset) {
                    buddies[index] &= SHIFT_MASK;
                    return false;
                }
                throw new IllegalStateException("The intended segment was not found at index " +
                        index + ", for size " + size + " and offset " + offset);
            }

            // We're at a parent size level. Use the target offset to guide our drill-down path.
            boolean claims;
            int siblingIndex;
            if (offset < currOffset + (currSize >> 1)) {
                // Must be down the left path.
                claims = unreserveMatchingBuddy(index << 1, size, offset, currOffset);
                siblingIndex = (index << 1) + 1;
            } else {
                // Must be down the rigth path.
                claims = unreserveMatchingBuddy((index << 1) + 1, size, offset, currOffset + (currSize >> 1));
                siblingIndex = index << 1;
            }
            if (!claims) {
                // No other claims down the path we took. Check if the sibling has claims.
                byte sibling = buddies[siblingIndex];
                if ((sibling & SHIFT_MASK) == sibling) {
                    // No claims in the sibling. We can clear this level as well.
                    buddies[index] &= SHIFT_MASK;
                    return false;
                }
            }
            return true;
        }

Domain

Subdomains

Called By

Frequently Asked Questions

What does unreserveMatchingBuddy() do?
unreserveMatchingBuddy() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java.
Where is unreserveMatchingBuddy() defined?
unreserveMatchingBuddy() is defined in buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java at line 1484.
What calls unreserveMatchingBuddy()?
unreserveMatchingBuddy() is called by 1 function(s): accept.

Analyze Your Own Codebase

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

Try Supermodel Free