Home / Class/ InternalThreadLocalMap Class — netty Architecture

InternalThreadLocalMap Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146["InternalThreadLocalMap"]
  953c61a2_a5c1_78fd_fbe7_eb498de68fd7["InternalThreadLocalMap.java"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|defined in| 953c61a2_a5c1_78fd_fbe7_eb498de68fd7
  128283a5_0567_7bd8_2a1b_5509b8287da8["InternalThreadLocalMap()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| 128283a5_0567_7bd8_2a1b_5509b8287da8
  3353f4a0_76ab_1521_137f_b4d37700f757["remove()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| 3353f4a0_76ab_1521_137f_b4d37700f757
  ea1fb144_1f63_3b7a_d34d_c36ae844c9f0["destroy()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| ea1fb144_1f63_3b7a_d34d_c36ae844c9f0
  64a3a443_69a7_62c8_b6cb_f813141aa05c["nextVariableIndex()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| 64a3a443_69a7_62c8_b6cb_f813141aa05c
  e8a0064a_0ca9_e28f_8c0d_c291dcc15e4e["lastVariableIndex()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| e8a0064a_0ca9_e28f_8c0d_c291dcc15e4e
  ebbe453d_07a7_97aa_af93_c6f54a1a4c37["newIndexedVariableTable()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| ebbe453d_07a7_97aa_af93_c6f54a1a4c37
  932336b9_8efe_0945_c2dd_edb6711bdff8["size()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| 932336b9_8efe_0945_c2dd_edb6711bdff8
  276afa21_355c_7af8_331c_5ed6b7385b75["StringBuilder()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| 276afa21_355c_7af8_331c_5ed6b7385b75
  710fdcd8_da14_ff6e_49b6_a3e86c4648ab["charsetEncoderCache()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| 710fdcd8_da14_ff6e_49b6_a3e86c4648ab
  2c5575cc_eb8e_c9b2_a7b6_0f37cf0a1aa9["charsetDecoderCache()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| 2c5575cc_eb8e_c9b2_a7b6_0f37cf0a1aa9
  a2c4a93b_cee6_8dc3_00a6_288c494d5869["arrayList()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| a2c4a93b_cee6_8dc3_00a6_288c494d5869
  e737214d_82d9_9def_464d_627b2ab17497["futureListenerStackDepth()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| e737214d_82d9_9def_464d_627b2ab17497
  ce0dafdc_5056_188d_2fd0_c81924b971ff["setFutureListenerStackDepth()"]
  d6ca0ae0_1399_e584_fef6_bfc2f1e3e146 -->|method| ce0dafdc_5056_188d_2fd0_c81924b971ff

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/InternalThreadLocalMap.java lines 41–393

public final class InternalThreadLocalMap extends UnpaddedInternalThreadLocalMap {
    private static final ThreadLocal<InternalThreadLocalMap> slowThreadLocalMap =
            new ThreadLocal<InternalThreadLocalMap>();
    private static final AtomicInteger nextIndex = new AtomicInteger();
    // Internal use only.
    public static final int VARIABLES_TO_REMOVE_INDEX = nextVariableIndex();

    private static final int DEFAULT_ARRAY_LIST_INITIAL_CAPACITY = 8;
    private static final int ARRAY_LIST_CAPACITY_EXPAND_THRESHOLD = 1 << 30;
    // Reference: https://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/util/ArrayList.java#l229
    private static final int ARRAY_LIST_CAPACITY_MAX_SIZE = Integer.MAX_VALUE - 8;

    private static final int HANDLER_SHARABLE_CACHE_INITIAL_CAPACITY = 4;
    private static final int INDEXED_VARIABLE_TABLE_INITIAL_SIZE = 32;

    private static final int STRING_BUILDER_INITIAL_SIZE;
    private static final int STRING_BUILDER_MAX_SIZE;

    private static final InternalLogger logger;
    /** Internal use only. */
    public static final Object UNSET = new Object();

    /** Used by {@link FastThreadLocal} */
    private Object[] indexedVariables;

    // Core thread-locals
    private int futureListenerStackDepth;
    private int localChannelReaderStackDepth;
    private Map<Class<?>, Boolean> handlerSharableCache;
    private Map<Class<?>, TypeParameterMatcher> typeParameterMatcherGetCache;
    private Map<Class<?>, Map<String, TypeParameterMatcher>> typeParameterMatcherFindCache;

    // String-related thread-locals
    private StringBuilder stringBuilder;
    private Map<Charset, CharsetEncoder> charsetEncoderCache;
    private Map<Charset, CharsetDecoder> charsetDecoderCache;

    // ArrayList-related thread-locals
    private ArrayList<Object> arrayList;

    private BitSet cleanerFlags;

    /** @deprecated These padding fields will be removed in the future. */
    public long rp1, rp2, rp3, rp4, rp5, rp6, rp7, rp8;

    static {
        STRING_BUILDER_INITIAL_SIZE =
                SystemPropertyUtil.getInt("io.netty.threadLocalMap.stringBuilder.initialSize", 1024);
        STRING_BUILDER_MAX_SIZE =
                SystemPropertyUtil.getInt("io.netty.threadLocalMap.stringBuilder.maxSize", 1024 * 4);

        // Ensure the InternalLogger is initialized as last field in this class as InternalThreadLocalMap might be used
        // by the InternalLogger itself. For this its important that all the other static fields are correctly
        // initialized.
        //
        // See https://github.com/netty/netty/issues/12931.
        logger = InternalLoggerFactory.getInstance(InternalThreadLocalMap.class);
        logger.debug("-Dio.netty.threadLocalMap.stringBuilder.initialSize: {}", STRING_BUILDER_INITIAL_SIZE);
        logger.debug("-Dio.netty.threadLocalMap.stringBuilder.maxSize: {}", STRING_BUILDER_MAX_SIZE);
    }

    public static InternalThreadLocalMap getIfSet() {
        Thread thread = Thread.currentThread();
        if (thread instanceof FastThreadLocalThread) {
            return ((FastThreadLocalThread) thread).threadLocalMap();
        }
        return slowThreadLocalMap.get();
    }

    public static InternalThreadLocalMap get() {
        Thread thread = Thread.currentThread();
        if (thread instanceof FastThreadLocalThread) {
            return fastGet((FastThreadLocalThread) thread);
        } else {
            return slowGet();
        }
    }

    private static InternalThreadLocalMap fastGet(FastThreadLocalThread thread) {
        InternalThreadLocalMap threadLocalMap = thread.threadLocalMap();
        if (threadLocalMap == null) {

Frequently Asked Questions

What is the InternalThreadLocalMap class?
InternalThreadLocalMap is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/InternalThreadLocalMap.java.
Where is InternalThreadLocalMap defined?
InternalThreadLocalMap is defined in common/src/main/java/io/netty/util/internal/InternalThreadLocalMap.java at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free