Class Data Sharing
There are two related CDS features:
- CDS caches preprocessed JVM class metadata on-disk to improve startup performance and reduce memory footprint.
- AppCDS extends CDS with support for application classes.
Where the archive is stored depends on the platform:
- Linux and macOS:
During start up the JVM memory maps the file to allow sharing read-only JVM metadata across multiple JVM processes.
-Xsharesets the CDS mode:
dumpis used during the JVM build process to create CDS archives to ship with a distribution. By default this will generate an archive containing a predefined subset of Java classes, as defined in
autocauses the JVM to use shared class data if available, and is the default.
onRequires use of shared class data, failing otherwise. Use only for testing purposes.
offprevents usage of shared class data.
-XX:SharedArchiveFilespecifies the path to the CDS shared archive file.
- CDS is supported with the ZGC, G1, Parallel, and Serial collectors.
- Shared Java object heaps are supported only with the G1 collector on 64-bit, non-Windows platforms.
You can generate a dynamic CDS archive using the default archive as a base:
[class,load] $className source: shared objects filefor classes loaded from the CDS archive.
Prior to SE 13 it was necessary to manually assemble and specify, using
-XX:SharedClassListFile, a list of classes to include in the CDS archive:
java \ -XX:DumpLoadedClassList=app-classlist \ -jar app.jar java \ -Xshare:dump \ -XX:SharedClassListFile=app-classlist \ -XX:SharedArchiveFile=app-cds.jsa \ --class-path app.jar
When created this way, AppCDS archives don't reference the JVM's own CDS archive, and all JVM classes need to be included in the AppCDS archive to avoid loading them from disk.
In more recent versions, the JVM can be configured to write the CDS archive during shutdown, and generated archives will reference the JVM's
java \ -XX:ArchiveClassesAtExit=app-cds.jsa \ -jar app.jar
The application can now be launched using this dynamic CDS archive:
java \ -XX:SharedArchiveFile=app-cds.jsa \ -jar app.jar
-Xshare:dumpis used during the JVM build process to create CDS archives to ship with a distribution.
-XX:DumpLoadedClassListlists the loaded classes.
-XX:SharedClassListFilespecifies additional classes to store in the CDS archive, formatted one class per-line with dots (
.) replaced by slashes (
-XX:SharedArchiveFileshould be set to an application-specific path when including application classes.
-XX:SharedArchiveConfigFilespecifies additional data: strings and symbols as dumped by jcmd's
- p.r.comp.lang.java.jvm.versions.se5 (Private) (client): introduced as a startup performance improvement, but only for system classes and only for Serial.
- SE 9: