如何在某个时刻强制执行/确保Java热点JIT编译

时间:2021-04-25 17:21:32

The problem i'm interested in at the moment is profiling/optimizing some piece of code. General recommendation for profiling with Java is "run", "wait for some time for hotspot JIT compiler to do its job", "repeat the test" ...

我现在感兴趣的问题是分析/优化某些代码。使用Java进行性能分析的一般建议是“运行”,“等待一段时间让热点JIT编译器完成其工作”,“重复测试”......

So the questions are

所以问题是

  • how long shoud I wait for hotspot to start and complete its job?
  • 我等待热点开始并完成其工作多久了?

  • will JIT run while CPU is rather saturated (by other threads)? - it may happen in real life that process constantly loads CPU up to 100%.
  • 将JIT运行,而CPU相当饱和(由其他线程)? - 它可能在现实生活中发生,该过程不断加载CPU高达100%。

  • how many executions of the same piece of code is needed to identify the "hot spots"?
  • 需要多少次执行同一段代码来识别“热点”?

  • is it possible to somehow magically (probably using some proprietary API of the Oracle JVM) to trigger JIT compilation for certaing classes?
  • 是否可能以某种方式神奇地(可能使用Oracle JVM的某些专有API)来触发针对certaing类的JIT编译?

1 个解决方案

#1


0  

how long shoud I wait for hotspot to start and complete its job?

我等待热点开始并完成其工作多久了?

About 10,000 calls/iterations and a few milli-seconds.

大约10,000次调用/迭代和几毫秒。

will JIT run while CPU is rather saturated (by other threads)? - it may happen in real life that process constantly loads CPU up to 100%.

将JIT运行,而CPU相当饱和(由其他线程)? - 它可能在现实生活中发生,该过程不断加载CPU高达100%。

Yes, it may take longer, but performing test at 100% of CPU it's usually a good idea as the results are less likely to be representative of what you would do in production.

是的,它可能需要更长的时间,但是在100%的CPU上执行测试通常是一个好主意,因为结果不太可能代表您在生产中所做的事情。

how many executions of the same piece of code is needed to identify the "hot spots"?

需要多少次执行同一段代码来识别“热点”?

I would wait until the code has warmed up where possible. Realistic test data, a few seconds at high CPU utilisation and a decent profiler is usually enough.

我会等到代码尽可能热身。现实的测试数据,高CPU利用率的几秒钟和一个不错的分析器通常就足够了。

is it possible to somehow magically (probably using some proprietary API of the Oracle JVM) to trigger JIT compilation for certaing classes?

是否可能以某种方式神奇地(可能使用Oracle JVM的某些专有API)来触发针对certaing类的JIT编译?

Other than running it enough times no. Compiling the class too early can lead to sub-optimal code. The code is optimised based on how it is used. JRockit (which is also owned by Oracle) has/had such a feature.

除了运行足够的次数没有。过早编译类可能导致次优代码。代码根据其使用方式进行优化。 JRockit(也归Oracle所有)具有这样的功能。

#1


0  

how long shoud I wait for hotspot to start and complete its job?

我等待热点开始并完成其工作多久了?

About 10,000 calls/iterations and a few milli-seconds.

大约10,000次调用/迭代和几毫秒。

will JIT run while CPU is rather saturated (by other threads)? - it may happen in real life that process constantly loads CPU up to 100%.

将JIT运行,而CPU相当饱和(由其他线程)? - 它可能在现实生活中发生,该过程不断加载CPU高达100%。

Yes, it may take longer, but performing test at 100% of CPU it's usually a good idea as the results are less likely to be representative of what you would do in production.

是的,它可能需要更长的时间,但是在100%的CPU上执行测试通常是一个好主意,因为结果不太可能代表您在生产中所做的事情。

how many executions of the same piece of code is needed to identify the "hot spots"?

需要多少次执行同一段代码来识别“热点”?

I would wait until the code has warmed up where possible. Realistic test data, a few seconds at high CPU utilisation and a decent profiler is usually enough.

我会等到代码尽可能热身。现实的测试数据,高CPU利用率的几秒钟和一个不错的分析器通常就足够了。

is it possible to somehow magically (probably using some proprietary API of the Oracle JVM) to trigger JIT compilation for certaing classes?

是否可能以某种方式神奇地(可能使用Oracle JVM的某些专有API)来触发针对certaing类的JIT编译?

Other than running it enough times no. Compiling the class too early can lead to sub-optimal code. The code is optimised based on how it is used. JRockit (which is also owned by Oracle) has/had such a feature.

除了运行足够的次数没有。过早编译类可能导致次优代码。代码根据其使用方式进行优化。 JRockit(也归Oracle所有)具有这样的功能。