智能JVM和JIT微优化 [英] Smart JVM and JIT Micro-Optimizations

查看:120
本文介绍了智能JVM和JIT微优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着时间的推移,Sun的JVM和JIT变得非常聪明。不再需要将常识作为必要的微优化的东西,因为它会得到照顾。

Over time, Sun's JVM and JIT have gotten pretty smart. Things that used to be common knowledge as being a necessary micro-optimization are no longer needed, because it gets taken care of for you.

例如,它曾经是您应该将所有可能的类标记为final的情况,因此JVM会尽可能多地内联代码。但是现在,JIT根据在运行时加载的类知道你的类是否是最终的,如果你加载一个类使原始类不可能,它会取消内联方法并取消标记为最终。

For example, it used to be the case that you should mark all possible classes as final, so the JVM inlines as much code as possible. However now, the JIT knows whether your class is final based on what classes get loaded in at runtime, and if you load a class to make the original one non-final-able, it un-inlines the methods and un-marks it as final.

JVM或JIT为您做了哪些其他智能微优化?

What other smart micro-optimizations does the JVM or JIT do for you?

编辑:我把它做成了社区维基;我想随着时间的推移收集它们。

EDIT: I made this a community wiki; I'd like to collect these over time.

推荐答案

这令人印象深刻。所有这些都是你在C ++中不能用做的事情(当然与Java一样)。请记住,Java的早期版本由于没有这些东西而开始了缓慢的声誉,并且随着时间的推移我们会不断改进 。这仍然是一个很大的研究领域。

It's beyond impressive. All of these are things you can't do in C++ (certainly to the same extent Java does). Keep in mind that early versions of Java started the "slow" reputation by not having these things, and we keep improving significantly over time. This is still a big research area.

  • Efficient interface dispatch.
  • Inlining and direct dispatch of virtual method calls.
  • Very fast object allocation with bump pointers (slide 19 or so) and escape analysis.

这篇关于智能JVM和JIT微优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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