吊装和重新订购同样的东西? [英] Are hoisting and reordering the same thing?
问题描述
我从 Effective Java 在没有同步的情况下,下面的序列A可以被虚拟机转换为序列B,这称为 hoisting
。我还在某处读到,如果变量未被声明为涉及变量的易失性指令,则可以重新排序。提升和重新排序是一样的吗?
I read from Effective Java that In the absence of synchronization the following sequence A below can be converted into sequence B by the virtual machine and this is called hoisting
. I also read somewhere that if variables are not declared as volatile instructions involving the variables can be reordered . Are hoisting and reordering the same thing?
while (!done) sequence A
i++;
if (!done)
while (true) sequence B
i++;
推荐答案
它们略有不同。
提升表示您已将某些操作从循环中拉出,因为循环本身不会影响操作的结果。在您的情况下,您将从while循环中提升条件测试。
Hoisting means that you have pulled some operation out of a loop because the loop itself does not affect the result of the operation. In your case, you are hoisting the conditional test out of the while loop.
重新排序意味着以某种方式更改指令序列这不会影响结果。通常,这将是相邻的指令,没有数据依赖性,例如,您执行以下两个语句的顺序无关紧要:
Re-ordering means changing the sequence of instructions in a way that does not affect the result. Typically this would be adjacent instructions with no data dependencies, e.g. it does not matter which order you perform the following two statements:
int a = x;
int b = y;
这篇关于吊装和重新订购同样的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!