Search code examples
javaoptimizationjvmjitjvm-hotspot

Can deoptimization happen after the damage has been done?


Aggressive speculation can be seen as a collective term for optimization techniques that require prediction of a program's next moves. When the prediction fails, deoptimization happens.

In HotSpot, when aggressive speculation predicting that "a non-constant object pointed by a reference is constant" has failed, will the damage necessarily rollback before deoptimization?

I'm wondering if there could be instances such as "cache coherency issues on multithreading environments" or "wrong values sent over the network due to failed predictions" could happen.

I don't have the whereabouts of the JVM code for JIT optimizations yet so I would just like to confirm with you guys if these kinds of stuff could happen.

Side question: Is it true that the JIT part code is not available at OpenJDK?


Solution

  • If it did, it would be a bug. Optimization is specifically not allowed to do that. That doesn't mean you don't need to synchronize your multithreaded programs; it means that if the optimizer breaks guarantees the synchronization makes, the optimization is broken. It also doesn't mean that this kind of problem never happens; sometimes, optimizers have bugs.