Java JVM JIT – Does Current JIT Optimize Machine Codes for Branch Prediction Based on Runtime Statistics?

javajitjvm

Some JVMs would compile Java byte code into native machine code. We know that there are lots of optimizations we could apply for that. Recently, I also learn that a branch operation may block the CPU and affect the performance significantly, if a CPU makes a wrong prediction.

Does anyone know if any JVM would generate machine codes easier for CPU making right prediction based on runtime statistics collected?

Best Answer

No, HotSpot does not add hints to the hardware branch predictor as stated on the OpenJDK mailing list:

It's been considered, and decided against. The platforms which openjdk currently targets all have decent to spectacular hardware branch prediction. Those that didn't, such as Niagara 1, ignored prediction bits. Conclusion is that it's not worth complicating the code with, as David says, 'magic macros'.