Reputation: 552
Is the JVM (any of them) ever re-compiling code that has already been compiled at runtime?
Upvotes: 1
Views: 58
Reputation: 9599
It depends on what you mean by re-compiling, but the HotSpot VM will discard code that relies on optimistic assumptions when they are proven to be wrong or no longer relevant. See deoptimization:
Deoptimization is the process of changing an optimized stack frame to an unoptimized one. With respect to compiled methods, it is also the process of throwing away code with invalid optimistic optimizations, and replacing it by less-optimized, more robust code.
The fourth point is particularly interesting:
If a class is loaded that invalidates an earlier class hierarchy analysis, any affected method activations, in any thread, are forced to a safepoint and deoptimized.
This applies to optimistic method inlining as described in this paper:
A class hierarchy analysis (CHA) is used to detect virtual call sites where currently only one suitable method exists. This method is then optimistically inlined. If a class is loaded later that adds another suitable method and, therefore, the optimistic assumption no longer holds, the method is deoptimized.
Upvotes: 1