Are hoisting and reordering the same thing?

空扰寡人 提交于 2019-11-28 07:42:36

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;

The term "reordering" as it's used in the Java Memory Model refers to all possible optimizations that may affect correctness of improperly synchronized programs.

So, reordering in this sense is a generic term that includes optimizations such as hoisting, effects of out-of-order execution, inconsistencies caused by memory hierarchy (i.e. caches), and so on.

amicngh

Reordering relates to performance of execution where as reordering doesn't impact performance.

Hoisting is done to reordering of Memory barrier instructions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!