The Java HotSpot™ Virtual Machine of Sun Microsystems optimizes Java applications at run time. The just-in-time compiler translates Java bytecodes of frequently executed methods to machine code and performs aggressive optimizations such as inlining of dynamically bound methods. The optimizations are performed optimistically based on the set of currently loaded classes and methods. If an optimization is invalidated later, e.g. because of dynamic class loading, the VM can revert the optimization. This is called deoptimization. The optimized machine code is discarded, and execution continues in the interpreter.
This paradigm simplifies all sorts of run-time optimizations because it handles uncommon or unpredictable situations in the optimization system. We use deoptimization in several research projects. For example, our algorithm for array bounds check elimination assumes that no bounds check fails and uses deoptimization if this assumption does not hold.
Automatic object inlining and array inlining is a novel feedback-directed optimization that uses not only the just-in-time compiler, but also the garbage collector to reduce the overhead of memory accesses. The order of frequently accessed objects on the heap is changed such that memory accesses can be replaced with address arithmetic. Deoptimization handles rare cases such as field accesses via reflection.