热点 JIT 优化

发布于 2024-12-11 04:27:17 字数 94 浏览 0 评论 0原文

在关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

笑红尘 2024-12-18 04:27:17

那么,您应该浏览 Brian Goetz 的文章以获取示例。

简而言之,HotSpot 可以并且将会:

  1. 内联方法
  2. 连接同一对象上的相邻同步块
  3. 如果无法从其他线程访问监视器,则消除锁定
  4. 消除死代码(因此大多数微基准测试都是毫无意义的)
  5. 丢弃内存为非易失性变量编写
  6. 将接口调用替换为仅实现一次的方法的直接方法调用

Well, you should scan Brian Goetz's articles for examples.

In brief, HotSpot can and will:

  1. Inline methods
  2. Join adjacent synchronized blocks on the same object
  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
  6. Replace interface calls with direct method calls for methods only implemented once

et cetera

关于从前 2024-12-18 04:27:17

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.

稍尽春風 2024-12-18 04:27:17

我认为有趣的事情是传统编译器无法做的与 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).

棒棒糖 2024-12-18 04:27:17

本文中有一个旧的但可能仍然有效的概述。

亮点似乎是基于可用的运行时分析信息执行经典优化:

  • JITting“热点”到本机代码中
  • 自适应内联 - 内联给定方法分派最常调用的实现,以避免巨大的代码大小

以及一些次要的优化,例如分代 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:

  • 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.

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.

花海 2024-12-18 04:27:17

跳转到等效的本机机器代码,而不是操作码的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文