简体   繁体   English

热点JIT优化

[英]Hotspot JIT optimizations

In a lecture about JIT in Hotspot I want to give as many examples as possible of the specific optimizations that JIT performs. 在关于Hotspot中的JIT的讲座中,我想尽可能多地给出JIT执行的特定优化的示例。

I know just about "method inlining", but there should be much more. 我只知道“方法内联”,但应该有更多。 Give a vote for every example. 为每个例子投票。

Well, you should scan Brian Goetz's articles for examples. 好吧,你应该扫描Brian Goetz的文章作为例子。

In brief, HotSpot can and will: 简而言之,HotSpot可以并且将会:

  1. Inline methods 内联方法
  2. Join adjacent synchronized blocks on the same object 加入同一对象上的相邻synchronized
  3. Eliminate locks if monitor is not reachable from other threads 如果无法从其他线程访问监视器,则消除锁定
  4. Eliminate dead code (hence most of micro-benchmarks are senseless) 消除死代码(因此大多数微基准都没有意义)
  5. Drop memory write for non- volatile variables 丢弃非易失volatile变量的内存写入
  6. Replace interface calls with direct method calls for methods only implemented once 使用直接方法调用替换接口调用,方法仅实现一次

et cetera 等等

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 有关现代JVM在Jikes RVM站点上使用的优化的精彩演示: ACACES'06 - 虚拟机中的动态编译和自适应优化

It discusses architecture, tradeoffs, measurements and techniques. 它讨论了架构,权衡,测量和技术。 And names at least 20 things JVMs do to optimize the machine code. 并且至少列出了JVM为优化机器代码所做的20件事。

I think the interesting stuff are those things that a conventional compiler can't do contrary to the JIT. 我认为有趣的东西是传统编译器不能与JIT相反的东西。 Inlining methods, eliminating dead code, CSE, live analysis, etc. are all done by your average c++ compiler as well, nothing "special" here 内联方法,消除死代码,CSE,实时分析等都是由你的普通c ++编译器完成的,这里没什么“特别的”

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. 自适应优化是我认为真正区分JIT与mill c ++编译器运行的一件事。

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). 也许还提到了JIT完成的运行时分析,以分析它应该应用哪些优化(不过那时所有的配置文件引导的优化都不再那么独特)。

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: 亮点似乎是基于可用的运行时分析信息执行经典优化:

  • JITting "hot spots" into native code 将“热点”引入本机代码
  • Adaptive inlining – inlining the most commonly called implementations for a given method dispatch to avoid a huge code size 自适应内联 - 为给定的方法分派内联最常用的实现,以避免巨大的代码大小

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. 还有一些次要的,比如代际GC,这使得分配短寿命对象更便宜,以及各种其他更小的优化,以及自该文章发布以来添加的任何其他内容。

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. 还有一个更详细的官方白皮书 ,以及一个相当细致的HotSpot Internals wiki页面 ,其中列出了如何编写快速Java代码,以便您可以推断出优化的用例。

Jumps to equivalent native machine code instead of JVM interpretation of the op-codes. 跳转到等效的本机机器代码而不是操作码的JVM解释。 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. 对于Java应用程序的大量使用部分(相当于JVM的扩展)而言,不需要在机器代码中模拟机器(JVM)提供了良好的速度提升。

Of course, that's most of what HotSpot is. 当然,这就是HotSpot的大部分内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM