Java静态调用是否比非静态调用更昂贵或更便宜? [英] Are Java static calls more or less expensive than non-static calls?
问题描述
这种或那种方式有任何性能上的好处吗?它是编译器/ VM特定的吗?我正在使用Hotspot。
Is there any performance benefit one way or another? Is it compiler/VM specific? I am using Hotspot.
推荐答案
首先:你不应该在做的基础上做出静态与非静态的选择性能。
First: you shouldn't be making the choice of static vs non-static on the basis of performance.
第二:在实践中,它不会有任何区别。热点可以选择优化方式,使一个方法的静态调用更快,另一个方法的非静态调用更快。
Second: in practice, it won't make any difference. Hotspot may choose to optimize in ways that make static calls faster for one method, non-static calls faster for another.
第三:围绕静态与非静态的大多数神话static基于非常旧的JVM(在Hotspot所做的优化附近没有做任何事情),或者是一些关于C ++的记忆琐事(其中动态调用使用一个比静态调用更多的内存访问) )。
Third: much of the mythos surrounding static versus non-static are based either on very old JVMs (which did not do anywhere near the optimization that Hotspot does), or some remembered trivia about C++ (in which a dynamic call uses one more memory access than a static call).
这篇关于Java静态调用是否比非静态调用更昂贵或更便宜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!