Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
I think HotSpot does this, but also the CPU has dynamic prediction technology since Pentium II, so if it made the wrong decision twice, it'll correct itself at the third time if it's let to recognize the context. –  Aadaam Aug 6 '12 at 16:07

1 Answer 1

As Aadaam mentions in his comment to the question, HotSpot does this. I assume that J9 and the other major JVMs also do something similar.

share|improve this answer
How are they able to use collected statistic to improve branch prediction? Any reference? I know they collect them and I've idea about how to use them for other purposes -- a related one would be increase cache locality by wisely choosing the consecutive basic blocks -- but I can't see how to improve branch prediction (excepted hints on ISA which have them, but modern processors ignore hints as soon as they have collected themselves statistic). Perhaps on correlated branches? But ISTR that the stat collected by JVM aren't detailed enough for that. –  AProgrammer Aug 6 '12 at 18:30
And this is where I'm going to give the standard (somewhat painful) response. You're going to have to look at the source code of Hotspot for the version of HotSpot that you're looking to work with (documentation is.... limited). The hotspot mailing list is also a good place to ask your question, it's certainly an interesting one! –  Martijn Verburg Aug 7 '12 at 9:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.