Precompiling Custom JARs

24. June, 2009

Java 5 precompiles the rt.jar to a file with the JIT when you start it the first time. This is mostly to improve startup times; it takes only a few moments and is much more efficient than running the JIT when a class has been used more than N times. Next time the class is requested, the VM skips the bytecode loading and directly pulls in the precompiled binary which is already optimized for your CPU.

My idea is to open this process for custom JARs. Any big Java app loads heaps of external JARs and that takes time – often a lot of time. JARs would need to supply a special META-INF file which contains a UUID or a checksum from which the VM can conclude whether the JAR has changed or not.

The first time the JAR shows up in the classpath, the JIT precompiler would convert it, save the result in the cache. Next time, the META-INF file would be read, and the bytecode would be ignored. I’ll open a enhancement request in OpenJDK 7. If you like the idea, please support it.