Skip to main navigation Skip to search Skip to main content

Ownership and immutability in generic Java

  • Yoav Zibin*
  • , Alex Potanin
  • , Paley Li
  • , Mahmood Ali
  • , Michael D. Ernst
  • *Corresponding author for this work

Research output: Chapter in Book/Report/Conference proceedingConference Paperpeer-review

47 Citations (Scopus)

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.

Original languageEnglish
Title of host publicationOOPSLA/SPLASH '10: Proceedings of the ACM International Conference on Object Oriented Programming, Systems, Languages, and Applications
Place of PublicationNew York
PublisherAssociation for Computing Machinery (ACM)
Pages598-617
Number of pages20
ISBN (Electronic)978-1-4503-0203-6
DOIs
Publication statusPublished - Oct 2010
Externally publishedYes
Event2010 ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages, and Applications, OOPSLA'10 - Reno/Tahoe, NV, United States
Duration: 17 Oct 201021 Oct 2010

Publication series

NameACM SIGPLAN Notices
PublisherAssociation for Computing Machinery (ACM)
Number10
Volume45
ISSN (Print)1523-2867

Conference

Conference2010 ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages, and Applications, OOPSLA'10
Country/TerritoryUnited States
CityReno/Tahoe, NV
Period17/10/1021/10/10

Fingerprint

Dive into the research topics of 'Ownership and immutability in generic Java'. Together they form a unique fingerprint.

Cite this