< prev index next >

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

Print this page
rev 49550 : 8201179: Regression due loading java.nio.charset.StandardCharsets during bootstrap
Reviewed-by: sherman

@@ -32,35 +32,41 @@
  * @see <a href="Charset.html#standard">Standard Charsets</a>
  * @since 1.7
  */
 public final class StandardCharsets {
 
+    // To avoid accidental eager initialization of often unused Charsets
+    // from happening while the VM is booting up, which may delay
+    // initialization of VM components, we should generally avoid depending
+    // on this class from elsewhere in java.base.
+
     private StandardCharsets() {
         throw new AssertionError("No java.nio.charset.StandardCharsets instances for you!");
     }
+
     /**
      * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the
      * Unicode character set
      */
-    public static final Charset US_ASCII = new sun.nio.cs.US_ASCII();
+    public static final Charset US_ASCII = sun.nio.cs.US_ASCII.INSTANCE;
     /**
      * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
      */
-    public static final Charset ISO_8859_1 = new sun.nio.cs.ISO_8859_1();
+    public static final Charset ISO_8859_1 = sun.nio.cs.ISO_8859_1.INSTANCE;
     /**
      * Eight-bit UCS Transformation Format
      */
-    public static final Charset UTF_8 = new sun.nio.cs.UTF_8();
+    public static final Charset UTF_8 = sun.nio.cs.UTF_8.INSTANCE;
     /**
      * Sixteen-bit UCS Transformation Format, big-endian byte order
      */
-    public static final Charset UTF_16BE = new sun.nio.cs.UTF_16BE();
+    public static final Charset UTF_16BE = sun.nio.cs.UTF_16BE.INSTANCE;
     /**
      * Sixteen-bit UCS Transformation Format, little-endian byte order
      */
-    public static final Charset UTF_16LE = new sun.nio.cs.UTF_16LE();
+    public static final Charset UTF_16LE = sun.nio.cs.UTF_16LE.INSTANCE;
     /**
      * Sixteen-bit UCS Transformation Format, byte order identified by an
      * optional byte-order mark
      */
-    public static final Charset UTF_16 = new sun.nio.cs.UTF_16();
+    public static final Charset UTF_16 = sun.nio.cs.UTF_16.INSTANCE;
 }
< prev index next >