GeezerVison is showing github.com — Adaptive: Only use ThreadLocal if called from FastThreadLocalThread i… · netty/netty@4d1f98d
File tree
Expand file treeCollapse file tree
Open diff view settings
buffer/src/main/java/io/netty/buffer
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/ByteBufUtil.java +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
22 | 22 | import io.netty.util.Recycler.EnhancedHandle; |
23 | 23 | import io.netty.util.ResourceLeakDetector; |
24 | 24 | import io.netty.util.concurrent.FastThreadLocal; |
| 25 | +import io.netty.util.concurrent.FastThreadLocalThread; |
25 | 26 | import io.netty.util.internal.MathUtil; |
26 | 27 | import io.netty.util.internal.ObjectPool; |
27 | 28 | import io.netty.util.internal.ObjectPool.Handle; |
|
45 | 46 | import java.nio.charset.CoderResult; |
46 | 47 | import java.nio.charset.CodingErrorAction; |
47 | 48 | import java.util.Arrays; |
48 | | -import java.util.Locale; |
49 | 49 |
|
50 | 50 | import static io.netty.util.internal.MathUtil.isOutOfBounds; |
51 | 51 | import static io.netty.util.internal.ObjectUtil.checkNotNull; |
@@ -110,8 +110,13 @@ protected byte[] initialValue() throws Exception { |
110 | 110 | * Allocates a new array if minLength > {@link ByteBufUtil#MAX_TL_ARRAY_LEN} |
111 | 111 | */ |
112 | 112 | static byte[] threadLocalTempArray(int minLength) { |
113 | | - return minLength <= MAX_TL_ARRAY_LEN ? BYTE_ARRAYS.get() |
114 | | - : PlatformDependent.allocateUninitializedArray(minLength); |
| 113 | + // Only make use of ThreadLocal if we use a FastThreadLocalThread to make the implementation |
| 114 | + // Virtual Thread friendly. |
| 115 | + // See https://github.com/netty/netty/issues/14609 |
| 116 | + if (minLength <= MAX_TL_ARRAY_LEN && Thread.currentThread() instanceof FastThreadLocalThread) { |
| 117 | + return BYTE_ARRAYS.get(); |
| 118 | + } |
| 119 | + return PlatformDependent.allocateUninitializedArray(minLength); |
115 | 120 | } |
116 | 121 |
|
117 | 122 | /** |
|