Re: JavaMemoryModel: Draft JSR-133 Cookbook for compiler writers

From: Yue Yang (yyang@cs.utah.edu)
Date: Fri Dec 06 2002 - 12:02:19 EST


I would like to point out an issue regarding the Write->Read reordering
for volatile variables.

Currently JSR133 forbids such reordering, even if the operations are for
different variables. This is reflected by the "No" entry in the first
reordering table in Doug's Cookbook. However, it is also suggested in the
Cookbook that a StoreLoad barrier is strictly necessary only between
stores and subsequent loads of the SAME location(s). So the question
is: do these two requirements provide the same semantics for volatile
field accesses? I think the answer is no, which can be shown from the
following example:

Initially, a = b = 0 (a and b are volatiles)

T1 T2
a = 1; b = 1;
StoreLoad; StoreLoad;
x = b; y = a;

Finally, can x = y = 0?

If the StoreLoad barrier is only for the same location, the interleaving
would be allowed. But if the StoreLoad is for all variables, the final
result would be impossible. So the "same location" barrier would not be
strong enough. It seems either the spec needs to be relaxed to allow
Write->Read reordering on different variables, or the StoreLoad barrier
for all locations must be used whenever necessary to ensure compliance.

-- Jason

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:42 EDT