Home / Function/ pinnedMemoryMustReflectBuffersInUse() — netty Function Reference

pinnedMemoryMustReflectBuffersInUse() — netty Function Reference

Architecture documentation for the pinnedMemoryMustReflectBuffersInUse() function in PooledByteBufAllocatorTest.java from the netty codebase.

Function java Buffer Allocators calls 2 called by 2

Entity Profile

Dependency Diagram

graph TD
  08211f11_bee4_3bd9_dbd8_90a0bc23c18e["pinnedMemoryMustReflectBuffersInUse()"]
  f8855572_2abf_1bf6_a32b_5cf6d1cf4947["PooledByteBufAllocatorTest"]
  08211f11_bee4_3bd9_dbd8_90a0bc23c18e -->|defined in| f8855572_2abf_1bf6_a32b_5cf6d1cf4947
  88d8db73_a509_61ad_67d2_9752469827b3["pinnedMemoryMustReflectBuffersInUseWithThreadLocalCaching()"]
  88d8db73_a509_61ad_67d2_9752469827b3 -->|calls| 08211f11_bee4_3bd9_dbd8_90a0bc23c18e
  0177ba94_808b_6a70_9fd3_395a4a2f05f9["pinnedMemoryMustReflectBuffersInUseWithoutThreadLocalCaching()"]
  0177ba94_808b_6a70_9fd3_395a4a2f05f9 -->|calls| 08211f11_bee4_3bd9_dbd8_90a0bc23c18e
  4e681469_9c14_67cb_5890_46b5d4b12dd2["PooledByteBufAllocator()"]
  08211f11_bee4_3bd9_dbd8_90a0bc23c18e -->|calls| 4e681469_9c14_67cb_5890_46b5d4b12dd2
  02a85fe5_dcd6_3be9_7157_1b2137312b9e["usedMemory()"]
  08211f11_bee4_3bd9_dbd8_90a0bc23c18e -->|calls| 02a85fe5_dcd6_3be9_7157_1b2137312b9e
  style 08211f11_bee4_3bd9_dbd8_90a0bc23c18e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java lines 871–930

    private static void pinnedMemoryMustReflectBuffersInUse(boolean useThreadLocalCaching) {
        int smallCacheSize;
        int normalCacheSize;
        if (useThreadLocalCaching) {
            smallCacheSize = PooledByteBufAllocator.defaultSmallCacheSize();
            normalCacheSize = PooledByteBufAllocator.defaultNormalCacheSize();
        } else {
            smallCacheSize = 0;
            normalCacheSize = 0;
        }
        int directMemoryCacheAlignment = 0;
        PooledByteBufAllocator alloc = new PooledByteBufAllocator(
                PooledByteBufAllocator.defaultPreferDirect(),
                1,
                1,
                PooledByteBufAllocator.defaultPageSize(),
                PooledByteBufAllocator.defaultMaxOrder(),
                smallCacheSize,
                normalCacheSize,
                useThreadLocalCaching,
                directMemoryCacheAlignment);
        PooledByteBufAllocatorMetric metric = alloc.metric();
        AtomicLong capSum = new AtomicLong();

        for (long index = 0; index < 10000; index++) {
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            int bufCount = rnd.nextInt(1, 100);
            List<ByteBuf> buffers = new ArrayList<ByteBuf>(bufCount);

            if (index % 2 == 0) {
                // ensure that we allocate a small buffer
                for (int i = 0; i < bufCount; i++) {
                    ByteBuf buf = alloc.directBuffer(rnd.nextInt(8, 128));
                    buffers.add(buf);
                    capSum.addAndGet(buf.capacity());
                }
            } else {
                // allocate a larger buffer
                for (int i = 0; i < bufCount; i++) {
                    ByteBuf buf = alloc.directBuffer(rnd.nextInt(1024, 1024 * 100));
                    buffers.add(buf);
                    capSum.addAndGet(buf.capacity());
                }
            }

            if (index % 100 == 0) {
                long used = usedMemory(metric.directArenas());
                long pinned = alloc.pinnedDirectMemory();
                assertThat(capSum.get()).isLessThanOrEqualTo(pinned);
                assertThat(pinned).isLessThanOrEqualTo(used);
            }

            for (ByteBuf buffer : buffers) {
                buffer.release();
            }
            capSum.set(0);
            // After releasing all buffers, pinned memory must be zero
            assertThat(alloc.pinnedDirectMemory()).isZero();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does pinnedMemoryMustReflectBuffersInUse() do?
pinnedMemoryMustReflectBuffersInUse() is a function in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java.
Where is pinnedMemoryMustReflectBuffersInUse() defined?
pinnedMemoryMustReflectBuffersInUse() is defined in buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java at line 871.
What does pinnedMemoryMustReflectBuffersInUse() call?
pinnedMemoryMustReflectBuffersInUse() calls 2 function(s): PooledByteBufAllocator, usedMemory.
What calls pinnedMemoryMustReflectBuffersInUse()?
pinnedMemoryMustReflectBuffersInUse() is called by 2 function(s): pinnedMemoryMustReflectBuffersInUseWithThreadLocalCaching, pinnedMemoryMustReflectBuffersInUseWithoutThreadLocalCaching.

Analyze Your Own Codebase

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

Try Supermodel Free