Deoptimization
In the previous section, we looked at various optimization techniques that the JIT compiler performs. The JIT compiler optimizes the code with some assumptions that it makes, based on the profiling. Sometimes, these assumptions may be not correct in a different context. When JIT stumbles upon these scenarios, it deoptimizes the code and goes back to using an interpreter to run the code. This is called Deoptimization and has an impact on performance.
There are two scenarios where Deoptimization occurs:
- When the code is "non-entrant"
- When the code is "zombie"
Let's understand these scenarios with the help of examples.
Non-entrant code
There are two cases where the code becomes non-entrant:
- Assumptions made during polymorphism: As we discussed in the section on monomorphic dispatch, polymorphism has a significant performance overhead on JVM. One of the optimizations that JIT performs is assuming a particular implementation...