方法未在 Hotspot JVM 中编译的原因

发布于 2024-09-07 03:42:38 字数 129 浏览 6 评论 0原文

有一些可用标志提供已编译方法的日志信息。有关未编译方法的信息以及未编译原因的信息在哪里?能够了解热点编译器如何做出决定以及它不编译某些方法的原因将使我更好地了解 JVM,并允许我编写更好的代码并可能优化我的一些方法。有人对这个话题有什么想法吗?

There are flags available that provide log information on methods that have been compiled. Where is the information on methods that didn't get compiled and why they didn't get compiled? Being able to see how the hotspot compiler makes its decisions and the reasons for it not compiling certain methods would give me a better understanding of the JVM, and allow me to write better code and possibly optimize some of my methods. Anybody have any thoughts on this subject?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哑剧 2024-09-14 03:42:38

根据: http://blog.headius.com /2009/01/my-favorite-hotspot-jvm-flags.html

-XX:+PrintCompilation 打印出每个Java方法Hotspot的名称
决定进行 JIT 编译。该名单将
通常会展示一堆核心Java
首先类方法,然后转向
到您的应用程序中的方法。

我个人认为这只会浪费你很多时间。如果您使用最佳实践和一些常识进行编码,然后如果性能是一个问题,请进行分析。你应该做得很好。

As per: http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-flags.html

-XX:+PrintCompilation prints out the name of each Java method Hotspot
decides to JIT compile. The list will
usually show a bunch of core Java
class methods initially, and then turn
to methods in your application.

My personal belief is this is just going to suck a lot of your time. If you code using best practices and some common sense and then if performance is a problem, profile. You should do fine.

海夕 2024-09-14 03:42:38

答案是,如果方法执行的次数不够多,则可能无法编译它们。本机代码缓存是有限的,因此编译每个方法会适得其反;您最终可能会得到许多已编译的方法,但重要的方法不再适合缓存大小。

确切的数字因版本而异,但如果您使用 -XX:+PrintFlagsFinal 运行 Java,那么您将看到可以调整的所有设置,包括 Tier3CompileThreshold (其值为 2000)Tier4CompileThreshold(其值为 15000)。因此,如果您调用方法的次数不超过 2000 次,它将仅使用解释器来执行它。

如果您想在 JIT 条件下执行分析,那么您需要执行大量循环调用方法才能看到好处,或者使用分析工具,例如 JMH 正确进行分析。

The answer is that methods may not be compiled if they've not been executed enough times. The native code cache is limited, and so compiling every method is counterproductive; you could end up with a number of methods that have been compiled but then the important ones no longer fit in the cache size.

The exact numbers vary from release to release, but if you run Java with -XX:+PrintFlagsFinal then you'll see all of the settings that you can tweak, including Tier3CompileThreshold (which has the value 2000) Tier4CompileThreshold (which has the value 15000). So if you don't call your method more than 2000 times it'll just use the interpreter to go through it.

If you're wanting to perform profiling under JIT conditions then you need to perform a significant number of loops calling the methods in order to see the benefit, or use a profiling harness such as JMH to do the profiling properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文