At 2:53 PM +1100 11/12/99, David Holmes wrote:
>Doesn't the left-to-right evaluation of expressions define the order in
>which the reads must occur? So the compiler can't reorder them.
The compiler can't reorder them unless it can prove that the results of that
reordering are not observable.
Without class initialization, you could be guaranteed that no one could
prove that you had reordered the variables.
In the previous examples, there wasn't really a compelling example. But how
about A.x+B.y+A.x. In compiling code for that, it would be very tempting to
avoid the reload of A.x. But you can't if reading B.y might modify A.x.
I tested HotSpot and the ExactVM, and haven't caught them doing anything wrong
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:23 EDT