我可以强制JVM本地编译给定的方法吗? [英] Can I force the JVM to natively compile a given method?

查看:143
本文介绍了我可以强制JVM本地编译给定的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用启动时经常调用一个性能关键的方法。最终,它得到了JIT编译,但是在解释器中运行了一些明显的时间后没有。

I have a performance-critical method called often when my app starts up. Eventually, it gets JIT-compiled, but not after some noticeable time being run in the interpreter.

有什么方法可以告诉JVM我想要编译这个方法从一开始就没有用 -XX:CompileThreshold 之类的内容调整其他内部结构?

Is there any way I can tell the JVM that I want this method compiled right from the start (without tweaking other internals with stuff like -XX:CompileThreshold)?

推荐答案

我知道的唯一方法是 -Xcomp 标志,但通常不建议使用。它会在第一次运行时强制立即对所有类和方法进行JIT编译。缺点是您将在初始启动时看到性能下降(由于JIT活动增加)。此标志的另一个主要限制是它似乎禁用JIT通常会执行的基于增量分析的优化。在标准混合模式下,JIT编译器可以(并将)根据收集的分析和运行时信息不断地优化和重新编译部分代码。这允许它纠正错误的优化,例如省略但被证明需要的边界检查,次优内联等。 -Xcomp 禁用基于分析的优化和取决于程序,可能会导致整体性能显着下降,只有很小或没有真正的启动增益,这就是为什么不建议使用它。

The only way I know of is the -Xcomp flag, but that is not generally advisable to use. It forces immediate JIT compilation of ALL classes and methods first time they are run. The downside is that you will see a performance decrease on initial startup (due to increased JIT activity). The other major limitation with this flag is that it appears to disable the incremental profiling-based optimization that JIT would normally do. In standard mixed mode, the JIT compiler can (and will) deoptimize and re-compile parts of the code continually based on profiling and run-time information collected. This allows it to "correct" faulty optimizations like boundary checks that were omitted but turned out to be needed, sub-optimal inlinings etc. -Xcomp disables the profiling-based optimization and depending on program, can cause significant performance losses overall for only a small or no real gain in startup, which is why it's not recommended to use.

超出 -Xcomp (这是非常残酷的)和 -XX:CompileThreshold (它控制JIT将运行的给定方法的执行次数在编译/优化它之前收集统计信息的解释模式),还有 -Xbatch 。这迫使JIT编译到前景,基本上阻止对方法的调用,直到它被编译,而不是像往常那样在后台编译它。

Beyond to -Xcomp (which is pretty brutal) and -XX:CompileThreshold (which controls how many executions of a given method the JIT will run in intepreted mode to gather stats before compiling/optimizing it), there is also -Xbatch. This forces JIT compilation to the "foreground", essentially blocking calls to methods until it's been compiled, rather than compiling it in the background as it normally does.

你没有' t指定您正在使用的Java版本,但如果Java 7是您的选项,它会引入一个名为Tiered compilation的新JIT模型(使用 -XX激活:+ TieredCompilation 开关)。分层编译的作用是,它允许在第一次使用方法时进行初始的,较小的编译传递,而不是基于收集的分析数据进行额外的,更大的编译/优化。听起来它应该对你很有意思。

You didn't specify which Java version you are using, but if Java 7 is an option for you, it introduces a new JIT model called "Tiered compilation" (activated with the -XX:+TieredCompilation switch). What tiered compilation does is that it allows an initial, smaller compilation pass on the first use of a method and than an additional, larger compilation/optimization later, based on collected profiling data. Sounds like it should be interesting to you.

据说需要一些额外的调整和参数/配置,但我还没有进一步检查它。

It supposedly requires some additional tweaking and parameters/configurations, but I've not got around to checking it out further.

这篇关于我可以强制JVM本地编译给定的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆