Herong's Tutorial Notes on JVM
Dr. Herong Yang, Version 3.00, 2007

Class Data Sharing

Part:   1  2  3 

This chapter explains:

  • What is class data sharing (CDS).
  • How to regenerate the shared archive file.
  • Startup time improved by CDS.
  • Footprint affected by CDS.

What Is Class Data Sharing

Class Data Sharing (CDS) is a new feature introduced in JDK 1.5.0. CDS is designed to reduce the startup time and footprint of Java applications. The basic idea of CDS is to:

  • Select a set of system classes that are commonly used by Java applications.
  • Load the selected classes into memory.
  • Dump the loaded classes to a file called a "shared archive".
  • When a subsequent Java application is launched, JVM will restore the shared archive file into memory.
  • When multiple Java applications are launched on the machine, a portion of the shared archive will be shared by multiple JVM processes.

The startup time is reduced because of restoring shared archive is much faster than loading classes.

The footprint is reduced because of some data is shared by multiple JVM processes.

"java" command options related to CDS:

"-Xshare:dump" - Regenerating the shared archive file
"-Xshare:on" - Forcing JVM to restore the shared archive file
"-Xshare:off" - Forcing JVM to not use the shared archive file

Regenerating Shared Archive

When JDK 1.5.0 is installed on Windows 2000, the shared archive is stored in a file named "classes.jsa" in the "jre/bin/client" sub-directory. The following commands show you how I regenerated the shared archive file on my system:

del /F \j2sdk1.5.0\jre\bin\client\classes.jsa
\j2sdk1.5.0\bin\java -Xshare:dump
Loading classes to share ... done.
Rewriting and unlinking classes ... done.
Calculating hash values for String objects .. done.
Calculating fingerprints ... done.
Removing unshareable information ... done.
Moving most read-only objects to shared space at 0x2aa80000 ... done.
Moving common symbols to shared space at 0x2adde848 ... done.
Moving remaining symbols to shared space at 0x2af01148 ... done.
Moving string char arrays to shared space at 0x2af01bd8 ... done.
Moving additional symbols to shared space at 0x2af82ef0 ... done.
Read-only space ends at 0x2afd7960, 5601632 bytes.
Moving read-write objects to shared space at 0x2b280000 ... done.
Moving String objects to shared space at 0x2b7d5be8 ... done.
Read-write space ends at 0x2b8143a8, 5850024 bytes.
Updating references to shared objects ... done.

Test 1 - Startup Time Saving with Restoring Shared Archive

In order to test the saving of start up time with CDS, I wrote the following simple perl program, StartupTimeTest.pl:

#
#- StartupTimeTest.java
#- Copyright (c) 2004 by Dr. Herong Yang
#
   ($test) = @ARGV;
   if ($test eq "jdk142") {
      $cmd = "\\j2sdk1.4.2\\bin\\java -cp . Hello";
   } elsif ($test eq "jdk150_off") {
      $cmd = "\\j2sdk1.5.0\\bin\\java -cp . -Xshare:off Hello";
   } elsif ($test eq "jdk150_on") {
      $cmd = "\\j2sdk1.5.0\\bin\\java -cp . -Xshare:on Hello";
   }
   $number = 100;
   $t1 = time();
   for ($i=0; $i<$number; $i++) {
      system($cmd);
   }
   $t2 = time();
   $tt =  $t2 - $t1;
   $at =  $tt/$number;
   print "Command: $cmd\n";
   print "Total time: $tt seconds.\n";
   print "Average time: $at seconds.\n";

(Continued on next part...)

Part:   1  2  3 

Dr. Herong Yang, updated in 2007
Herong's Tutorial Notes on JVM - Class Data Sharing