Last Updated: February 25, 2016
·
1.618K
· colindean

Speed up program startup when using the IBM Java Virtual Machine

My coworker Stan found a great tip for expediting program startup when using the IBM version of Java.

Add -Xshareclasses:name=cachename to your JVM startup options, be it idea.vmoptions for IntelliJ IDEA, eclipse.ini for Eclipse, or whatever. Replace cachename with whatever program you're using so that the caches don't collide.

It creates a persistent cache on your file system to store the classes translated to native code that the JVM needs to run a particular application which makes subsequent startups really fast.

There are some utilities to help you do manage your shared classes:

// duh
java -Xshareclasses:listAllCaches
// destroy just one cache
java -Xshareclasses:destroy,name=myCacheName
// destroy all caches
java -Xshareclasses:destroy

You can read more information and other options in the IBM JDK Knowledge Center.

Remember, though, that this option applies only to the IBM JVM. If you try it out on Hotspot (Oracle JVM), OpenJDK, or IcedTea, you're gonna have a bad time.

To ensure that you can use it, try running java -Xshareclasses:help first. If it bombs out, then you're not necessarily out of luck! You can download the IBM JDK for Linux or get the IBM Development Package for Eclipse for Windows, as IBM doesn't ship a separate JDK for that platform. OSX folks are out of luck for now.

Also, one warning: If you update a program using Xshareclasses, you really should reset or destroy the cache. Otherwise, the program may behave weirdly when some cached classes aren't properly invalidated.