< prev index next >

src/java.base/share/classes/java/util/jar/Attributes.java

Print this page
rev 54134 : 8214712: Archive Attributes$Name.KNOWN_NAMES
Reviewed-by: alanb, jiangli

@@ -32,10 +32,12 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 
+import jdk.internal.misc.VM;
+import jdk.internal.vm.annotation.Stable;
 import sun.util.logging.PlatformLogger;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
 /**

@@ -452,11 +454,11 @@
         private final int hashCode;
 
         /**
          * Avoid allocation for common Names
          */
-        private static final Map<String, Name> KNOWN_NAMES;
+        private static @Stable Map<String, Name> KNOWN_NAMES;
 
         static final Name of(String name) {
             Name n = KNOWN_NAMES.get(name);
             if (n != null) {
                 return n;

@@ -539,138 +541,161 @@
          * manifest attribute. This attribute indicates the version number
          * of the manifest standard to which a JAR file's manifest conforms.
          * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
          *      Manifest and Signature Specification</a>
          */
-        public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
+        public static final Name MANIFEST_VERSION;
 
         /**
          * {@code Name} object for {@code Signature-Version}
          * manifest attribute used when signing JAR files.
          * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
          *      Manifest and Signature Specification</a>
          */
-        public static final Name SIGNATURE_VERSION = new Name("Signature-Version");
+        public static final Name SIGNATURE_VERSION;
 
         /**
          * {@code Name} object for {@code Content-Type}
          * manifest attribute.
          */
-        public static final Name CONTENT_TYPE = new Name("Content-Type");
+        public static final Name CONTENT_TYPE;
 
         /**
          * {@code Name} object for {@code Class-Path}
          * manifest attribute.
          * @see <a href="{@docRoot}/../specs/jar/jar.html#class-path-attribute">
          *      JAR file specification</a>
          */
-        public static final Name CLASS_PATH = new Name("Class-Path");
+        public static final Name CLASS_PATH;
 
         /**
          * {@code Name} object for {@code Main-Class} manifest
          * attribute used for launching applications packaged in JAR files.
          * The {@code Main-Class} attribute is used in conjunction
          * with the {@code -jar} command-line option of the
          * {@code java} application launcher.
          */
-        public static final Name MAIN_CLASS = new Name("Main-Class");
+        public static final Name MAIN_CLASS;
 
         /**
          * {@code Name} object for {@code Sealed} manifest attribute
          * used for sealing.
          * @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
          *      Package Sealing</a>
          */
-        public static final Name SEALED = new Name("Sealed");
+        public static final Name SEALED;
 
         /**
          * {@code Name} object for {@code Extension-List} manifest attribute
          * used for the extension mechanism that is no longer supported.
          */
-        public static final Name EXTENSION_LIST = new Name("Extension-List");
+        public static final Name EXTENSION_LIST;
 
         /**
          * {@code Name} object for {@code Extension-Name} manifest attribute.
          * used for the extension mechanism that is no longer supported.
          */
-        public static final Name EXTENSION_NAME = new Name("Extension-Name");
+        public static final Name EXTENSION_NAME;
 
         /**
          * {@code Name} object for {@code Extension-Installation} manifest attribute.
          *
          * @deprecated Extension mechanism is no longer supported.
          */
         @Deprecated
-        public static final Name EXTENSION_INSTALLATION = new Name("Extension-Installation");
+        public static final Name EXTENSION_INSTALLATION;
 
         /**
          * {@code Name} object for {@code Implementation-Title}
          * manifest attribute used for package versioning.
          */
-        public static final Name IMPLEMENTATION_TITLE = new Name("Implementation-Title");
+        public static final Name IMPLEMENTATION_TITLE;
 
         /**
          * {@code Name} object for {@code Implementation-Version}
          * manifest attribute used for package versioning.
          */
-        public static final Name IMPLEMENTATION_VERSION = new Name("Implementation-Version");
+        public static final Name IMPLEMENTATION_VERSION;
 
         /**
          * {@code Name} object for {@code Implementation-Vendor}
          * manifest attribute used for package versioning.
          */
-        public static final Name IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor");
+        public static final Name IMPLEMENTATION_VENDOR;
 
         /**
          * {@code Name} object for {@code Implementation-Vendor-Id}
          * manifest attribute.
          *
          * @deprecated Extension mechanism is no longer supported.
          */
         @Deprecated
-        public static final Name IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");
+        public static final Name IMPLEMENTATION_VENDOR_ID;
 
         /**
          * {@code Name} object for {@code Implementation-URL}
          * manifest attribute.
          *
          * @deprecated Extension mechanism is no longer supported.
          */
         @Deprecated
-        public static final Name IMPLEMENTATION_URL = new Name("Implementation-URL");
+        public static final Name IMPLEMENTATION_URL;
 
         /**
          * {@code Name} object for {@code Specification-Title}
          * manifest attribute used for package versioning.
          */
-        public static final Name SPECIFICATION_TITLE = new Name("Specification-Title");
+        public static final Name SPECIFICATION_TITLE;
 
         /**
          * {@code Name} object for {@code Specification-Version}
          * manifest attribute used for package versioning.
          */
-        public static final Name SPECIFICATION_VERSION = new Name("Specification-Version");
+        public static final Name SPECIFICATION_VERSION;
 
         /**
          * {@code Name} object for {@code Specification-Vendor}
          * manifest attribute used for package versioning.
          */
-        public static final Name SPECIFICATION_VENDOR = new Name("Specification-Vendor");
+        public static final Name SPECIFICATION_VENDOR;
 
         /**
          * {@code Name} object for {@code Multi-Release}
          * manifest attribute that indicates this is a multi-release JAR file.
          *
          * @since   9
          */
-        public static final Name MULTI_RELEASE = new Name("Multi-Release");
+        public static final Name MULTI_RELEASE;
 
         private static void addName(Map<String, Name> names, Name name) {
             names.put(name.name, name);
         }
 
         static {
+
+            VM.initializeFromArchive(Attributes.Name.class);
+
+            if (KNOWN_NAMES == null) {
+                MANIFEST_VERSION = new Name("Manifest-Version");
+                SIGNATURE_VERSION = new Name("Signature-Version");
+                CONTENT_TYPE = new Name("Content-Type");
+                CLASS_PATH = new Name("Class-Path");
+                MAIN_CLASS = new Name("Main-Class");
+                SEALED = new Name("Sealed");
+                EXTENSION_LIST = new Name("Extension-List");
+                EXTENSION_NAME = new Name("Extension-Name");
+                EXTENSION_INSTALLATION = new Name("Extension-Installation");
+                IMPLEMENTATION_TITLE = new Name("Implementation-Title");
+                IMPLEMENTATION_VERSION = new Name("Implementation-Version");
+                IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor");
+                IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");
+                IMPLEMENTATION_URL = new Name("Implementation-URL");
+                SPECIFICATION_TITLE = new Name("Specification-Title");
+                SPECIFICATION_VERSION = new Name("Specification-Version");
+                SPECIFICATION_VENDOR = new Name("Specification-Vendor");
+                MULTI_RELEASE = new Name("Multi-Release");
+
             var names = new HashMap<String, Name>(64);
             addName(names, MANIFEST_VERSION);
             addName(names, SIGNATURE_VERSION);
             addName(names, CONTENT_TYPE);
             addName(names, CLASS_PATH);

@@ -687,31 +712,43 @@
             addName(names, MULTI_RELEASE);
 
             // Common attributes used in MANIFEST.MF et.al; adding these has a
             // small footprint cost, but is likely to be quickly paid for by
             // reducing allocation when reading and parsing typical manifests
+
+                // JDK internal attributes
             addName(names, new Name("Add-Exports"));
             addName(names, new Name("Add-Opens"));
-            addName(names, new Name("Ant-Version"));
-            addName(names, new Name("Archiver-Version"));
-            addName(names, new Name("Build-Jdk"));
-            addName(names, new Name("Built-By"));
-            addName(names, new Name("Bnd-LastModified"));
-            addName(names, new Name("Bundle-Description"));
-            addName(names, new Name("Bundle-DocURL"));
-            addName(names, new Name("Bundle-License"));
-            addName(names, new Name("Bundle-ManifestVersion"));
-            addName(names, new Name("Bundle-Name"));
-            addName(names, new Name("Bundle-Vendor"));
-            addName(names, new Name("Bundle-Version"));
-            addName(names, new Name("Bundle-SymbolicName"));
-            addName(names, new Name("Created-By"));
-            addName(names, new Name("Export-Package"));
-            addName(names, new Name("Import-Package"));
+                // LauncherHelper attributes
+                addName(names, new Name("Launcher-Agent-Class"));
+                addName(names, new Name("JavaFX-Application-Class"));
+                // jarsigner attributes
             addName(names, new Name("Name"));
+                addName(names, new Name("Created-By"));
             addName(names, new Name("SHA1-Digest"));
-            addName(names, new Name("X-Compile-Source-JDK"));
-            addName(names, new Name("X-Compile-Target-JDK"));
-            KNOWN_NAMES = names;
+                addName(names, new Name("SHA-256-Digest"));
+                KNOWN_NAMES = Map.copyOf(names);
+            } else {
+                // Even if KNOWN_NAMES was read from archive, we still need
+                // to initialize the public constants
+                MANIFEST_VERSION = KNOWN_NAMES.get("Manifest-Version");
+                SIGNATURE_VERSION = KNOWN_NAMES.get("Signature-Version");
+                CONTENT_TYPE = KNOWN_NAMES.get("Content-Type");
+                CLASS_PATH = KNOWN_NAMES.get("Class-Path");
+                MAIN_CLASS = KNOWN_NAMES.get("Main-Class");
+                SEALED = KNOWN_NAMES.get("Sealed");
+                EXTENSION_LIST = KNOWN_NAMES.get("Extension-List");
+                EXTENSION_NAME = KNOWN_NAMES.get("Extension-Name");
+                EXTENSION_INSTALLATION = KNOWN_NAMES.get("Extension-Installation");
+                IMPLEMENTATION_TITLE = KNOWN_NAMES.get("Implementation-Title");
+                IMPLEMENTATION_VERSION = KNOWN_NAMES.get("Implementation-Version");
+                IMPLEMENTATION_VENDOR = KNOWN_NAMES.get("Implementation-Vendor");
+                IMPLEMENTATION_VENDOR_ID = KNOWN_NAMES.get("Implementation-Vendor-Id");
+                IMPLEMENTATION_URL = KNOWN_NAMES.get("Implementation-URL");
+                SPECIFICATION_TITLE = KNOWN_NAMES.get("Specification-Title");
+                SPECIFICATION_VERSION = KNOWN_NAMES.get("Specification-Version");
+                SPECIFICATION_VENDOR = KNOWN_NAMES.get("Specification-Vendor");
+                MULTI_RELEASE = KNOWN_NAMES.get("Multi-Release");
+            }
         }
     }
 }
< prev index next >