skip to main content
research-article

Ownership and immutability in generic Java

Authors Info & Claims
Published:17 October 2010Publication History
Skip Abstract Section

Abstract

The Java language lacks the important notions of ownership (an object owns its representation to prevent unwanted aliasing) and immutability (the division into mutable, immutable, and readonly data and references). Programmers are prone to design errors, such as representation exposure or violation of immutability contracts. This paper presents Ownership Immutability Generic Java (OIGJ), a backward-compatible purely-static language extension supporting ownership and immutability. We formally defined a core calculus for OIGJ, based on Featherweight Java, and proved it sound. We also implemented OIGJ and performed case studies on 33,000 lines of code.

Creation of immutable cyclic structures requires a "cooking phase" in which the structure is mutated but the outside world cannot observe this mutation. OIGJ uses ownership information to facilitate creation of immutable cyclic structures, by safely prolonging the cooking phase even after the constructor finishes.

OIGJ is easy for a programmer to use, and it is easy to implement (flow-insensitive, adding only 14 rules to those of Java). Yet, OIGJ is more expressive than previous ownership languages, in the sense that it can type-check more good code. OIGJ can express the factory and visitor patterns, and OIGJ can type-check Sun's java.util collections (except for the clone method) without refactoring and with only a small number of annotations. Previous work required major refactoring of existing code in order to fit its ownership restrictions. Forcing refactoring of well-designed code is undesirable because it costs programmer effort, degrades the design, and hinders adoption in the mainstream community.

References

  1. }}Chandrasekhar Boyapati. SafeJava: A Unified Type System for Safe Programming. PhD thesis, MIT Dept. of EECS, Feb. 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}Chandrasekhar Boyapati, Robert Lee, and Martin Rinard. Ownership types for safe programming: Preventing data races and deadlocks. In OOPSLA, pages 211--230, Oct. 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}Chandrasekhar Boyapati, Barbara Liskov, and Liuba Shrira. Ownership types for object encapsulation. In POPL, pages 213--223, Jan. 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}John Boyland. Why we should not add readonly to Java (yet). In FTfJP, July 2005.Google ScholarGoogle Scholar
  5. }}John Boyland, James Noble, and William Retert. Capabilities for sharing: A generalisation of uniqueness and read-only. In ECOOP, pages 2--27, June 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}John Boyland, William Retert, and Yang Zhao. Comprehending annotations on object-oriented programs using fractional permissions. In IWACO, pages 1--11, July 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. }}Gilad Bracha, Martin Odersky, David Stoutamire, and Philip Wadler. Making the future safe for the past: Adding genericity to the Java programming language. In OOPSLA, pages 183--200, Oct. 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}Nicholas Cameron and Sophia Drossopoulou. Existential quantification for variant ownership. In ESOP, pages 128--142, Mar. 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. }}Nicholas Cameron, Sophia Drossopoulou, and Erik Ernst. A model for Java with wildcards. In ECOOP, pages 2--26, July 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}Nicholas R. Cameron, Sophia Drossopoulou, James Noble, and Matthew J. Smith. Multiple ownership. In OOPSLA, pages 441--460, Oct. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}Dave Clarke and Sophia Drossopoulou. Ownership, encapsulation and the disjointness of type and effect. In OOPSLA, pages 292--310, Oct. 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}Dave Clarke and Tobias Wrigstad. External uniqueness is unique enough. In ECOOP, pages 176--200, July 2003.Google ScholarGoogle ScholarCross RefCross Ref
  13. }}David G. Clarke, John M. Potter, and James Noble. Ownership types for flexible alias protection. In OOPSLA, pages 48--64, Oct. 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. }}Werner Dietl, Sophia Drossopoulou, and Peter Muller. Generic Universe Types. In ECOOP, pages 28--53, Aug. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}Michael D. Ernst. Type Annotations specification (JSR 308). http://types.cs.washington.edu/jsr308/, Sep. 12, 2008.Google ScholarGoogle Scholar
  16. }}Manuel Fahndrich and Songtao Xia. Establishing object invariants with delayed types. In OOPSLA, pages 337--350, Oct. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. }}Erich Gamma, Richard Helm, Ralph E. Johnson, and John Vlissides. Design Patterns. Addison-Wesley, Reading, MA, 1995.Google ScholarGoogle Scholar
  18. }}Christian Haack and Erik Poll. Type-based object immutability with flexible initialization. In ECOOP, pages 520--545, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. }}Christian Haack, Erik Poll, Jan Schafer, and Aleksy Schubert. Immutable objects for a Java-like language. In ESOP, pages 347--362, Mar. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. }}Shan Shan Huang, David Zook, and Yannis Smaragdakis. cJ: Enhancing Java with safe type conditions. In AOSD, pages 185--198, Mar. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. }}Atsushi Igarashi, Benjamin C. Pierce, and Philip Wadler. Featherweight Java: a minimal core calculus for Java and GJ. ACM TOPLAS, 23(3):396--450, May 2001. ISSN 0164-0925. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. }}Gunter Kniesel and Dirk Theisen. JAC - access right based encapsulation for Java. Software: Practice and Experience, 31(6):555--576, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. }}K. Rustan M. Leino, Peter Muller, and Angela Wallenburg. Flexible immutability with frozen objects. In VSTTE, pages 192--208, Oct. 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. }}P. Muller and A. Poetzsch-Heffter. Universes: A type system for controlling representation exposure. In Programming Languages and Fundamentals of Programming, pages 131--140, 1999.Google ScholarGoogle Scholar
  25. }}Peter Muller and Arsenii Rudich. Ownership transfer in universe types. In OOPSLA, pages 461--478, Oct. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. }}Stefan Nageli. Ownership in design patterns. Master's thesis, ETH Zurich, Zurich, Switzerland, Mar. 2006.Google ScholarGoogle Scholar
  27. }}James Noble. Iterators and encapsulation. In TOOLS Pacific, pages 431--442, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. }}James Noble, Jan Vitek, and John Potter. Flexible alias protection. In ECOOP, pages 158--185, July 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. }}Nathaniel Nystrom, Vijay Saraswat, Jens Palsberg, and Christian Grothoff. Constrained types for object-oriented languages. In OOPSLA, pages 457--474, Oct. 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. }}Johan Ostlund, Tobias Wrigstad, and Dave Clarke. Ownership, uniqueness and immutability. In Tools Europe, pages 178--197, 2008.Google ScholarGoogle ScholarCross RefCross Ref
  31. }}Matthew M. Papi, Mahmood Ali, Telmo Luis Correa Jr., Jeff H. Perkins, and Michael D. Ernst. Practical pluggable types for Java. In ISSTA, pages 201--212, July 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. }}Benjamin C. Pierce. Types and Programming Languages. MIT Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. }}Alex Potanin, James Noble, Dave Clarke, and Robert Biddle. Generic Ownership for Generic Java. In OOPSLA, pages 311--324, Oct. 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. }}Mats Skoglund and Tobias Wrigstad. A mode system for read-only references in Java. In FTfJP, June 2001.Google ScholarGoogle Scholar
  35. }}Matthew S. Tschantz and Michael D. Ernst. Javari: Adding reference immutability to Java. In OOPSLA, pages 211--230, Oct. 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. }}Jan Vitek and Boris Bokowski. Confined types. In OOPSLA, pages 82--96, Nov. 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. }}Tobias Wrigstad. Ownership-Based Alias Management. PhD thesis, Royal Institute of Technology, Sweden, May 2006.Google ScholarGoogle Scholar
  38. }}Tobias Wrigstad and Dave Clarke. Existential owners for ownership types. J. Object Tech., 6(4):141--159, May-June 2007.Google ScholarGoogle ScholarCross RefCross Ref
  39. }}Yoav Zibin. Featherweight Ownership and Immutability Generic Java (FOIGJ). Technical Report 10-16, ECS, VUW, June 2010. http://ecs.victoria.ac.nz/Main/TechnicalReportSeries.Google ScholarGoogle Scholar
  40. }}Yoav Zibin, Alex Potanin, Mahmood Ali, Shay Artzi, Adam Kiezun, and Michael D. Ernst. Object and reference immutability using Java generics. In ESEC/FSE, pages 75--84, Sep. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. }}Yoav Zibin, Alex Potanin, Paley Li, Mahmood Ali, and Michael D. Ernst. OIGJ with owners as modifiers. Technical Report 10-15, ECS, VUW, January 2010.Google ScholarGoogle Scholar

Index Terms

  1. Ownership and immutability in generic Java

      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 45, Issue 10
        OOPSLA '10
        October 2010
        957 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/1932682
        Issue’s Table of Contents
        • cover image ACM Conferences
          OOPSLA '10: Proceedings of the ACM international conference on Object oriented programming systems languages and applications
          October 2010
          984 pages
          ISBN:9781450302036
          DOI:10.1145/1869459

        Copyright © 2010 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 17 October 2010

        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!