优秀Java VM中方法调用的开销是多少? [英] What is the overhead of a method call in a good Java VM?

查看:164
本文介绍了优秀Java VM中方法调用的开销是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能想出一个反汇编的机器码汇编列表吗?

Can someone come up with a disassembled machine code assembler listing?

我的意思是与C中的普通函数调用相比,必须有一些开销。

I mean there must be some overhead compared to the normal function call in C.

VM需要跟踪调用以查找热点,当它使用已编译的代码时,如果新加载的类需要重新编译,则需要提供更改已编译方法的方法。

The VM needs to track calls to find hotspots and when it uses compiled code it needs to provid ways to change the compiled method on fly if a new loaded class requires a recompilation.

我想在某处还有一个返回堆栈溢出检查。

I guess there is also a return stack overflow check somewhere.

编辑:我想我应该提到我是不是java程序员而是编译器编写者,并且想要找出为什么java应用程序如此缓慢而java微基准测试与本机编译代码相当。因此,在这里查看一些细节对我来说很重要,即使它们只需要几个几纳秒和一些额外的指令。

I think i should mention that i'm not a java programmer but a compiler writer and want to find out why java applications are so slow while the java micro benchmarks are comparable to native compiled code. So looking at some the details is important for me here, even if they take only a few dozend nanoseconds and a few additional instructions.

推荐答案

Java不直接编译为机器代码,它编译为字节码,然后在运行时解释或编译为机器代码 - 我不知道如何在运行时获取机器代码,我只是想象它为此大量的移位,改变字节,最终快速可靠地执行DAMN。

Java doesn't compile directly to machine code, it compiles to bytecode which is then either interpreted or compiled to machine code at runtime--I have no idea how to get to the machine code at runtime, I just imagine it as this huge mass of shifting, changing bytes that just ends up executing DAMN quickly and reliably.

一个小方法调用应该在运行时完全编译。如果可以解析或忽略足够的引用,即使是大型方法调用也可以由VM编写为内联机器代码。

A small method call should compile out completely at runtime. Even a large method call can be written as in-line machine code by the VM if enough references can be resolved or ignored.

使用Final可以提供很多帮助,因为它给出了虚拟机暗示它可能如何优化更多。

Using Final can help a lot because it gives the VM hints as to how it might optimize even more.

因为方法调用实际上可以完全编译出来并且最多只需要最低成本 - 你真的应该'担心它。当你有一个失败的性能规范时,只需编写最好的代码并担心性能问题(在这一点上,优化点比尝试消除代码中的方法调用要好得多,破坏了所涉及的每个人的代码库)。

Since a method call can actually compile out completely and at best has a minimal cost anyway--you really shouldn't worry about it. Just code your best and worry about performance problems when you have a failing performance spec (at which point spot-optimizing will do MUCH better than trying to eliminate method calls across your code, ruining your codebase for everyone involved).

请注意,由于运行时分析,它在某些非常罕见的情况下实际上比C中的类似代码更快(c编译器不会在运行时进行分析并手动优化代码你,你必须自己完成所有这些。)

Note that because of the runtime analysis, it can actually be faster in some very rare cases than similar code in C (The c compiler won't profile at runtime and hand-optimize your code for you, you have to do all that yourself).

这篇关于优秀Java VM中方法调用的开销是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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