Home / Function/ free() — netty Function Reference

free() — netty Function Reference

Architecture documentation for the free() function in PoolChunk.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  0cda7768_6ec2_f223_9f8e_7ab81f365adf["free()"]
  271be16e_fb25_9fe6_0749_cf5dd80dd903["PoolChunk"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|defined in| 271be16e_fb25_9fe6_0749_cf5dd80dd903
  84c148a2_d160_9465_4de0_96875dcb9627["isSubpage()"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|calls| 84c148a2_d160_9465_4de0_96875dcb9627
  22016f68_b853_63ea_32c8_c288b8996440["runOffset()"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|calls| 22016f68_b853_63ea_32c8_c288b8996440
  4dbb9d2f_2923_9ae7_8fb1_1280438fa050["bitmapIdx()"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|calls| 4dbb9d2f_2923_9ae7_8fb1_1280438fa050
  1bdfe3f7_3884_814f_0eb6_924b6a843c79["runSize()"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|calls| 1bdfe3f7_3884_814f_0eb6_924b6a843c79
  ef3c5aae_1376_7df3_1784_9bef85c2d5a9["collapseRuns()"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|calls| ef3c5aae_1376_7df3_1784_9bef85c2d5a9
  9adde7b9_78be_7351_d13f_4b1e178b71e5["insertAvailRun()"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|calls| 9adde7b9_78be_7351_d13f_4b1e178b71e5
  dc13ebd8_c529_7ebf_35cc_4cc9171ec3d6["runPages()"]
  0cda7768_6ec2_f223_9f8e_7ab81f365adf -->|calls| dc13ebd8_c529_7ebf_35cc_4cc9171ec3d6
  style 0cda7768_6ec2_f223_9f8e_7ab81f365adf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/PoolChunk.java lines 500–546

    void free(long handle, int normCapacity, ByteBuffer nioBuffer) {
        if (isSubpage(handle)) {
            int sIdx = runOffset(handle);
            PoolSubpage<T> subpage = subpages[sIdx];
            assert subpage != null;
            PoolSubpage<T> head = subpage.chunk.arena.smallSubpagePools[subpage.headIndex];
            // Obtain the head of the PoolSubPage pool that is owned by the PoolArena and synchronize on it.
            // This is need as we may add it back and so alter the linked-list structure.
            head.lock();
            try {
                assert subpage.doNotDestroy;
                if (subpage.free(head, bitmapIdx(handle))) {
                    //the subpage is still used, do not free it
                    return;
                }
                assert !subpage.doNotDestroy;
                // Null out slot in the array as it was freed and we should not use it anymore.
                subpages[sIdx] = null;
            } finally {
                head.unlock();
            }
        }

        int runSize = runSize(pageShifts, handle);
        //start free run
        runsAvailLock.lock();
        try {
            // collapse continuous runs, successfully collapsed runs
            // will be removed from runsAvail and runsAvailMap
            long finalRun = collapseRuns(handle);

            //set run as not used
            finalRun &= ~(1L << IS_USED_SHIFT);
            //if it is a subpage, set it to run
            finalRun &= ~(1L << IS_SUBPAGE_SHIFT);

            insertAvailRun(runOffset(finalRun), runPages(finalRun), finalRun);
            freeBytes += runSize;
        } finally {
            runsAvailLock.unlock();
        }

        if (nioBuffer != null && cachedNioBuffers != null &&
            cachedNioBuffers.size() < PooledByteBufAllocator.DEFAULT_MAX_CACHED_BYTEBUFFERS_PER_CHUNK) {
            cachedNioBuffers.offer(nioBuffer);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does free() do?
free() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/PoolChunk.java.
Where is free() defined?
free() is defined in buffer/src/main/java/io/netty/buffer/PoolChunk.java at line 500.
What does free() call?
free() calls 7 function(s): bitmapIdx, collapseRuns, insertAvailRun, isSubpage, runOffset, runPages, runSize.

Analyze Your Own Codebase

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

Try Supermodel Free