是否可以启用本机代码缓存? [英] Is it possible to enable caching of native code?

查看:78
本文介绍了是否可以启用本机代码缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以使JVM将其生成的优化本机代码缓存到文件中,以提高以后运行的性能?

Is there any way to make the JVM cache the optimized native code it generates to a file, to improve the performance of future runs?

推荐答案

从JDK 9开始就可以进行提前(AOT)编译.请参见

Ahead-of-Time (AOT) compilation is available since JDK 9. See JEP 295.
Note: this is not the same as GraalVM Native Image.

由于某些原因,缓存JIT编译代码是有问题的.

Caching of JIT compiled code is problematic for several reasons.

  • HotSpot编译器严重依赖于推测性优化.这些优化基于某些运行时条件,这些条件可能从一次运行到另一次运行并不总是相同.

  • HotSpot compilers heavily rely on speculative optimizations. These optimizations are based on certain runtime conditions that may not be always the same from one run to another.

JIT编译的代码可能引用特定的对象和类,它可能依赖于仅在运行时才知道值的常量,并且可能将内存地址直接内联到指令流中.这使得缓存的代码无法直接重用.可以通过额外的间接级别解决该问题,这将影响性能.

JIT compiled code may refer to the particular objects and classes, it may rely on the constants which values are known in runtime only, it may have memory addresses inlined directly into the instruction stream. This makes the cached code impossible for direct reuse. The problem can be solved by an extra level of indirection, which will impact the performance.

这就是为什么几个JVM供应商采用另一种方法的原因:缓存运行时配置文件数据,而不是最终代码.从前一次运行中收集到的概要文件数据可用于尽快重新编译最热门的方法(一旦满足所有前提条件),而无需运行解释器中的方法来再次收集概要文件.

That's why several JVM vendors took another approach: to cache runtime profile data instead of the final code. The profile data collected from the previous run can then be used to recompile the hottest methods as soon as possible (once all the preconditions are met) without need to run methods in the interpreter to collect the profile again.

至少有两个已知的解决方案:

There are at least two known solutions:

  • JWarmup available in Alibaba Dragonwell;
  • ReadyNow! available in Azul Zing.

Zing虚拟机还具有 Compile Stashing 技术来重用已编译的代码本身.它可以与ReadyNow!一起使用.

Zing Virtual Machine also has Compile Stashing technology to reuse the compiled code itself. It can be used together with ReadyNow!.

有一个 JEP草案在OpenJDK中添加了JWarmup支持.

There is a JEP draft to add JWarmup support in OpenJDK.

这是有关AOT的漂亮的博客帖子HotSpot中的编译,JIT缓存和相关技术.

Here is a nice blog post about AOT Compilation in HotSpot, JIT Caching and related technologies.

这篇关于是否可以启用本机代码缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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