简体   繁体   中英

Does JVM has its runtime branch prediction? If so, is there a way in Java code to hint branch results?

As the title says:

I remember that in some C compilers (such as GCC), we're able to give hint to compiler about likely branch prediction results. Does JVM have such function?

Thank you!

Unless there's some new annotation that's escaped me, no.

On the other hand, it's not clear how terribly useful such a feature would be. Remember that, unlike a language such as C/C++, "prediction" at the level of the source code isn't necessarily the best strategy because What The Code Is Actually Doing In Practice as it is running isn't a mystery: the JVM can potentially monitor critical behaviour and if necessary re-compile sections of code in accordance with its measurements.

No, the JVM has no such compiler hints or optimizations at the source level.

This post is interesting and includes a case where Java branch prediction fails:

Why is it faster to process a sorted array than an unsorted array?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM