Re: JavaMemoryModel: Why I want to prohibit test cases 5 and 10

From: Jerry Schwarz (jerry.schwarz@oracle.com)
Date: Thu Jan 22 2004 - 23:04:44 EST


Apologies, I inadvertently sent an incomplete message. Ignore the garbage
that starts with "what scares me". I haven't yet constructed an example to
demonstrate my concern which is that a compiler does an analysis based on
"forbidden reads" that indicates a prescient read is possible. Determines
based on the value of the prescient read that something is thread local,
but then doesn't insert the prescient read.

At 09:03 PM 1/17/2004, Bill Pugh wrote:
>OK, I don't have a formal proof that allowing 5 and 10 would cause the
>roof to collapse.
>
>But here is an example that gives me the willies:
>
>Initially, x = y = z = 0
>
>Thread 1
>r1 = z
>r2= 42 // really assume this is really a call to allocate
> // and initialize an object, and 42 is a reference to that object
>if r1 == 1
> x = r2
>
>Thread 2
>z = 1
>
>Thread 3
>r3 = x
>y = r3
>
>Thread 4
>r4 = y
>x = r4
>
>Scary behavior:
> r2 == r3 == r4 == 42, r1 == 0
>
>OK, the problem here is that from the viewpoint of thread 1, it sure looks
>like in the cases where r1 == 0, the object allocated in thread 1 is
>thread local, and it can freely allocate it in thread local storage and
>reclaim it immediately after it is no longer used by thread 1.
>
>However, I believe that Sarita's model would allow threads 3 and 4 to get
>a reference to the allocated object, even in the case where r1 = 0.
>
>This scares me.

It shouldn't scare you. Just because the model says that Thread s 3 and 4
get a reference to "42" doesn't mean that they will be able to in some
implementation. If the compiler, just looking at thread 1 believes "42" is
thread local, then it be generating code that indeed prevents "42" from
escaping.

What scares me is this

Thread 1

r1 = x
if ( r1 = 1 )

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

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



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