JDK-8296754 : AutoCreateSharedArchive in JDK 20 is not compatible with JDK 19
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-11-10
  • Updated: 2022-12-05
  • Resolved: 2022-11-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 b26Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
The -XX:+AutoCreateSharedArchive  flag was implemented in JDK 19 (JDK-8261455). However, this flag doesn't work across JDK 19 and 20.

Expected: JDK 20 should recreate the specified CDS archive
Actual: JDK 20 cannot recognize the archive file and gives up

$ rm foo.jsa

$ ./jdk-19/bin/java -XX:+AutoCreateSharedArchive -XX:SharedArchiveFile=foo.jsa -cp HelloWorld.jar HelloWorld
Hello World

$ ls -l foo.jsa
-r--r--r-- 1 iklam iklam 241664 Nov  9 17:58 foo.jsa

$ java -showversion -Xlog:cds -XX:+AutoCreateSharedArchive -XX:SharedArchiveFile=foo.jsa -cp HelloWorld.jar HelloWorld
[0.000s][info][cds] UseSharedSpaces: The shared archive file version 0xe does not match the required version 0x11.
[0.000s][info][cds] UseSharedSpaces: Invalid base_archive_name offset/size: 0/527052459
Java HotSpot(TM) 64-Bit Server VM warning: -XX:+AutoCreateSharedArchive is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info.
[0.000s][info][cds] Unable to use shared archive: invalid archive
java version "20-internal" 2023-03-21
Java(TM) SE Runtime Environment (build 20-internal-adhoc.iklam.rum)
Java HotSpot(TM) 64-Bit Server VM (build 20-internal-adhoc.iklam.rum, mixed mode)
Hello World

Comments
Changeset: a249a525 Author: Matias Saavedra Silva <matsaave@openjdk.org> Committer: Ioi Lam <iklam@openjdk.org> Date: 2022-11-28 15:26:27 +0000 URL: https://git.openjdk.org/jdk/commit/a249a52501f3cd7d4fbe5293d14ac8d0d6ffcc69
28-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/11148 Date: 2022-11-14 21:33:23 +0000
15-11-2022

When -XX:+AutoCreateSharedArchive -XX:SharedArchiveFile=foo.jsa is specified: - If the JVM can recognize the format of foo.jsa, and found out that it's out of date, the archive is re-generated - If the JVM canNOT recognize the format of foo.jsa, it leaves foo.jsa, without overwriting it. The intention is to avoid overwriting important files that are unintentionally specified, e.g., -XX:SharedArchiveFile=key-to-bitcoin-locker ==== For the archive file to be recognizable across different versions of JDK, we require that the GenericCDSFileMapHeader must be always the same in different JDK versions. https://github.com/openjdk/jdk/blob/3a873d3c5b2281b2389e9364ff26f04ee86b0607/src/hotspot/share/include/cds.h#L67-L88 However, this requirement was broken by JDK-8279366 when a new field was added in there. The fix is to move this new field from GenericCDSFileMapHeader (in cds.h) to FileMapHeader (in filemap.hpp)
10-11-2022