Are hoisting and reordering the same thing?

前端 未结 3 629
北海茫月
北海茫月 2020-12-09 05:14

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 <

3条回答
  •  佛祖请我去吃肉
    2020-12-09 05:47

    They are slightly different.

    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;
    

提交回复
热议问题