< prev index next >

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

Print this page
*** 24,12 ***
   */
  
  package sun.nio.ch;
  
  import java.nio.ByteBuffer;
- import jdk.internal.ref.CleanerFactory;
  
  
  /**
   * Manipulates a native array of iovec structs on Solaris:
   *
   * <pre> {@code
--- 24,14 ---
   */
  
  package sun.nio.ch;
  
  import java.nio.ByteBuffer;
  
+ import jdk.internal.access.JavaLangAccess;
+ import jdk.internal.access.SharedSecrets;
+ import jdk.internal.ref.CleanerFactory;
  
  /**
   * Manipulates a native array of iovec structs on Solaris:
   *
   * <pre> {@code

*** 42,10 ***
--- 44,11 ---
   * @author Mike McCloskey
   * @since 1.4
   */
  
  class IOVecWrapper {
+     private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
  
      // Miscellaneous constants
      private static final int BASE_OFFSET = 0;
      private static final int LEN_OFFSET;
      private static final int SIZE_IOVEC;

*** 79,12 ***
              obj.free();
          }
      }
  
      // per thread IOVecWrapper
!     private static final ThreadLocal<IOVecWrapper> cached =
-         new ThreadLocal<IOVecWrapper>();
  
      private IOVecWrapper(int size) {
          this.size      = size;
          this.buf       = new ByteBuffer[size];
          this.position  = new int[size];
--- 82,11 ---
              obj.free();
          }
      }
  
      // per thread IOVecWrapper
!     private static final ThreadLocal<IOVecWrapper> cached = new ThreadLocal<>();
  
      private IOVecWrapper(int size) {
          this.size      = size;
          this.buf       = new ByteBuffer[size];
          this.position  = new int[size];

*** 93,20 ***
          this.vecArray  = new AllocatedNativeObject(size * SIZE_IOVEC, false);
          this.address   = vecArray.address();
      }
  
      static IOVecWrapper get(int size) {
!         IOVecWrapper wrapper = cached.get();
          if (wrapper != null && wrapper.size < size) {
              // not big enough; eagerly release memory
              wrapper.vecArray.free();
              wrapper = null;
          }
          if (wrapper == null) {
              wrapper = new IOVecWrapper(size);
              CleanerFactory.cleaner().register(wrapper, new Deallocator(wrapper.vecArray));
!             cached.set(wrapper);
          }
          return wrapper;
      }
  
      void setBuffer(int i, ByteBuffer buf, int pos, int rem) {
--- 95,20 ---
          this.vecArray  = new AllocatedNativeObject(size * SIZE_IOVEC, false);
          this.address   = vecArray.address();
      }
  
      static IOVecWrapper get(int size) {
!         IOVecWrapper wrapper = JLA.getCarrierThreadLocal(cached);
          if (wrapper != null && wrapper.size < size) {
              // not big enough; eagerly release memory
              wrapper.vecArray.free();
              wrapper = null;
          }
          if (wrapper == null) {
              wrapper = new IOVecWrapper(size);
              CleanerFactory.cleaner().register(wrapper, new Deallocator(wrapper.vecArray));
!             JLA.setCarrierThreadLocal(cached, wrapper);
          }
          return wrapper;
      }
  
      void setBuffer(int i, ByteBuffer buf, int pos, int rem) {
< prev index next >