< prev index next >

src/java.base/share/classes/java/nio/charset/Charset.java

Print this page
*** 23,10 ***
--- 23,11 ---
   * questions.
   */
  
  package java.nio.charset;
  
+ import jdk.internal.misc.Gate;
  import jdk.internal.misc.VM;
  import sun.nio.cs.ThreadLocalCoders;
  import sun.security.action.GetPropertyAction;
  
  import java.nio.ByteBuffer;

*** 368,13 ***
                  }
  
              };
      }
  
!     // Thread-local gate to prevent recursive provider lookups
!     private static ThreadLocal<ThreadLocal<?>> gate =
!             new ThreadLocal<ThreadLocal<?>>();
  
      @SuppressWarnings("removal")
      private static Charset lookupViaProviders(final String charsetName) {
  
          // The runtime startup sequence looks up standard charsets as a
--- 369,18 ---
                  }
  
              };
      }
  
!     // gate to prevent recursive provider lookups
!     private static class Holder {
!         static final Gate LOOKUP_GATE = Gate.create();
+     }
+ 
+     private static Gate gate() {
+         return Holder.LOOKUP_GATE;
+     }
  
      @SuppressWarnings("removal")
      private static Charset lookupViaProviders(final String charsetName) {
  
          // The runtime startup sequence looks up standard charsets as a

*** 386,16 ***
          // information.
          //
          if (!VM.isBooted())
              return null;
  
!         if (gate.get() != null)
              // Avoid recursive provider lookups
              return null;
          try {
-             gate.set(gate);
- 
              return AccessController.doPrivileged(
                  new PrivilegedAction<>() {
                      public Charset run() {
                          for (Iterator<CharsetProvider> i = providers();
                               i.hasNext();) {
--- 392,14 ---
          // information.
          //
          if (!VM.isBooted())
              return null;
  
!         if (!gate().tryEnter())
              // Avoid recursive provider lookups
              return null;
          try {
              return AccessController.doPrivileged(
                  new PrivilegedAction<>() {
                      public Charset run() {
                          for (Iterator<CharsetProvider> i = providers();
                               i.hasNext();) {

*** 407,11 ***
                          return null;
                      }
                  });
  
          } finally {
!             gate.set(null);
          }
      }
  
      /* The extended set of charsets */
      private static class ExtendedProviderHolder {
--- 411,11 ---
                          return null;
                      }
                  });
  
          } finally {
!             gate().exit();
          }
      }
  
      /* The extended set of charsets */
      private static class ExtendedProviderHolder {
< prev index next >