Did you know… that just by using OpenJ9 as your runtime, applications using deserialization could gain a huge performance advantage?
Background
Java serialization provides a way to easily convert a sequence of bytes to and from a java.lang.Object
.
One step that occurs during the process of deserialization is loading the class specified by the class descriptor in the stream of bytes. This involves calling two methods that contribute to slow performance:
- java.lang.Class.forName
- java.io.ObjectInputStream.latestUserDefinedLoader
This is a private method that finds the latest user defined classloader or “LUDCL” to use with Class.forName
. If first acquires VM access which means its safe to examine VM data structures and walk the stack. It then walks the stack to find the most recent ClassLoader
which is an expensive action.
Optimization
In OpenJ9 there are two optimizations at work:
- Class caching: create a
java.io.ClassCache
to reduce calls tojava.lang.Class.forName
for repeated lookups - Cache “LUDCL”: The loader can be safely cached while in the
ObjectInputStream
class. If customreadObject
methods are invoked during this process the LUDCL will need to be refreshed. - JIT replacing
ObjectInputStream.readObject
: To eliminate another LUDCL retrieval, the JIT will replaceObjectInputStream.readObject()
call withObjectInputStream.redirectedReadObject(ObjectInputStream iStream, Class caller)
.ObjectInputStream.redirectedReadObject
will provide the LUDCL information through an argument preventing extra calls to LUDCL.
Performance results for Java 8

How can I take advantage of this?
This deserialization goodness will be enabled by default starting with OpenJ9’s 0.18.0 release this January, 2020 for all Java versions.
In the meantime to ensure you are making the most of OpenJ9’s performance advantage you can enable the option with the com.ibm.enableClassCaching
property. See our documentation for more details.
This should probably link to the Javadoc for ObjectInputStream.resolveClass, since that Javadoc is what explains how the LUDCL is actually used.