我目前感兴趣的问题是分析/优化一些代码。使用 Java 进行分析的一般建议是“运行”、“等待热点 JIT 编译器完成它的工作”、“重复测试”...
所以问题是
- 我应该等待热点启动并完成其工作多长时间?
- JIT 会在 CPU 相当饱和(由其他线程)时运行吗? - 在现实生活中可能会发生进程不断加载 CPU 高达 100%。
- 识别“热点”需要执行多少次相同的代码?
- 是否有可能以某种神奇的方式(可能使用 Oracle JVM 的某些专有 API)触发某些类的 JIT 编译?
最佳答案
how long shoud I wait for hotspot to start and complete its job?
大约 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%.
是的,这可能需要更长的时间,但是以 100% 的 CPU 执行测试通常是个好主意,因为结果不太可能代表您在生产中所做的事情。
how many executions of the same piece of code is needed to identify the "hot spots"?
我会尽可能等到代码预热。真实的测试数据、几秒钟的高 CPU 使用率和一个像样的分析器通常就足够了。
is it possible to somehow magically (probably using some proprietary API of the Oracle JVM) to trigger JIT compilation for certaing classes?
除了运行它足够多次之外没有。过早编译类会导致代码不理想。代码根据其使用方式进行了优化。 JRockit(也归 Oracle 所有)有这样的功能。
关于java - 如何在特定时刻强制/确保 Java 热点 JIT 编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14570899/