Ownership and Immutability in Generic Java']Java

被引:27
|
作者
Zibin, Yoav [1 ]
Potanin, Alex [1 ]
Li, Paley [1 ]
Ali, Mahmood [2 ]
Ernst, Michael D. [3 ]
机构
[1] Victoria Univ Wellington, Wellington, New Zealand
[2] MIT, Cambridge, MA 02139 USA
[3] Univ Washington, Seattle, WA 98195 USA
关键词
Experimentation; Languages; Theory;
D O I
10.1145/1932682.1869509
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页码:598 / 617
页数:20
相关论文
共 50 条
  • [1] Generic ownership for generic Java']Java
    Potanin, Alex
    Noble, James
    Clarke, Dave
    Biddle, Robert
    [J]. ACM SIGPLAN NOTICES, 2006, 41 (10) : 311 - 324
  • [2] Java']Javari: Adding reference immutability to Java']Java
    Tschantz, MS
    Ernst, MD
    [J]. ACM SIGPLAN NOTICES, 2005, 40 (10) : 211 - 230
  • [3] Glacier: Transitive Class Immutability for Java']Java
    Coblenz, Michael
    Nelson, Whitney
    Aldrich, Jonathan
    Myers, Brad
    Sunshine, Joshua
    [J]. 2017 IEEE/ACM 39TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE), 2017, : 496 - 506
  • [4] GJ: A generic Java']Java
    Wadler, P
    [J]. DR DOBBS JOURNAL, 2000, 25 (02): : 23 - +
  • [5] Encoding Ownership Types in Java']Java
    Cameron, Nicholas
    Noble, James
    [J]. OBJECTS, MODELS, COMPONENTS, PATTERNS, 2010, 6141 : 271 - 290
  • [6] Safe instantiation in Generic Java']Java
    Allen, EE
    Cartwright, R
    [J]. SCIENCE OF COMPUTER PROGRAMMING, 2006, 59 (1-2) : 26 - 37
  • [7] Java']Java garbage collection - a generic solution?
    Meehan, A
    Lunney, T
    [J]. INFORMATION AND SOFTWARE TECHNOLOGY, 2001, 43 (02) : 151 - 155
  • [8] A Generic Type System for Featherweight Java']Java
    Schoepp, Ulrich
    Xu, Chuangjie
    [J]. PROCEEDINGS OF THE 23RD ACM INTERNATIONAL WORKSHOP ON FORMAL TECHNIQUES FOR JAVA-LIKE PROGRAMS (FTFJP '21), 2021, : 9 - 15
  • [9] Generic Programming in C++ and Java']Java
    Mathur, Shilpa
    [J]. INTERNATIONAL JOURNAL OF COMPUTER SCIENCE AND NETWORK SECURITY, 2011, 11 (09): : 60 - 64
  • [10] Generic exception handling and the Java']Java monad
    Schröder, L
    Mossakowski, T
    [J]. ALGEBRAIC METHODOLOGY AND SOFTWARE TECHNOLOGY: PROCEEDINGS, 2004, 3116 : 443 - 459