On Validity of Program Transformations in the Java Memory Model

We analyse the validity of several common program transformations in multi-threaded Java, as defined by the Memory Model section of the Java Language Specification. The main design goal of the Java Memory Model (JMM) was to allow as many optimisations as possible. However, we find that commonly used optimisations, such as common subexpression elimination, can introduce new behaviours and so are invalid for Java. In this paper, we describe several kinds of transformations and explain the problems with a number of counterexamples. More positively, we also examine some valid transformations, and prove their validity. Our study contributes to the understanding of the JMM, and has the practical impact of revealing some cases where the Sun Hotspot JVM does not comply with the Java Memory Model.

[1]  Alexander Knapp,et al.  The Java Memory Model: Operationally, Denotationally, Axiomatically , 2007, ESOP.

[2]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[3]  Guy L. Steele,et al.  Java(TM) Language Specification , 2005 .

[4]  Jeremy Manson,et al.  The Java memory model , 2005, POPL '05.

[5]  Sarita V. Adve,et al.  Shared Memory Consistency Models: A Tutorial , 1996, Computer.

[6]  Julian Rathke,et al.  A fully abstract may testing semantics for concurrent objects , 2002, Proceedings 17th Annual IEEE Symposium on Logic in Computer Science.

[7]  Guy L. Steele,et al.  Java(TM) Language Specification, The (3rd Edition) (Java (Addison-Wesley)) , 2005 .

[8]  John C. Reynolds Toward a Grainless Semantics for Shared-Variable Concurrency , 2004, FSTTCS.

[9]  Mark D. Hill,et al.  A Unified Formalization of Four Shared-Memory Models , 1993, IEEE Trans. Parallel Distributed Syst..

[10]  Stephen D. Brookes Full Abstraction for a Shared-Variable Parallel Language , 1996, Inf. Comput..

[11]  David Aspinall,et al.  Formalising Java's Data Race Free Guarantee , 2007, TPHOLs.

[12]  Xiaowei Shen,et al.  Improving the Java memory model using CRF , 2000, OOPSLA '00.

[13]  Kousha Etessami,et al.  Verifying Probabilistic Procedural Programs , 2004, FSTTCS.

[14]  Cliff Click,et al.  The java hotspot TM server compiler , 2001 .

[15]  Cliff Click,et al.  Global code motion/global value numbering , 1995, PLDI '95.

[16]  Ken Kennedy,et al.  Optimizing Compilers for Modern Architectures: A Dependence-based Approach , 2001 .

[17]  William Pugh The Java memory model is fatally flawed , 2000 .

[18]  Stephen Brookes A semantics for concurrent separation logic , 2007, Theor. Comput. Sci..

[19]  Radha Jagadeesan,et al.  A theory of memory models , 2007, PPOPP.

[20]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[21]  David Aspinall Java Memory Model Examples: Good, Bad and Ugly , 2007 .