为什么 JVM 不缓存 JIT 编译的代码? [英] Why doesn't the JVM cache JIT compiled code?

查看:39
本文介绍了为什么 JVM 不缓存 JIT 编译的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sun 的规范 JVM 实现对字节码应用了一些非常复杂的优化,以便在代码运行几次后获得接近本机的执行速度.

The canonical JVM implementation from Sun applies some pretty sophisticated optimization to bytecode to obtain near-native execution speeds after the code has been run a few times.

问题是,为什么不将此编译后的代码缓存到磁盘以供后续使用同一函数/类时使用?

The question is, why isn't this compiled code cached to disk for use during subsequent uses of the same function/class?

就目前而言,每次执行程序时,JIT 编译器都会重新启动,而不是使用代码的预编译版本.当字节码基本上被解释时,添加此功能不会显着增加程序的初始运行时间吗?

As it stands, every time a program is executed, the JIT compiler kicks in afresh, rather than using a pre-compiled version of the code. Wouldn't adding this feature add a significant boost to the initial run time of the program, when the bytecode is essentially being interpreted?

推荐答案

没有对@MYYN 发布的链接进行剪切,我怀疑这是因为 JVM 执行的优化不是静态的,而是静态的动态的,基于数据模式和代码模式.这些数据模式很可能会在应用程序的生命周期内发生变化,从而导致缓存优化不太理想.

Without resorting to cut'n'paste of the link that @MYYN posted, I suspect this is because the optimisations that the JVM performs are not static, but rather dynamic, based on the data patterns as well as code patterns. It's likely that these data patterns will change during the application's lifetime, rendering the cached optimisations less than optimal.

因此,您需要一种机制来确定保存的优化是否仍然是最佳的,此时您不妨直接重新优化.

So you'd need a mechanism to establish whether than saved optimisations were still optimal, at which point you might as well just re-optimise on the fly.

这篇关于为什么 JVM 不缓存 JIT 编译的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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