简体   繁体   English

JVM 有它的运行时分支预测吗? 如果是这样,Java 代码中是否有提示分支结果的方法?

[英]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.我记得在某些 C 编译器(例如 GCC)中,我们能够向编译器提示可能的分支预测结果。 Does JVM have such function? JVM有这样的功能吗?

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.请记住,与 C/C++ 等语言不同,源代码级别的“预测”不一定是最佳策略,因为代码在运行时实际上在做什么并不神秘:JVM可以潜在地监视关键行为,并在必要时根据其测量结果重新编译代码段。

No, the JVM has no such compiler hints or optimizations at the source level.不,JVM 在源代码级别没有这样的编译器提示或优化。

This post is interesting and includes a case where Java branch prediction fails:这篇文章很有趣,包括一个 Java 分支预测失败的案例:

Why is it faster to process a sorted array than an unsorted array? 为什么处理排序数组比处理未排序数组更快?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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