skip to main content
10.1145/1040305.1040336acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
Article

The Java memory model

Published:12 January 2005Publication History

ABSTRACT

This paper describes the new Java memory model, which has been revised as part of Java 5.0. The model specifies the legal behaviors for a multithreaded program; it defines the semantics of multithreaded Java programs and partially determines legal implementations of Java virtual machines and compilers.The new Java model provides a simple interface for correctly synchronized programs -- it guarantees sequential consistency to data-race-free programs. Its novel contribution is requiring that the behavior of incorrectly synchronized programs be bounded by a well defined notion of causality. The causality requirement is strong enough to respect the safety and security properties of Java and weak enough to allow standard compiler and hardware optimizations. To our knowledge, other models are either too weak because they do not provide for sufficient safety/security, or are too strong because they rely on a strong notion of data and control dependences that precludes some standard compiler transformations.Although the majority of what is currently done in compilers is legal, the new model introduces significant differences, and clearly defines the boundaries of legal transformations. For example, the commonly accepted definition for control dependence is incorrect for Java, and transformations based on it may be invalid.In addition to providing the official memory model for Java, we believe the model described here could prove to be a useful basis for other programming languages that currently lack well-defined models, such as C++ and C#.

References

  1. Ada Joint Program Office. Ada 95 Rationale. Intermetrics, Inc., Cambridge, Massachusetts, 1995.]]Google ScholarGoogle Scholar
  2. Sarita Adve. Designing Memory Consistency Models for Shared-Memory Multiprocessors. PhD thesis, University of Wisconsin, Madison, December 1993. Ph.D. Thesis.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Sarita Adve and Kourosh Gharachorloo. Shared memory consistency models: A tutorial. IEEE Computer, 29(12):66--76, 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Sarita Adve and Mark Hill. Weak ordering---A new definition. In Proc. of the 17th Annual Int'l Symp. on Computer Architecture (ISCA'90), pages 2--14, 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Sarita V. Adve. The SC- memory model for Java, 2004. http://www.cs.uiuc.edu/~sadve/jmm.]]Google ScholarGoogle Scholar
  6. Sarita V. Adve and Mark D. Hill. A unified formalization of four shared-memory models. IEEE Trans. on Parallel and Distributed Systems, 4(6):613--624, June 1993.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Sarita V. Adve and Mark D. Hill. Sufficient conditions for implementing the data-race-free-1 memory model. Technical Report #1107, Computer Sciences Department, University of Wisconsin-Madison, September 1992.]]Google ScholarGoogle Scholar
  8. Arvind, Jan-Willem Maessen, and Xiaowei Shen. Improving the Java memory model using CRF. In OOPSLA, pages 1--12, October 2000.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. John K. Bennett, John B. Carter, and Willy Zwanaepoel. Adaptive software cache management for distributed shared memory architectures. In Proc. 17th Annual Intl. Symp. on Computer Architecture, May 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Gianfranco Bilardi and Keshav Pingali. A Framework for Generalized Control Dependence. In ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation, Philadelphia, Pennsylvania, United States, June 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Christopher Brumme. C# memory model. http://blogs.msdn.com/cbrumme/archive/2003/05/17/51445.apx.]]Google ScholarGoogle Scholar
  12. Michel Dubois, Christoph Scheurich, and Faye A. Briggs. Memory access buffering in multiprocessors. In Proc. 13th Ann. Intl. Symp. on Computer Architecture, pages 434--442, June 1986.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. ECMA. Common Language Infrastructure (CLI), December 2002. http://www.ecma-international.org/publications/standards/Ecma-335.htm.]]Google ScholarGoogle Scholar
  14. Kourosh Gharachorloo. Memory consistency models for shared-memory multiprocessors. PhD thesis, Stanford University, 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Kourosh Gharachorloo, Sarita V. Adve, Anoop Gupta, John L. Hennessy, and Mark D. Hill. Programming for different memory consistency models. Journal of Parallel and Distributed Computing, 15(4):399--407, August 1992.]]Google ScholarGoogle ScholarCross RefCross Ref
  16. Kourosh Gharachorloo, Anoop Gupta, and John Hennessy. Two techniques to enhance the performance of memory consistency models. In Proc. Intl. Conf. on Parallel Processing, pages I355--I364, 1991.]]Google ScholarGoogle Scholar
  17. Kourosh Gharachorloo, Daniel Lenoski, James Laudon, Phillip Gibbons, Anoop Gupta, and John Hennessy. Memory consistency and event ordering in scalable shared-memory multiprocessors. In Proc. 17th Ann. Intl. Symp. on Computer Architecture, pages 15--26, May 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. James Gosling, Bill Joy, and Guy Steele. The Java Language Specification. Addison Wesley, 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. IBM System/370 Principles of Operation, May 1983. Publication Number GA22-7000-9, File Number S370-01.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Java Specification Request (JSR) 133. Java Memory Model and Thread Specification Revision, 2004. http://jcp.org/jsr/detail/133.jsp.]]Google ScholarGoogle Scholar
  21. The Java memory model. Mailing list and web page. http://www.cs.umd.edu/users/pugh/java/memoryModel.]]Google ScholarGoogle Scholar
  22. Pete Keleher, Alan L. Cox, and Willy Zwaenepoel. Lazy release consistency for software distributed shared memory. In Proc. 19th Ann. Intl. Symp. on Computer Architecture, pages 13--21, 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. B. W. Kernighan and D. M. Ritchie. The C Programming Language. Prentice Hall, second edition, 1988.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Vishnu Kotrajaras. Towards an Improved Memory Model for Java. PhD thesis, Department of Computing, Imperial College, August 2001.]]Google ScholarGoogle Scholar
  25. Leslie Lamport. Time, clocks, and the ordering of events in a distributed system. CACM, 21(7):558--564, 1978.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Leslie Lamport. How to make a multiprocessor computer that correctly executes multiprocess programs. IEEE Transactions on Computers, 9(29):690--691, 1979.]]Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Bil Lewis and Daniel J. Berg. Multithreaded programming with pthreads. Sun Microsystems, 2550 Garcia Avenue, Mountain View, CA 94043, USA, 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Jeremy Manson and William Pugh. Core semantics of multithreaded Java. In ACM Java Grande Conference, June 2001.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Jeremy Manson and William Pugh. Semantics of Multithreaded Java. Technical Report CS-TR-4215, Dept. of Computer Science, University of Maryland, College Park, March 2001.]]Google ScholarGoogle Scholar
  30. Jeremy Manson and William Pugh. Requirements for Programming Language Memory Models. In PODC Workshop on Concurrency and Synchronization in Java Programs, St. John's, Newfoundland, Canada, July 2004.]]Google ScholarGoogle Scholar
  31. C. May et al., editors. The PowerPC Architecture: A Specification for a New Family of RISC Processors. Morgan Kaufmann, San Francisco, 1994.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Andy Podgurski and Lori Clarke. A formal model of program dependences and its implications for software testing debugging and maintenance. IEEE Transactions on Software Engineering, 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. William Pugh. Fixing the Java memory model. In ACM Java Grande Conference, June 1999.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. William Pugh. The Java memory model is fatally flawed. Concurrency: Practice and Experience, 12(1):1--11, 2000.]]Google ScholarGoogle Scholar
  35. Parthasarathy Ranganathan, Vijay S. Pai, and Sarita V. Adve. Using speculative retirement and larger instruction windows to narrow the performance gap between memory consistency models. In Proceedings of the 9th Annual ACM Symposium on Parallel Algorithms and Architectures, pages 199--210, 1997.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Vijay Saraswat. Concurrent Constraint-based Memory Machines: A framework for Java Memory Models. Technical report, IBM TJ Watson Research Center, March 2004.]]Google ScholarGoogle Scholar
  37. Douglas Schmidt and Tim Harrison. Double-checked locking: An optimization pattern for efficiently initializing and accessing thread-safe objects. In 3rd Annual Pattern Languages of Program Design Conference, 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Dennis Shasha and Marc Snir. Efficient and correct execution of parallel programs that share memory. ACM Trans. on Programming Languages and Systems, 10(2):282--312, April 1988.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Xiaowei Shen, Arvind, and Larry Rudolph. Commit-reconcile & fences (CRF): A new memory model for architects and compiler writers. Proceedings of the 26th International Symposium on Computer Archite cture, 1999.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. R. L. Sites and R. T. Witek, editors. Alpha AXP Architecture Reference Manual. Digital Press, Boston, 1995. 2nd edition.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Bjarne Stroustrup. The C++ Programming Language. Addison-Wesley Longman, Reading Mass. USA, 3rd edition, 1997.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Z. Sura, C.-L. Wong, X. Fang, J. Lee, S. Midkiff, and D. Padua. Automatic implementation of programming language consistency models. In Proc. of the 15th International Workshop on Languages and Compilers for Parallel Computing (LCPC'02), 2002. To appear Lecture Notes in Computer Science, Springer-Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. David Weaver and Tom Germond. The SPARC Architecture Manual, version 9. Prentice-Hall, 1994.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Yue Yang, Ganesh Gopalakrishnan, and Gary Lindstrom. Specifying Java thread semantics using a uniform memory model. In ACM Java Grande Conference, November 2001.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Yue Yang, Ganesh Gopalakrishnan, and Gary Lindstrom. Formalizing the Java memory model for multithreaded program correctness and optimization. Technical Report UUCS-02-011, University of Utah, April 2002.]]Google ScholarGoogle Scholar

Index Terms

  1. The Java memory model

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in
            • Published in

              cover image ACM Conferences
              POPL '05: Proceedings of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages
              January 2005
              402 pages
              ISBN:158113830X
              DOI:10.1145/1040305
              • General Chair:
              • Jens Palsberg,
              • Program Chair:
              • Martín Abadi
              • cover image ACM SIGPLAN Notices
                ACM SIGPLAN Notices  Volume 40, Issue 1
                Proceedings of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages
                January 2005
                391 pages
                ISSN:0362-1340
                EISSN:1558-1160
                DOI:10.1145/1047659
                Issue’s Table of Contents

              Copyright © 2005 ACM

              Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 12 January 2005

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • Article

              Acceptance Rates

              Overall Acceptance Rate824of4,130submissions,20%

              Upcoming Conference

              POPL '25

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader