ABSTRACT
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.
- J. P. Banning. An efficient way to find the side effects of procedure calls and the aliases of variables. In POPL, pages 29--41, 1979. Google ScholarDigital Library
- D. Bäumer, D. Riehle, W. Siberski, C. Lilienthal, D. Megert, K.-H. Sylla, and H. Züllighoven. Want value objects in java? Technical report, 1998.Google Scholar
- J. Bloch. Effective Java: Programming Language Guide. Addison-Wesley, 2001. Google ScholarDigital Library
- J.-D. Choi, M. Gupta, M. Serrano, V. C. Sreedhar, and S. Midkiff. Escape analysis for java. In OOPSLA, pages 1--19, 1999. Google ScholarDigital Library
- D. Dig, J. Marrero, and M. D. Ernst. Refactoring sequential java code for concurrency via concurrent libraries. In ICSE, pages 397--407, 2009. Google ScholarDigital Library
- D. Dig, M. Tarce, C. Radoi, M. Minea, and R. Johnson. Relooper: refactoring for loop parallelism in Java. In OOPSLA, pages 793--794, 2009. Google ScholarDigital Library
- J. J. Dolado, M. Harman, M. C. Otero, and L. Hu. An empirical investigation of the influence of a type of side effects on program comprehension. IEEE TSE, 29(7):665--670, 2003. Google ScholarDigital Library
- E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1994. Google ScholarDigital Library
- B. Goetz, T. Peierls, J. Bloch, J. Bowbeer, D. Holmes, and D. Lea. Java Concurrency in Practice. Addison-Wesley, 2006. Google ScholarDigital Library
- W. G. Griswold and D. Notkin. Automated assistance for program restructuring. ACM TOSEM, 2(3):228--269, 1993. Google ScholarDigital Library
- R. Hickey. The clojure programming language. In DLS, 2008. Google ScholarDigital Library
- Java SE 6 API Specification. http://java.sun.com/javase/6/docs/api.Google Scholar
- D. Lea. Concurrent Programming In Java. Addison-Wesley, second edition, 2000.Google ScholarDigital Library
- D. Marinov and R. O'Callahan. Object equality profiling. In OOPSLA, pages 313--325, 2003. Google ScholarDigital Library
- W. F. Opdyke and R. E. Johnson. Refactoring: An aid in designing application frameworks and evolving object-oriented systems. In SOOPPA, pages 145--160, 1990.Google Scholar
- I. Pechtchanski and V. Sarkar. Immutability specification and its applications. In Java Grande, pages 202--211, 2002. Google ScholarDigital Library
- D. Riehle. Value object. In PLOP, 2006. Google ScholarDigital Library
- A. Rountev. Precise identification of side-effect-free methods in Java. In ICSM, pages 82--91, 2004. Google ScholarDigital Library
- B. G. Ryder, W. Landi, P. Stocks, S. Zhang, and R. Altucher. A schema for interprocedural modification side-effect analysis with pointer aliasing. ACM TOPLAS, 23(2):105--186, 2001. Google ScholarDigital Library
- A. Salcianu and M. C. Rinard. Purity and side effect analysis for java programs. In VMCAI, pages 199--215, 2005. Google ScholarDigital Library
- M. Schäfer, M. Sridharan, J. Dolby, and F. Tip. Refactoring java programs for flexible locking. To appear in ICSE, 2011.Google Scholar
- M. S. Tschantz and M. D. Ernst. Javari: Adding reference immutability to Java. In OOPSLA, pages 211--230, 2005. Google ScholarDigital Library
- T.J. Watson Libraries for Analysis (WALA). http://wala.sourceforge.net/wiki/index.php.Google Scholar
- J. Whaley and M. C. Rinard. Compositional pointer and escape analysis for java programs. In OOPSLA, pages 187--206, 1999. Google ScholarDigital Library
- J. Wloka, M. Sridharan, and F. Tip. Refactoring for Reentrancy. In FSE, pages 173--182, 2009. Google ScholarDigital Library
- Y. Zibin, A. Potanin, M. Ali, S. Artzi, A. Kiezun, and M. D. Ernst. Object and Reference Immutability using Java Generics. In FSE, pages 75--84, 2007. Google ScholarDigital Library
Index Terms
- Transformation for class immutability
Recommendations
Ownership and immutability in generic Java
OOPSLA '10The 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,...
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,...
Comments