I read about CDS in Oracle doc https://docs.oracle.com/javase/8/docs/technotes/guides/vm/class-data-sharing.html
What I understood is the system class files needed for loading the jvm are parsed, verified and then stored in a archive at jre/lib/[arch]/client/classes.jsa. Moreover they also provide their memory mapping for jvm,so jvm directly maps the memory according to the mapping information given in the archive. So this reduces the overhead of class loading everytime a jvm instance starts. Please correct me if was wrong.
Now coming to java 10, how can I achieve this for my application code ? Secondly, would the complete application code be eligible for CDS or are there some restrictions?
There are three essential steps to creating and using an archive with application class-data (for more details, read my post about application class-data sharing):
Creating a list of classes to include in the archive:
java -XX:+UseAppCDS
-XX:DumpLoadedClassList=classes.lst
-jar app.jar
Creating an archive:
java -XX:+UseAppCDS -Xshare:dump
-XX:SharedClassListFile=classes.lst
-XX:SharedArchiveFile=app-cds.jsa
--class-path app.jar
Using the archive:
java -XX:+UseAppCDS -Xshare:on
-XX:SharedArchiveFile=app-cds.jsa
-jar app.jar
Keep the following in mind:
-Xlog:class+load
(more on -Xlog
) to get more informationThe JEP for AppCDS has the example show casing how to add your application classes to shared archive. As for the restrictions, there are few:
There are other practical considerations to be aware of when using CDS/AppCDS, such as:
Another nice and detailed article on CDS and AppCDS is https://simonis.github.io/cl4cds/.
Author of the article has also written a tool that allows sharing of application classes even if they get loaded by a custom class loaders.
If you are interested in using CDS, you can also try OpenJ9 JVM which has this feature for a long time and is much more mature and complete. Read more about it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With