Art Java Concurrency (v) reordering

1, reordering: means compilers and processors a means to optimize the performance of the program and reordering sequence of instructions.

 

2, data dependency: two access operations with a variable, and the two operations by a write operation, then there is data dependency between the two operations.

(1) Category: read-after-write , write-write , read before write .

(2) a compiler and a processor at the reorder, data dependencies will follow, will not change the order of execution of two operations present the data dependencies.

(3) data dependencies only for a single processor instruction sequence executed in a single thread operation execution.

 

3, as-if-serial: No matter how reorder the results (single-threaded) program can not be changed, it is multi-threaded execution results may be changed.

 

4, volatile reordering rules:

(1) volatile operation prior written will not be compiled thinks highly volatile after ordering to write.

(2) volatile operation after reading can not be sorted before compiled discouraged to volatile read.

(3) The first is a volatile write operation, the second operation is a volatile read, no reordering.

 

5, final reordering domain rules:

(1) In the constructor written in the field for a final, subsequent to this configuration referenced object is assigned to a reference variable, the reordering is not between these two operations.

(2) reading a first target domain comprising a final reference, and then read the final initial field, the reordering is not between these two operations.

Guess you like

Origin www.cnblogs.com/xy80hou/p/11221327.html