JVM Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.10

Startup Time Saving with Restoring Shared Archive

This section provides a tutorial example on how to save startup time by restoring shared archive 'java -Xshare:on'.

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

#
#- StartupTimeTest.pl
#- Copyright (c) 2004 by Dr. Herong Yang, herongyang.com
#
   ($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";

Here is how I did my tests:

\j2sdk1.4.2\bin\javac Hello.java
perl StartupTimeTest.pl jdk142
Hello world!
Hello world!
...
Command: \j2sdk1.4.2\bin\java -cp . Hello
Total time: 24 seconds.
Average time: 0.24 seconds.

\j2sdk1.5.0\bin\javac Hello.java
perl StartupTimeTest.pl jdk150_off
Hello world!
Hello world!
...
Command: \j2sdk1.5.0\bin\java -cp . -Xshare:off Hello
Total time: 31 seconds.
Average time: 0.31 seconds.

perl StartupTimeTest.pl jdk150_on
Hello world!
Hello world!
...
Command: \j2sdk1.5.0\bin\java -cp . -Xshare:on Hello
Total time: 18 seconds.
Average time: 0.18 seconds.

The test result is very interest:

  • With JDK 1.5.0, CDS indeed reduced the startup time of running Hello.java from 0.31 seconds to 0.18 seconds.
  • However, the startup time of running Hello.java increased from 0.24 seconds to 0.31 seconds between JDK 1.4.2 and JDK 1.5.0.

Last update: 2004.

Table of Contents

 About This Book

 Download and Install Java SE 1.6 Update 2

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 Sun's JVM - Java HotSpot VM

 JRockit JVM 7.0 by BEA Systems

 JRockit JVM 8.0 by BEA Systems

 Memory Management Rules and Tests

 Garbage Collection Tests

 Stack Overflow Tests

 Thread Testing Program and Result

 StringBuffer Testing Program and Result

CDS (Class Data Sharing)

 What Is Class Data Sharing?

 Regenerating Shared Archive

Startup Time Saving with Restoring Shared Archive

 Startup Time Saving with Multiple JVM Processes

 Footprint Saving with Restoring Shared Archive

 Viewing Shared Memory of JVM Processes

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2010
Startup Time Saving with Restoring Shared Archive