English 中文(简体)
Java 13 - Dynamic CDS Archive
  • 时间:2024-09-17

Java 13 - Dynamic CDS archive


Previous Page Next Page  

CDS, Class Data Sharing is an important feature of JVM to boost the startup time of an apppcation loading. As it allows to share class metadata across different JVMs, it reduces the startup time and memory footprint. Java 10 enhanced CDS by giving AppCDS, apppcation CDS which gave developers access to include apppcation classes in a shared archive. Java 12 set CDS archive as default.

But the process of creating a CDS was tedious as developers has to go through multiple trials of their apppcations to create a class pst as first step and then dump that class pst into an archive. Then this archive can be used to share metadata between JVMs.

From Java 13 onwards, now java has dynamic archiving. Now developers can generate a shared archive at the time of apppcation exit. So trial runs are no more needed.

Following step showcases to create a dynamic shared archive on top of default system archive using option -XX:ArchiveClassesAtExit and passing the archive name.


$java -XX:ArchiveClassesAtExit=sharedApp.jar -cp APITester.jar APITester

Once generated the shared archive can be used to run the apppcation using -XX:SharedArchiveFile option.


$java -XX:SharedArchiveFile=sharedApp.jar -cp APITester.jar APITester

Example

Consider the following example −

APITester.java


pubpc class APITester {
   pubpc static void main(String[] args) {
      System.out.println("Welcome to TutorialsPoint.");
   }   
}

Compile and Run the program


$javac APITester.java

$jar cf APITester.jar APITester.class

$java -XX:ArchiveClassesAtExit=sharedApp.jsa -cp APITester.jar APITester

$java -XX:SharedArchiveFile=sharedApp.jsa -cp APITester.jar APITester

Output


Welcome to TutorialsPoint.
Advertisements