Home / Class/ ConcurrentSkipListChunkCache Class — netty Architecture

ConcurrentSkipListChunkCache Class — netty Architecture

Architecture documentation for the ConcurrentSkipListChunkCache class in AdaptivePoolingAllocator.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  ce074796_a915_3e8e_0b02_6bb0f820ea3e["ConcurrentSkipListChunkCache"]
  fee3fa6d_a7fb_30d6_ea34_49602c633a2c["AdaptivePoolingAllocator.java"]
  ce074796_a915_3e8e_0b02_6bb0f820ea3e -->|defined in| fee3fa6d_a7fb_30d6_ea34_49602c633a2c
  5a2e6e6c_2713_d2a1_873d_04611a4d1c9e["ConcurrentSkipListChunkCache()"]
  ce074796_a915_3e8e_0b02_6bb0f820ea3e -->|method| 5a2e6e6c_2713_d2a1_873d_04611a4d1c9e
  8edf4271_5ef6_204f_a88c_f516a308944f["Chunk()"]
  ce074796_a915_3e8e_0b02_6bb0f820ea3e -->|method| 8edf4271_5ef6_204f_a88c_f516a308944f
  8581bfb7_29e0_ba76_9f0e_87d86c459049["offerChunk()"]
  ce074796_a915_3e8e_0b02_6bb0f820ea3e -->|method| 8581bfb7_29e0_ba76_9f0e_87d86c459049

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java lines 556–642

    private static final class ConcurrentSkipListChunkCache implements ChunkCache {
        private final ConcurrentSkipListIntObjMultimap<Chunk> chunks;

        private ConcurrentSkipListChunkCache() {
            chunks = new ConcurrentSkipListIntObjMultimap<>(-1);
        }

        @Override
        public Chunk pollChunk(int size) {
            if (chunks.isEmpty()) {
                return null;
            }
            IntEntry<Chunk> entry = chunks.pollCeilingEntry(size);
            if (entry != null) {
                Chunk chunk = entry.getValue();
                if (chunk.hasUnprocessedFreelistEntries()) {
                    chunk.processFreelistEntries();
                }
                return chunk;
            }

            Chunk bestChunk = null;
            int bestRemainingCapacity = 0;
            Iterator<IntEntry<Chunk>> itr = chunks.iterator();
            while (itr.hasNext()) {
                entry = itr.next();
                final Chunk chunk;
                if (entry != null && (chunk = entry.getValue()).hasUnprocessedFreelistEntries()) {
                    if (!chunks.remove(entry.getKey(), entry.getValue())) {
                        continue;
                    }
                    chunk.processFreelistEntries();
                    int remainingCapacity = chunk.remainingCapacity();
                    if (remainingCapacity >= size &&
                            (bestChunk == null || remainingCapacity > bestRemainingCapacity)) {
                        if (bestChunk != null) {
                            chunks.put(bestRemainingCapacity, bestChunk);
                        }
                        bestChunk = chunk;
                        bestRemainingCapacity = remainingCapacity;
                    } else {
                        chunks.put(remainingCapacity, chunk);
                    }
                }
            }

            return bestChunk;
        }

        @Override
        public boolean offerChunk(Chunk chunk) {
            chunks.put(chunk.remainingCapacity(), chunk);

            int size = chunks.size();
            while (size > CHUNK_REUSE_QUEUE) {
                // Deallocate the chunk with the fewest incoming references.
                int key = -1;
                Chunk toDeallocate = null;
                for (IntEntry<Chunk> entry : chunks) {
                    Chunk candidate = entry.getValue();
                    if (candidate != null) {
                        if (toDeallocate == null) {
                            toDeallocate = candidate;
                            key = entry.getKey();
                        } else {
                            int candidateRefCnt = RefCnt.refCnt(candidate.refCnt);
                            int toDeallocateRefCnt = RefCnt.refCnt(toDeallocate.refCnt);
                            if (candidateRefCnt < toDeallocateRefCnt ||
                                    candidateRefCnt == toDeallocateRefCnt &&
                                            candidate.capacity() < toDeallocate.capacity()) {
                                toDeallocate = candidate;
                                key = entry.getKey();
                            }
                        }
                    }
                }
                if (toDeallocate == null) {
                    break;
                }
                if (chunks.remove(key, toDeallocate)) {
                    toDeallocate.release();

Frequently Asked Questions

What is the ConcurrentSkipListChunkCache class?
ConcurrentSkipListChunkCache is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java.
Where is ConcurrentSkipListChunkCache defined?
ConcurrentSkipListChunkCache is defined in buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java at line 556.

Analyze Your Own Codebase

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

Try Supermodel Free