“现代 JVM”是如何实现的?与旧版 JVM 有何不同?

发布于 2024-08-16 04:51:28 字数 200 浏览 5 评论 0原文

这是我在高中和大学计算机科学课程中经常听到的一句话:

“这对于现代 JVM 来说不是问题。”

通常这会在有关整体性能或优化策略的讨论中出现。不过,它总是被视为一种神奇的最终答案,就好像它让问题不再值得思考。这让我想知道:典型的“现代 JVM”和旧版 JVM 之间到底有什么区别?

Here's a phrase that I heard a lot throughout high school and university computer science classes:

"That's not an issue for modern JVMs."

Usually this would come up in discussions about overall performance or optimization strategies. It was always treated as a kind of magical final answer, though, as if it makes issues no longer worth thinking about. And that just leads me to wonder: what are the differences between the prototypical "modern JVM" and older JVMs, really?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

白衬杉格子梦 2024-08-23 04:51:29

现代 JIT 可以根据分析信息和从字节代码派生的其他信息积极优化机器代码:

  • 可以使用从预期使用情况派生的优化级别生成机器代码(它被大量使用,也许会被更多地使用) 。这很有帮助!
  • 可以内联对 object.getFoo() 的调用,以便将方法的内容直接放置在生成的代码中,而无需方法调用。这可以递归地完成,并且可能导致复杂的代码被实际完成的少数指令替换。
  • 垃圾收集工作有了很大改善。这意味着很多时间没有被花费。

A modern JIT can aggressively optimize machine code based on profiling information and other information derived from the byte code:

  • Machine code can be generated with an optimization level derived from the expected usage (it WAS used a lot, perhaps it will be used even more). This helps a lot!
  • Calls to object.getFoo() can be inlined so the contents of the method is placed directly in the generated code without the method call. This can be done recursively, and may result in complex code being replaced with just the few instructions actually done.
  • Garbage collection has improved immensely. This means in much time not being spent.
西瑶 2024-08-23 04:51:28

JVM 技术最显着的改进是 JIT:Just In Time 编译器。 JIT 在代码运行时对其进行优化,从而产生巨大的性能提升,这使得 Java(至少在某些领域)能够与 C/C++ 程序竞争。

关于动态优化(在代码运行时)与静态优化(在编译期间)的好处的有趣讨论可以在 Steve Yegge 的演讲中找到:http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html (其中,顺便说一句,它本身就很有趣)。

与 JIT 并非完全无关的其他 JVM 改进是更快地调度虚拟方法,无论是类方法还是接口方法。

The most significant improvement in JVM technology is the JIT: Just In Time compiler. The JIT optimizes the code as it runs, thereby producing huge performance gains which makes Java (at least in some domains) competitive with C/C++ programs.

An interesting discussion regarding the benefits of dynamic optimization (as the code runs) vs. static optimization (during compilation) can be found in Steve Yegge's talk: http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html (which, BTW is interesting in its own right).

Other JVM improvements, which are not entirely unrelated to JIT, is faster dispatch of virtual methods, both for class methods and interface methods.

愛上了 2024-08-23 04:51:28

无竞争同步过去很慢。
垃圾收集变得更快了。
热点优化变得更好。
一些非常古老的 JVM 专门有绿色线程

Uncontended synchronization used to be slow.
Garbage collection has gotten a lot faster.
Hotspot optimization has gotten better.
Some really old JVMs had green threads exclusively.

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