JDK-8261455 : Automatically generate the CDS archive if necessary
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-02-09
  • Updated: 2022-12-19
  • Resolved: 2022-01-13
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 19
19 b06Fixed
Related Reports
Blocks :  
CSR :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8273853 :  
JDK-8288376 :  
Description
Currently, you must explicitly create the CDS archive before using it (with -Xshare:dump or -XX:ArchiveClassesAtExit).

For example, a program needs to be started by a script like this:

if test ! -f foo.jsa; then
  java -XX:ArchiveClassesAtExit=foo.jsa -cp foo.jar Foo
else
  java -XX:ShareArchiveFile=foo.jsa -cp foo.jar Foo
fi

However, even this won't handle the case when you upgrade your JDK. So the script will need to do JDK version checking as well. This makes it inconvenient to use CDS.

To improve usability, we should allow the CDS archive to be automatically generated if necessary (e.g., if the specified archive doesn't exist, or if it's out of date because you have updated the JDK).

Perhaps we can have a new JVM options like this:

java -XX:+AutoCreateSharedArchive -XX:SharedArchiveFile=foo.jsa -cp foo.jar Foo

If foo.jsa doesn't exist, or if it was generated for a different version of the JDK, DynamicDumpSharedSpaces will be enabled automatically, and foo.jsa will be created when the Java process exits. When the app is launched again, it will be able to use foo.jsa.

This can be built on top of the facilities added by JDK-8259070.
Comments
Changeset: 1228b2f1 Author: Yumin Qi <minqi@openjdk.org> Date: 2022-01-13 00:23:05 +0000 URL: https://git.openjdk.java.net/jdk/commit/1228b2f1f8737a363ab6a7065b24e9f972441b27
13-01-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/6920 Date: 2021-12-23 00:22:54 +0000
23-12-2021

The JDK-8259070 implementation used the existing DynamicArchive::dump to dump the shared archive. Here we do not need call into java (CDS.dumpSharedArchive) to generate archive. If want to create dynamic archive at exit automatically (-XX:+AutoCreateSharedArchive), what we need to do: 1) At vm args parsing stage, set RecordDynamicDumpInfo so the class info of classes which are to be loaded be recorded. 2) At app exit call DynamicArchive::dump(const char*, TRAPS).
19-07-2021