Java 13 – Dynamic CDS archive

  • Post author:
  • Post category:Java 13
  • Post comments:1 Comment
Java 13 - Dynamic CDS archive

This topic is about Java 13 – Dynamic CDS archive.

CDS, Class Data Sharing is an important feature of JVM to boost the startup time of an application 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, application CDS which gave developers access to include application 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 applications to create a class list as first step and then dump that class list 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 application 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 application using -XX:SharedArchiveFile option.

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

Example

Consider the following example −

APITester.java

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

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 Adglob.

In this topic we learned about Java 13 – Dynamic CDS archive. To know more, Click Here.

This Post Has One Comment

Leave a Reply