< prev index next >

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

Print this page
@@ -35,16 +35,19 @@
  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.access.foreign.MemorySegmentProxy;
  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;

@@ -73,12 +76,11 @@
       * jdk.nio.maxCachedBufferSize property. Even though
       * ByteBuffer.capacity() returns an int, we're using a long here
       * for potential future-proofing.
       */
      private static long getMaxCachedBufferSize() {
-         String s = GetPropertyAction
-                 .privilegedGetProperty("jdk.nio.maxCachedBufferSize");
+         String s = GetPropertyAction.privilegedGetProperty("jdk.nio.maxCachedBufferSize");
          if (s != null) {
              try {
                  long m = Long.parseLong(s);
                  if (m >= 0) {
                      return m;

@@ -226,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

@@ -253,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;
              }

@@ -290,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);
          }
      }

@@ -312,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 >