JavaMemoryModel: circular reasoning in compilers & memory models...

From: Cliff Click (cliff.click@sun.com)
Date: Tue Aug 06 2002 - 23:21:13 EDT


Just for kicks, here's a program that invites circular reasoning
from optimizing compilers. It takes advantage of uninitialized
variables to give the optimizer the choice to execute statement
S1 OR statement S2, but not both and not neither:

void main() {
  int x; // uninitialized

  while( P ) { // some predicate P
    if( x ) { S1; x==1; }
    else { S2; x==0; }
  }
}

Now an optimizer can choose to init x to some non-zero value
and this program infinitely loops on S1, and it's easy to
prove with conditional constant propagation (standard optimization
in any optimizing compiler). Or the optimizer can choose to
init x to zero and then it can easily prove that the loop
only executes S2.

I've seen systems assume 'x' was unknown (kept both S1 and S2,
but at runtime which one executed depended on stack junk), or
assume 'x' was zero (kept S2 only). Nobody kept S1. This
code crashed my PhD compiler and caused much head scratching
until I figured out what to do with it.

Not sure if it's relevent to circular reasoning in memory models,
but the cycle looks awfully similar.

Cliff

-- 
Dr. Cliff Click      Chief Architect, HotSpot Server  Sun Microsystems, Inc.
Cliff.Click@Sun.COM  Senior Staff Engineer            4150 Network Circle
(408) 276-7046       MS USCA14-102                    Santa Clara, CA 95054

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



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