Re: JavaMemoryModel: New one page version of Manson/Pugh core model

From: Bill Pugh (pugh@cs.umd.edu)
Date: Fri Aug 01 2003 - 12:00:04 EDT


At 2:35 AM -0700 8/1/03, Joseph Bowbeer wrote:
>Bill writes:
>
>> We will allow causality examples 1-3
>
>After some thought, I'm uncomfortable with allowing the inter-thread
>analysis that is required to produce the result in case 1.

Let me give you the compelling motivation for test case 1.

In Java, potential run-time exceptions represent implicit control
flow. Any time there is a pointer deference, array access, or store
into an array of objects, there is an implicit check and exception
branch.

These checks inhibit code motion.

We want to allow inter-thread analysis that determines whether a
reference is definitely non-null, and remove the implicit
null-pointer check in front of any dereference of that reference.

For example, assume p is a reference to a Point object.

If you know that p is initialized to a non-null value, and every
assignment to p is definitely non-null, then you want to be able to
remove the null pointer check.

For example, consider:

Initially, Point p = new Point(0,0), int a = 0

Thread 1:
r1 = p
r2 = r1.x
a = 1

Thread 2:
r3 = p
r4 = a
r3.x = r4

Thread 3: // just put in to ensure there is a race on p
r5 = p
p = r5

Can we allow r4 = r2 = 1?

If the compiler can show that the dereference r1.x will never throw a
null pointer exception, then it should be allowed to move a = 1
early, which would allow r4 = r2 = 1.

But if you make all the implicit checks explicit, you get:

Initially, Point p = new Point(0,0), int a = 0

Thread 1:
r1 = p
if (r1 != null)
   r2 = r1.x
   a = 1

Thread 2:
r3 = p
r4 = a
if (r3 != null)
   r3.x = r4

Thread 3: // just put in to ensure there is a race on p
r5 = p
p = r5

Which is exactly the analog of test case 1.

So you can't forbid test case 1 without forbidding interthread
analysis to remove runtime exception checks.

So I think we need to allow test case 1.

Joe, can you explain what about test case 1 makes you uncomfortable?

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



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