Abstract
Happens-before memory model (HMM) is used as the basis of Java memory model (JMM). Although HMM itself is simple, some complex axioms have to be introduced in JMM to prevent the causality loop, which causes absurd out-of-thin-air reads that may break the type safety and security guarantee of Java. The resulting JMM is complex and difficult to understand. It also has many anti-intuitive behaviors, as demonstrated by the “ugly examples” by Aspinall and Ševčík [1]. Furthermore, HMM (and JMM) specifies only what execution traces are acceptable, but says nothing about how these traces are generated. This gap makes it difficult for static reasoning about programs.
In this paper we present OHMM, an operational variation of HMM. The model is specified by giving an operational semantics to a language running on an abstract machine designed to simulate HMM. Thanks to its generative nature, the model naturally prevents out-of-thin-air reads. On the other hand, it uses a novel replay mechanism to allow instructions to be executed multiple times, which can be used to modelmany useful speculations and optimization. The model is weaker than JMM for lockless programs, thus can accommodate more optimization, such as the reordering of independent memory accesses that is not valid in JMM. Program behaviors are more natural in this model than in JMM, and many of the anti-intuitive examples in JMM are no longer valid here. We hope OHMM can serve as the basis for new memory models for Java-like languages.
Similar content being viewed by others
References
Aspinall D, Ševčík J. Java memory model examples: good, bad and ugly. In: Proceedings of Verification and Analysis of Multi-threaded Java-like Programs. 2007, 66–80
Lamport L. How to make a multiprocessor computer that correctly executes multiprocess programs. IEEE Transactions on Computers, 1979, 28(9): 690–691
Boehm H J. Threads cannot be implemented as a library. In: Proceedings of Programming Language Design and Implementation. 2005, 261–268
Adve S V, Gharachorloo K. Shared memory consistency models: a tutorial. IEEE Transactions on Computers, 1996, 29(12): 66–76
Manson J, Pugh W, Adve S V. The Java memory model. In: Proceedings of the 32nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 2005, 378–391
Cenciarelli P, Knapp A, Sibilio E. The Java memory model: operationally, denotationally, axiomatically. In: Proceedings of the 16th European Symposium on Programming. 2007, 331–346
Zhang Y, Feng X. An operational approach to happens-before memory model. In: Proceedings of the 7th International Symposium on Theoretical Aspects of Software Engineering. 2013, 121–128
Lamport L. Time, clocks, and the ordering of events in a distributed system. Communications of the ACM, 1978, 21(7): 558–565
Aspinall D, Ševčík J. Formalising Java’s data race free guarantee. In: Proceedings of Theorem Proving in Higher Order Logics. 2007, 22–37
Huisman M, Petri G. The Java memory model: a formal explanation. In: Proceedings of Verification and Analysis of Multi-threaded Javalike Programs. 2007, 81–96
Manson J. The Java Memory Model. Dissertation for the Doctoral Degree. College Park: University of Maryland, 2004
Ševčík J, Aspinall D. On validity of program transformations in the Java memory model. In: Proceedings of the 22nd European Conference on Object-Oriented Programming. 2008, 27–51
Vafeiadis V, Balabonski T, Chakraborty S, Morisset R, Nardelli F Z. Common compiler optimisations are invalid in the C11 memory model and what we can do about it. In: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 2015, 209–220
Yang Y, Gopalakrishnan G, Lindstrom G. Specifying Java thread semantics using a uniform memory model. In: Proceedings of Joint ACM Java Grande — ISCOPE 2002 Conference. 2002, 192–201
Lochbihler A. Java and the Java memory model — a unified, machinechecked formalisation. In: Proceedings of the 21st European Symposium on Programming. 2012, 497–517
Saraswat V A, Jagadeesan R, Michael M M, Praun V C. A theory of memory models. In: Proceedings of the 12th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming. 2007, 161–172
Jagadeesan R, Pitcher C, Riely J. Generative operational semantics for relaxed memory models. In: Proceedings of the 19th European Symposium on Programming. 2010, 307–326
Sarkar S, Sewell P, Alglave J, Maranget L, Williams D. Understanding power multiprocessors. In: Proceedings of the 32nd ACM SIGPLAN conference on Programming language design and implementation. 2011, 175–186
Author information
Authors and Affiliations
Corresponding author
Additional information
Yang Zhang is a PhD student in computer science at University of Science and Technology of China, China. His research interests are in the area of programming languages and formal methods. He is interested in relaxed memory model in particular.
Xinyu Feng is a professor in computer science at University of Science and Technology of China, China. His research interests are in the area of programming languages, formal verification, and concurrency theories.
Rights and permissions
About this article
Cite this article
Zhang, Y., Feng, X. An operational happens-before memory model. Front. Comput. Sci. 10, 54–81 (2016). https://doi.org/10.1007/s11704-015-4492-4
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11704-015-4492-4