本文介绍了Java编译器可以对函数调用进行重新排序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Java编译器实际上可以对代码指令进行重新排序。但是Java可以对函数调用重新排序吗?

I know that java compiler can actually reorder code instructions. But can java reorder function calls?

例如:

...
//these lines may be reordered
a=7;
b=5;
...
//but what about this?
callOne();
callTwo();


推荐答案

如果可以确定这样做没有效果结果,然后是。既然不能,编译器就不会。

If it can determine that doing so would have no effect on the result, then yes. Since it can't, the compiler won't.

JIT可以内联调用,因为它知道方法是否被覆盖,如果合适的话,它可以重新排列代码。由于只有在可以保证结果保持不变的情况下,它才能这样做,所以您为什么还要关心呢?无论如何,您看不到任何区别。

JIT can however inline the calls, since it knows if the methods are overridden, and it can then rearrange the code, if it sees fit. Since it can only do so if it can guarantee that result stays the same, why would you even care? You can't see a difference anyway.

这篇关于Java编译器可以对函数调用进行重新排序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 21:53