Re: JavaMemoryModel: required reads and writes (was: The choice we need to make on test cases 5 and 10)

From: Bill Pugh (
Date: Sat Aug 02 2003 - 21:15:18 EDT

At 3:16 PM -0700 8/2/03, Joseph Bowbeer wrote:
>FWIW - Here's more about running the races, requiring reads and writes, etc.
>Bill writes:
>> * To understand how an execution occurred,
>> you only need to reason about things that
>> - did occur in code that was executed, or
>> - were guaranteed to occur.
>=> Are all compiler transformations that lead to allowed executions legal?

yes. By definition

>Asked another way, To what extent can prescient knowledge be used to "fix"
>the outcome? (Or must the races be run?)

We need to allow the compiler to perform some transformations that
have effects that are indistinguishable from "fixing" the results of
races at compile time.

Since the semantics only talk about allowed behaviors, and not how
they are achieved, the compiler may perform transformations that
"fix" the results of races at compile time.

>Take case 11, for example.
>Knowing that x = 1 will occur, or simply knowing that r1 = r2 = r3 = r4 = 1
>is an allowed outcome, can the compiler rewrite this case as:
>r1 = 1
>r2 = 1
>r3 = 1
>r4 = 1
>(And then why even assign these registers if they're not used?)

We are assuming that the registers are all live at the end of each
thread, since we are reporting them as part of the observable
behavior of the program.

But in general, if a program does not depend on any input, it is
perfectly valid for a compiler to completely execute the program at
compile time, and generate the minimal executable that would produce
the same result as the execution that occurred at compile time.

JavaMemoryModel mailing list -

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