< prev index next >

src/java.base/share/classes/sun/nio/ch/Util.java

Print this page

        

@@ -35,15 +35,18 @@
 import java.security.PrivilegedAction;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Set;
 
+import jdk.internal.access.JavaLangAccess;
+import jdk.internal.access.SharedSecrets;
 import jdk.internal.misc.TerminatingThreadLocal;
 import jdk.internal.misc.Unsafe;
 import sun.security.action.GetPropertyAction;
 
 public class Util {
+    private static JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
 
     // -- Caches --
 
     // The number of temp buffers in our pool
     private static final int TEMP_BUF_POOL_SIZE = IOUtil.IOV_MAX;

@@ -225,11 +228,11 @@
         // below) given that we won't put the new buffer in the cache.
         if (isBufferTooLarge(size)) {
             return ByteBuffer.allocateDirect(size);
         }
 
-        BufferCache cache = bufferCache.get();
+        BufferCache cache = JLA.getCarrierThreadLocal(bufferCache);
         ByteBuffer buf = cache.get(size);
         if (buf != null) {
             return buf;
         } else {
             // No suitable buffer in the cache so we need to allocate a new

@@ -252,11 +255,11 @@
         if (isBufferTooLarge(size)) {
             return ByteBuffer.allocateDirect(size + alignment - 1)
                     .alignedSlice(alignment);
         }
 
-        BufferCache cache = bufferCache.get();
+        BufferCache cache = JLA.getCarrierThreadLocal(bufferCache);
         ByteBuffer buf = cache.get(size);
         if (buf != null) {
             if (buf.alignmentOffset(0, alignment) == 0) {
                 return buf;
             }

@@ -289,11 +292,11 @@
             free(buf);
             return;
         }
 
         assert buf != null;
-        BufferCache cache = bufferCache.get();
+        BufferCache cache = JLA.getCarrierThreadLocal(bufferCache);
         if (!cache.offerFirst(buf)) {
             // cache is full
             free(buf);
         }
     }

@@ -311,11 +314,11 @@
             free(buf);
             return;
         }
 
         assert buf != null;
-        BufferCache cache = bufferCache.get();
+        BufferCache cache = JLA.getCarrierThreadLocal(bufferCache);
         if (!cache.offerLast(buf)) {
             // cache is full
             free(buf);
         }
     }
< prev index next >