Search code examples
javajvmjvm-hotspot

Do some JVMs cache static initializer results, for commonly used library classes


Since JVM startup time seems to be a point of concern would it make sense to cache the results of some more complex static initializers, such as java.lang.invoke.MethodType(and other java.lang classes which have complex initialization logic). The JVM would then be able to start up more quickly after having run once. Additionally I believe that static initializers never contain certain JIT optimizations, so some static initializers could be quite slow. I imagine caching would only work on pure static initializers, so any caching would probably have to be restricted to the standard library. Are there any JVM implementations with some kind of caching of statically initialized classes?


Solution

  • Yes. For example, GraalVM Native Image can initialize certain classes just once at build time.
    See --initialize-at-build-time= option.