智能 JVM 和 JIT 微优化
随着时间的推移,Sun 的 JVM 和 JIT 已经变得相当智能。 过去作为必要的微优化而成为常识的事情不再需要,因为它会为您处理好。
例如,过去的情况是,您应该将所有可能的类标记为 Final,以便 JVM 内联尽可能多的代码。 然而现在,JIT 根据运行时加载的类来知道您的类是否是最终的,如果您加载一个类以使原始类成为非最终类,它会取消内联方法并将其标记为最终的。
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.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Java 在内联方面更聪明,因为它可以
甚至是动态生成的。
在 C++ 中)
Java is smarter at inlining as it can
or even dynamically generated.
in C++)
这令人印象深刻。 所有这些都是您在 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.Oracle 有一个关于 Hotspot JVM 中使用的性能技术的 wiki。
Oracle has a wiki on Performance techniques used in the Hotspot JVM.