Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed up application start by adding own application classes to classes.jsa

To speed up the startup time of the JVM, the Sun developers decided it is a good idea to precompile the standard runtime classes for a platform during installation of the JVM. These precompiled classes can be found e.g. at:

$JAVA_HOME\jre\bin\client\classes.jsa

My company currently develops a Java standalone application which brings its own JRE, so it would be a fantastic option to speed up our application start time by adding our own application classes to this jsa file, too.

I don't believe the JSA file was created by magic, so: How is it created? And how can I trick the JVM into incorporating my own classes?

EDIT: I already found out the following:

The classes.jsa is created by the command

java -Xshare:dump 

The list of classes to incorporate in the dump can be found in $JAVA_HOME/jre/lib/classlist.

I even managed to add my own classes here (and to add them into the rt.jar for java to find them), and to generate my own checksum below the classlist file.

The final problem is: Only classes in the packages java, com.sun, and org.w3c seem to be recognized, if I leave the same classes in their original packages, they won't be loaded. I searched the whole OpenJDK source for pointer about this, but it seems to have something to do with protection domains. If someone is interested enough in this topic and knowledgeable enough, please add some pointers for me to investigaete further.

like image 558
Daniel Avatar asked Jan 14 '11 14:01

Daniel


1 Answers

As of Java 8u40 (and Embedded Java 8u51), Java now supports Application Class Data Sharing (AppCDS) (ie your own classes in the shared archive). On our embedded java, we've found a startup improvement of >40%! Pretty awesome for almost no work on our part...

https://blogs.oracle.com/thejavatutorials/entry/jdk_8u40_released

like image 170
Ben Avatar answered Oct 02 '22 14:10

Ben