如何检查 JIT 编译器是否在 Java 中关闭

2022-01-17 00:00:00 jit compiler-construction java

我想知道如何检查 JIT 编译器是否已关闭.我有以下代码,旨在关闭 JIT 编译器.问题是,我不确定它是否真的这样做.所以我想知道是否有办法检查 JIT 是否关闭.我查看了 Compiler 类,但没有像 isDisabled/enabled() 这样的方法.

I would like to know how to check if the JIT compiler is turned off. I have the following code which is meant to turn the JIT compiler off.The problem is, I am not sure if it is actually doing that. So I was wondering if there is a way of checking if the JIT is off. I looked at the Compiler class but there isn't any method like isDisabled/enabled().

代码:

Compiler.disable();  

任何帮助或指导将不胜感激.

Any help or direction will be highly appreciated.

推荐答案

我不相信你可以在运行时关闭 JIT.

I don't believe you can turn the JIT off at runtime.

如果您想认真地对 Java 程序进行基准测试,您绝对应该忽略前几次运行.在 Java 中获得可靠的基准是一项非常棘手的工作,最好留给比你或我聪明得多的人.

If you want to seriously benchmark a Java program, you should definitely be ignoring the first few runs. Getting reliable benchmarks in Java is an extremely tricky business, best left to people much smarter than you or I.

我推荐使用 Caliper,它在 Google 内部用于微基准测试,并且在预热 JIT 方面非常聪明和东西.特别是查看示例这里,它展示了如何衡量不同输入大小的算法的效率.

I recommend using Caliper, which is used internally at Google for microbenchmarking and is plenty smart about warming up the JIT and stuff. In particular, look at the example here, which shows how to measure the efficiency of an algorithm for different input sizes.

相关文章