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.
- }}Chandrasekhar Boyapati. SafeJava: A Unified Type System for Safe Programming. PhD thesis, MIT Dept. of EECS, Feb. 2004. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}Chandrasekhar Boyapati, Barbara Liskov, and Liuba Shrira. Ownership types for object encapsulation. In POPL, pages 213--223, Jan. 2003. Google Scholar
Digital Library
- }}John Boyland. Why we should not add readonly to Java (yet). In FTfJP, July 2005.Google Scholar
- }}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 Scholar
Digital Library
- }}John Boyland, William Retert, and Yang Zhao. Comprehending annotations on object-oriented programs using fractional permissions. In IWACO, pages 1--11, July 2009. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}Nicholas Cameron and Sophia Drossopoulou. Existential quantification for variant ownership. In ESOP, pages 128--142, Mar. 2009. Google Scholar
Digital Library
- }}Nicholas Cameron, Sophia Drossopoulou, and Erik Ernst. A model for Java with wildcards. In ECOOP, pages 2--26, July 2008. Google Scholar
Digital Library
- }}Nicholas R. Cameron, Sophia Drossopoulou, James Noble, and Matthew J. Smith. Multiple ownership. In OOPSLA, pages 441--460, Oct. 2007. Google Scholar
Digital Library
- }}Dave Clarke and Sophia Drossopoulou. Ownership, encapsulation and the disjointness of type and effect. In OOPSLA, pages 292--310, Oct. 2002. Google Scholar
Digital Library
- }}Dave Clarke and Tobias Wrigstad. External uniqueness is unique enough. In ECOOP, pages 176--200, July 2003.Google Scholar
Cross Ref
- }}David G. Clarke, John M. Potter, and James Noble. Ownership types for flexible alias protection. In OOPSLA, pages 48--64, Oct. 1998. Google Scholar
Digital Library
- }}Werner Dietl, Sophia Drossopoulou, and Peter Muller. Generic Universe Types. In ECOOP, pages 28--53, Aug. 2007. Google Scholar
Digital Library
- }}Michael D. Ernst. Type Annotations specification (JSR 308). http://types.cs.washington.edu/jsr308/, Sep. 12, 2008.Google Scholar
- }}Manuel Fahndrich and Songtao Xia. Establishing object invariants with delayed types. In OOPSLA, pages 337--350, Oct. 2007. Google Scholar
Digital Library
- }}Erich Gamma, Richard Helm, Ralph E. Johnson, and John Vlissides. Design Patterns. Addison-Wesley, Reading, MA, 1995.Google Scholar
- }}Christian Haack and Erik Poll. Type-based object immutability with flexible initialization. In ECOOP, pages 520--545, 2009. Google Scholar
Digital Library
- }}Christian Haack, Erik Poll, Jan Schafer, and Aleksy Schubert. Immutable objects for a Java-like language. In ESOP, pages 347--362, Mar. 2007. Google Scholar
Digital Library
- }}Shan Shan Huang, David Zook, and Yannis Smaragdakis. cJ: Enhancing Java with safe type conditions. In AOSD, pages 185--198, Mar. 2007. Google Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}Gunter Kniesel and Dirk Theisen. JAC - access right based encapsulation for Java. Software: Practice and Experience, 31(6):555--576, 2001. Google Scholar
Digital Library
- }}K. Rustan M. Leino, Peter Muller, and Angela Wallenburg. Flexible immutability with frozen objects. In VSTTE, pages 192--208, Oct. 2008. Google Scholar
Digital Library
- }}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 Scholar
- }}Peter Muller and Arsenii Rudich. Ownership transfer in universe types. In OOPSLA, pages 461--478, Oct. 2007. Google Scholar
Digital Library
- }}Stefan Nageli. Ownership in design patterns. Master's thesis, ETH Zurich, Zurich, Switzerland, Mar. 2006.Google Scholar
- }}James Noble. Iterators and encapsulation. In TOOLS Pacific, pages 431--442, 2000. Google Scholar
Digital Library
- }}James Noble, Jan Vitek, and John Potter. Flexible alias protection. In ECOOP, pages 158--185, July 1998. Google Scholar
Digital Library
- }}Nathaniel Nystrom, Vijay Saraswat, Jens Palsberg, and Christian Grothoff. Constrained types for object-oriented languages. In OOPSLA, pages 457--474, Oct. 2008. Google Scholar
Digital Library
- }}Johan Ostlund, Tobias Wrigstad, and Dave Clarke. Ownership, uniqueness and immutability. In Tools Europe, pages 178--197, 2008.Google Scholar
Cross Ref
- }}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 Scholar
Digital Library
- }}Benjamin C. Pierce. Types and Programming Languages. MIT Press, 2002. Google Scholar
Digital Library
- }}Alex Potanin, James Noble, Dave Clarke, and Robert Biddle. Generic Ownership for Generic Java. In OOPSLA, pages 311--324, Oct. 2006. Google Scholar
Digital Library
- }}Mats Skoglund and Tobias Wrigstad. A mode system for read-only references in Java. In FTfJP, June 2001.Google Scholar
- }}Matthew S. Tschantz and Michael D. Ernst. Javari: Adding reference immutability to Java. In OOPSLA, pages 211--230, Oct. 2005. Google Scholar
Digital Library
- }}Jan Vitek and Boris Bokowski. Confined types. In OOPSLA, pages 82--96, Nov. 1999. Google Scholar
Digital Library
- }}Tobias Wrigstad. Ownership-Based Alias Management. PhD thesis, Royal Institute of Technology, Sweden, May 2006.Google Scholar
- }}Tobias Wrigstad and Dave Clarke. Existential owners for ownership types. J. Object Tech., 6(4):141--159, May-June 2007.Google Scholar
Cross Ref
- }}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 Scholar
- }}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 Scholar
Digital Library
- }}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 Scholar
Index Terms
Ownership and immutability in generic Java
Recommendations
Object and reference immutability using Java generics
ESEC-FSE '07: Proceedings of the the 6th joint meeting of the European software engineering conference and the ACM SIGSOFT symposium on The foundations of software engineeringA compiler-checked immutability guarantee provides useful documentation, facilitates reasoning, and enables optimizations. This paper presents Immutability Generic Java (IGJ), a novel language extension that expresses immutability without changing Java'...
Ownership and immutability in generic Java
OOPSLA '10: Proceedings of the ACM international conference on Object oriented programming systems languages and applicationsThe 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,...
Enforcing reference and object immutability in Java
OOPSLA Companion '08: Companion to the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applicationsImmutability information is useful in many software engineering tasks, such as modeling, verification, optimization, and refactoring. Furthermore, undesired mutation or side-effect are hard to detect and debug. This paper describes a javac plug-in that ...







Comments