热点 JIT 优化
在关于 Hotspot 中的 JIT 的讲座中,我想给出尽可能多的关于 JIT 执行的特定优化的示例。
我只知道“方法内联”,但应该还有更多。为每个示例投票。
In a lecture about JIT in Hotspot I want to give as many examples as possible of the specific optimizations that JIT performs.
I know just about "method inlining", but there should be much more. Give a vote for every example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
那么,您应该浏览 Brian Goetz 的文章以获取示例。
简而言之,HotSpot 可以并且将会:
等
Well, you should scan Brian Goetz's articles for examples.
In brief, HotSpot can and will:
synchronized
blocks on the same objectvolatile
variableset cetera
Jikes RVM 站点上有关于现代 JVM 使用的优化的精彩演示:
ACACES'06 - 虚拟机中的动态编译和自适应优化
它讨论了架构、权衡、测量和技术。并列出了 JVM 为优化机器代码所做的至少 20 件事。
There is a great presentation on the optimizations used by modern JVMs on the Jikes RVM site:
ACACES’06 - Dynamic Compilation and Adaptive Optimization in Virtual Machines
It discusses architecture, tradeoffs, measurements and techniques. And names at least 20 things JVMs do to optimize the machine code.
我认为有趣的事情是传统编译器无法做的与 JIT 相反的事情。内联方法、消除死代码、CSE、实时分析等都是由普通的 C++ 编译器完成的,这里没有什么“特别”的,
但是基于乐观假设优化某些内容,然后如果结果是错误的,那么稍后再进行反优化? (假设一种特定类型,删除如果不完成的话以后无论如何都会失败的分支,..)如果我们可以保证目前只存在一个类,则删除虚拟调用(同样,只有在去优化时才能可靠地工作)?我认为自适应优化是 JIT 与普通 C++ 编译器真正区别的一件事。
也许还提到 JIT 完成的运行时分析,以分析它应该应用哪些优化(尽管对于所有配置文件引导的优化来说,不再那么独特)。
I think the interesting stuff are those things that a conventional compiler can't do contrary to the JIT. Inlining methods, eliminating dead code, CSE, live analysis, etc. are all done by your average c++ compiler as well, nothing "special" here
But optimizing something based on optimistic assumptions and then deoptimizing later if they turn out to be wrong? (assuming a specific type, removing branches that will fail later anyhow if not done,..) Removing virtual calls if we can guarantee that there exists only one class at the moment (again something that only reliably works with deoptimization)? Adaptive optimization is I think the one thing that really distinguishes the JIT from your run of the mill c++ compiler.
Maybe also mention the runtime profiling done by the JIT to analyse which optimizations it should apply (not that unique anymore with all the profile-guided optimizations though).
本文中有一个旧的但可能仍然有效的概述。
亮点似乎是基于可用的运行时分析信息执行经典优化:
以及一些次要的优化,例如分代 GC这使得分配短命对象变得更便宜,以及各种其他较小的优化,以及自该文章发布以来添加的任何其他内容。
还有更详细的官方白皮书,以及相当详细的内容HotSpot 内部 wiki页面列出了如何编写快速 Java 代码,可以让您推断出哪些用例得到了优化。
There's an old but likely still valid overview in this article.
The highlights seem to be performing classical optimizations based on available runtime profiling information:
And some minor ones like generational GC which makes allocating short lived objects cheaper, and various other smaller optimizations, plus whatever else was added since that article was published.
There's also a more detailed official whitepaper, and a fairly nitty-gritty HotSpot Internals wiki page that lists how to write fast Java code that should let you extrapolate what use cases were optimized.
跳转到等效的本机机器代码,而不是操作码的 JVM 解释。 Java 应用程序中频繁使用的部分(相当于 JVM 的扩展)不需要在机器代码中模拟机器(JVM),从而提供了良好的速度提升。
当然,这就是 HotSpot 的大部分内容。
Jumps to equivalent native machine code instead of JVM interpretation of the op-codes. The lack of a need to simulate a machine (the JVM) in machine code for a heavily used part of a Java application (which is the equivalent of an extension of the JVM) provides a good speed increase.
Of course, that's most of what HotSpot is.