skip to main content
research-article

Automatic inference of stationary fields: a generalization of java's final fields

Published:07 January 2008Publication History
Skip Abstract Section

Abstract

Java programmers can document that the relationship between two objects is unchanging by declaring the field that encodes that relationship to be final. This information can be used in program understanding and detection of errors in new code additions. Unfortunately, few fields in programs are actually declared final. Programs often contain fields that could be final, but are not declared so. Moreover, the definition of final has restrictions on initializationthat limit its applicability.

We introduce stationary fields as a generalization of final. A field in a program is stationary if, for every object that contains it, all writes to the field occur before all the reads. Unlike the definition of final fields, there can be multiple writes during initialization, and initialization can span multiple methods.

We have developed an efficient algorithm for inferring which fields are stationary in a program, based on the observation that many fields acquire their value very close to object creation. We presume that an object's initialization phase has concluded when its reference is saved in some heap object. We perform precise analysis only regarding recently created objects. Applying our algorithm to real-world Java programs demonstrates that stationary fields are more common than final fields: 44-59% vs. 11-17% respectively in our benchmarks.

These surprising results have several significant implications. First, substantial portions of Java programs appear to be written in a functional style. Second, initialization of these fields occurs very close to object creation, when very good alias information is available. These results open the door for more accurate and efficient pointer alias analysis.

References

  1. Jong-Deok Choi, Manish Gupta, Mauricio Serrano, Vugranam C. Sreedhar, and Sam Midkiff. Escape analysis for java. In OOPSLA '99: Proceedings of the 14th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pages 1--19, New York, NY, USA, 1999. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Jeffrey Dean, David Grove, and Craig Chambers. Optimization of objectoriented programs using static class hierarchy analysis. In ECOOP'95: Proceedings of the 9th European Conference on Object-Oriented Programming, pages 77--101, London, UK, 1995. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Dawson Engler, David Yu Chen, Seth Hallem, Andy Chou, and Bejamin Chelf. Bugs as deviant behavior: A general approach to inferring errors in systems code. In Proceedings of Eighteenth ACM Symposium on Operating System Principles, pages 57--72, October 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Jeffrey S. Foster, Manuel Fäahndrich, and Alexander Aiken. A theory of type qualifiers. In PLDI '99: Proceedings of the ACM SIGPLAN 1999 Conference on Programming Language Design and Implementation, pages 192--203, New York, NY, USA, 1999. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification, Third Edition. The Java Series. Addison-Wesley, Boston, Mass., 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Samuel P. Harbison and Guy Steele. C, A Reference Manual. Prentice-Hall, Inc., New York, NY, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. David L. Heine and Monica S. Lam. A practical flow-sensitive and context-sensitive C and C++ memory leak detector. In PLDI '03: Proceedings of the ACM SIGPLAN 2003 Conference on Programming Language Design and Implementation, pages 168--181, New York, NY, USA, 2003. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. David L. Heine and Monica S. Lam. Static detection of leaks in polymorphic containers. In ICSE '06: Proceedings of the 28th International Conference on Software Engineering, pages 252--261, New York, NY, USA, 2006. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Gunter Kniesel and Dirk Theisen. JAC - acess right based encapsulation for Java. Software - Practice and Experience, 31(6):555--576, 2001. Ted Kremenek, Paul Twohey, Godmar Back, Andrew Ng, and Dawson Engler. From uncertainty to belief: inferring the specification within. In USENIX'06: Proceedings of the 7th conference on USENIX Symposium on Operating Systems Design and Implementation, pages 12--12, Berkeley, CA, USA, 2006. USENIX Association. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Viktor Kuncak, Patrick Lam, and Martin Rinard. Role analysis. In POPL'02: Proceedings of the 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 17--32, New York, NY, USA, 2002. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Benjamin Livshits and Thomas Zimmermann. DynaMine: finding common error patterns by mining software revision histories. In ESEC/FSE--13: Proceedings of the 10th European software engineering conference held jointly with 13th ACM SIGSOFT international symposium on Foundations of software engineering, pages 296--305, New York, NY, USA, 2005. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Peter Muller and Arnt Poetzch-Heffter. A type system for controlling representation exposure in Java. In 2nd ECOOP Workshop on Formal Techniques for Java Programs, 2001. Igor Pechtchanski and Vivek Sarkar. Immutability specification and its applications. In JGI '02: Proceedings of the 2002 joint ACM-ISCOPE conference on Java Grande, pages 202--211, New York, NY, USA, 2002. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Sara Porat, Marina Biberstein, Larry Koved, and Bilha Mendelson. Automatic detection of immutable fields in Java. In CASCON '00: Proceedings of the 2000 Conference of the Centre for Advanced Studies on Collaborative research, page 10. IBM Press, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. Salcianu and M. Rinard. Purity and side effect analysis for Java programs. Lecture Notes in Computer Science, 3385:199--215, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Mats Skoglund and Tobias Wrigstad. A mode system for readonly references. In Akos Frohner, editor, Formal Techniques for Java Programs, number 2323 in Object-Oriented Technology, ECOOP 2001 Workshop Reader, pages 30--, Berlin, Heidelberg, New York, 2001. Springer-Verlag. ISBN 3-540-43675-8. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Dave Thomas, Chad Fowler, and Andy Hunt. Programming Ruby: The Pragmatic Programmer's Guide, Second Edition. Addison-Wesley, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Matthew S. Tschantz and Michael D. Ernst. Javari: Adding reference immutability to Java. In Object--Oriented Programming Systems, Languages, and Applications (OOPSLA 2005), pages 211--230, San Diego, CA, USA, October 18--20 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. John Whaley. Joeq: A virtual machine and compiler infrastructure. In Proceedings of the SIGPLAN Workshop on Interpreters, Virtual Machines, and Emulators, pages 58--66, June 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. John Whaley and Martin Rinard. Compositional pointer and escape analysis for java programs. In OOPSLA '99: Proceedings of the 14th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pages 187--206, New York, NY, USA, 1999. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Chadd C. Williams and Jeffrey K. Hollingsworth. Recovering system specific rules from software repositories. In MSR '05: Proceedings of the 2005 international workshop on Mining software repositories, pages 1--5, New York, NY, USA, 2005. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Jinlin Yang, David Evans, Deepali Bhardwaj, Thirumalesh Bhat, and Manuvir Das. Perracotta: mining temporal API rules from imperfect traces. In ICSE '06: Proceeding of the 28th international conference on Software engineering, pages 282--291, New York, NY, USA, 2006. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Automatic inference of stationary fields: a generalization of java's final fields

        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

        Full Access

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 43, Issue 1
          POPL '08
          January 2008
          420 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/1328897
          Issue’s Table of Contents
          • cover image ACM Conferences
            POPL '08: Proceedings of the 35th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
            January 2008
            448 pages
            ISBN:9781595936899
            DOI:10.1145/1328438

          Copyright © 2008 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 7 January 2008

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!