Transformation for class immutability

It is common for object-oriented programs to have both mutable and immutable classes. Immutable classes simplify programing because the programmer does not have to reason about side-effects. Sometimes programmers write immutable classes from scratch, other times they transform mutable into immutable classes. To transform a mutable class, programmers must find all methods that mutate its transitive state and all objects that can enter or escape the state of the class. The analyses are non-trivial and the rewriting is tedious. Fortunately, this can be automated. We present an algorithm and a tool, Immutator, that enables the programmer to safely transform a mutable class into an immutable class. Two case studies and one controlled experiment show that Immutator is useful. It (i) reduces the burden of making classes immutable, (ii) is fast enough to be used interactively, and (iii) is much safer than manual transformations.

[1]  Frank Tip,et al.  Refactoring for reentrancy , 2009, ESEC/FSE '09.

[2]  Ralph E. Johnson,et al.  Relooper: refactoring for loop parallelism in Java , 2009, OOPSLA Companion.

[3]  Doug Lea,et al.  Concurrent Programming In Java , 1996 .

[4]  Frank Tip,et al.  Refactoring Java programs for flexible locking , 2011, 2011 33rd International Conference on Software Engineering (ICSE).

[5]  Atanas Rountev,et al.  Precise identification of side-effect-free methods in Java , 2004, 20th IEEE International Conference on Software Maintenance, 2004. Proceedings..

[6]  Barbara G. Ryder,et al.  A schema for interprocedural modification side-effect analysis with pointer aliasing , 2001, TOPL.

[7]  Darko Marinov,et al.  Object equality profiling , 2003, OOPSLA.

[8]  William G. Griswold,et al.  Automated assistance for program restructuring , 1993, TSEM.

[9]  John Banning,et al.  : An Efficient , 2022 .

[10]  Martin C. Rinard,et al.  Purity and Side Effect Analysis for Java Programs , 2005, VMCAI.

[11]  Jong-Deok Choi,et al.  Escape analysis for Java , 1999, OOPSLA '99.

[12]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[13]  Dirk Riehle,et al.  Value object , 2006, PLoP '06.

[14]  Michael D. Ernst,et al.  Refactoring sequential Java code for concurrency via concurrent libraries , 2009, 2009 IEEE 31st International Conference on Software Engineering.

[15]  Martin C. Rinard,et al.  Compositional pointer and escape analysis for Java programs , 1999, OOPSLA '99.

[16]  Joshua J. Bloch Effective Java : programming language guide , 2001 .

[17]  Mark Harman,et al.  An Empirical Investigation of the Influence of a Type of Side Effects on Program Comprehension , 2003, IEEE Trans. Software Eng..

[18]  Rich Hickey,et al.  The Clojure programming language , 2008, DLS '08.

[19]  Michael D. Ernst,et al.  Object and reference immutability using Java generics , 2007, ESEC-FSE '07.

[20]  David Holmes,et al.  Java Concurrency in Practice , 2006 .

[21]  Vivek Sarkar,et al.  Immutability specification and its applications , 2002, JGI '02.

[22]  Michael D. Ernst,et al.  Javari: adding reference immutability to Java , 2005, OOPSLA '05.