View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty.util.internal;
18  
19  import io.netty.util.concurrent.FastThreadLocal;
20  
21  import java.nio.charset.Charset;
22  import java.nio.charset.CharsetDecoder;
23  import java.nio.charset.CharsetEncoder;
24  import java.util.Map;
25  import java.util.concurrent.atomic.AtomicInteger;
26  
27  /**
28   * The internal data structure that stores the thread-local variables for Netty and all {@link FastThreadLocal}s.
29   * Note that this class is for internal use only and is subject to change at any time.  Use {@link FastThreadLocal}
30   * unless you know what you are doing.
31   */
32  class UnpaddedInternalThreadLocalMap {
33  
34      static ThreadLocal<InternalThreadLocalMap> slowThreadLocalMap;
35      static final AtomicInteger nextIndex = new AtomicInteger();
36  
37      /** Used by {@link FastThreadLocal} */
38      Object[] indexedVariables;
39  
40      // Core thread-locals
41      int futureListenerStackDepth;
42      int localChannelReaderStackDepth;
43      Map<Class<?>, Boolean> handlerSharableCache;
44      IntegerHolder counterHashCode;
45      ThreadLocalRandom random;
46      Map<Class<?>, TypeParameterMatcher> typeParameterMatcherGetCache;
47      Map<Class<?>, Map<String, TypeParameterMatcher>> typeParameterMatcherFindCache;
48  
49      // String-related thread-locals
50      StringBuilder stringBuilder;
51      Map<Charset, CharsetEncoder> charsetEncoderCache;
52      Map<Charset, CharsetDecoder> charsetDecoderCache;
53  
54      UnpaddedInternalThreadLocalMap(Object[] indexedVariables) {
55          this.indexedVariables = indexedVariables;
56      }
57  }