Flexible Immutability with Frozen Objects

  • K. Rustan M. Leino
  • Peter Müller
  • Angela Wallenburg
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5295)


Object immutability is a familiar concept that allows safe sharing of objects. Existing language support for immutability is based on immutable classes. However, class-based approaches are restrictive because programmers can neither make instances of arbitrary classes immutable, nor can they control when an instance becomes immutable. These restrictions prevent many interesting applications where objects of mutable classes go through a number of modifications before they become immutable.

This paper presents a flexible technique to enforce the immutability of individual objects by transferring their ownership to a special freezer object, which prevents further modification. The paper demonstrates how immutability facilitates program verification by extending the Boogie methodology for object invariants to immutable objects. The technique is based on Spec#’s dynamic ownership, but the concepts also apply to other ownership systems that support transfer.


Pseudo Code Proof Obligation Shared Object Mutable Classis Object Invariant 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Aldrich, J., Kostadinov, V., Chambers, C.: Alias annotations for program understanding. In: OOPSLA, pp. 311–330. ACM Press, New York (2002)Google Scholar
  2. 2.
    Barnett, M., DeLine, R., Fähndrich, M., Leino, K.R.M., Schulte, W.: Verification of object-oriented programs with invariants. JOT 3(6), 27–56 (2004), Google Scholar
  3. 3.
    Barnett, M., Naumann, D.A.: Friends need a bit more: Maintaining invariants over shared state. In: Kozen, D. (ed.) MPC 2004. LNCS, vol. 3125, pp. 54–84. Springer, Heidelberg (2004)Google Scholar
  4. 4.
    Bornat, R., Calcagno, C., O’Hearn, P., Parkinson, M.: Permission accounting in separation logic. In: POPL, vol. 40(1), pp. 259–270. ACM, New York (2005)Google Scholar
  5. 5.
    Boyapati, C.: SafeJava: A Unified Type System for Safe Programming. Ph.D., MIT (2004)Google Scholar
  6. 6.
    Boyland, J.: Checking interference with fractional permissions. In: Cousot, R. (ed.) SAS 2003. LNCS, vol. 2694, pp. 55–72. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  7. 7.
    Clarke, D., Wrigstad, T.: External uniqueness is unique enough. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743, pp. 176–200. Springer, Heidelberg (2003)Google Scholar
  8. 8.
    Clarke, D.G., Potter, J.M., Noble, J.: Ownership types for flexible alias protection. In: OOPSLA. ACM SIGPLAN Notices, vol. 33(10) (1998)Google Scholar
  9. 9.
    Darvas, Á., Leino, K.R.M.: Practical reasoning about invocations and implementations of pure methods. In: Dwyer, M.B., Lopes, A. (eds.) FASE 2007. LNCS, vol. 4422, pp. 336–351. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  10. 10.
    Darvas, Á., Müller, P.: Reasoning about method calls in interface specifications. JOT 5(5), 59–85 (2006)Google Scholar
  11. 11.
    Drossopoulou, S., Francalanza, A., Müller, P., Summers, A.J.: A unified framework for verification techniques for object invariants. In: ECOOP. LNCS. Springer, Heidelberg (2008)Google Scholar
  12. 12.
    Fähndrich, M., Xia, S.: Establishing object invariants with delayed types. In: OOPSLA. SIGPLAN Notices, vol. 42(10), pp. 337–350. ACM, New York (2007)Google Scholar
  13. 13.
    Haack, C., Poll, E., Schäfer, J., Schubert, A.: Immutable objects for a Java-like language. In: De Nicola, R. (ed.) ESOP 2007. LNCS, vol. 4421, pp. 347–362. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  14. 14.
    Leino, K.R.M., Müller, P.: Object invariants in dynamic contexts. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 491–516. Springer, Heidelberg (2004)Google Scholar
  15. 15.
    Leino, K.R.M., Müller, P.: Verification of equivalent-results methods. In: Drossopoulou, S. (ed.) ESOP 2008. LNCS, vol. 4960, pp. 307–321. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  16. 16.
    Leino, K.R.M., Schulte, W.: Using history invariants to verify observers. In: De Nicola, R. (ed.) ESOP 2007. LNCS, vol. 4421, pp. 80–94. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  17. 17.
    Leino, K.R.M., Wallenburg, A.: Class-local object invariants. In: First India Software Engineering Conference (ISEC). ACM, New York (2008)Google Scholar
  18. 18.
    Liskov, B., Curtis, D., Day, M., Ghemawat, S., Gruber, R., Johnson, P., Myers, A.C.: Theta reference manual, preliminary version. Memo 88, Programming Methodology Group, MIT Laboratory for Computer Science (1995),
  19. 19.
    Lu, Y., Potter, J., Xue, J.: Validity invariants and effects. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 202–226. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  20. 20.
    Müller, P., Poetzsch-Heffter, A., Leavens, G.T.: Modular invariants for layered object structures. Science of Computer Programming 62, 253–286 (2006)zbMATHCrossRefMathSciNetGoogle Scholar
  21. 21.
    Müller, P., Rudich, A.: Ownership transfer in Universe Types. In: OOPSLA. SIGPLAN Notices, vol. 42(10), pp. 461–478. ACM, New York (2007)Google Scholar
  22. 22.
    Naumann, D.A.: Observational purity and encapsulation. TCS 376(3), 205–224 (2007)zbMATHCrossRefMathSciNetGoogle Scholar
  23. 23.
    Östlund, J., Wrigstad, T., Clarke, D., Åkerblom, B.: Ownership, uniqueness and immutability. In: IWACO (2007)Google Scholar
  24. 24.
    Tschantz, M.S., Ernst, M.D.: Javari: adding reference immutability to Java. In: OOPSLA. SIGPLAN Notices, vol. 40(10), pp. 211–230. ACM, New York (2005)Google Scholar
  25. 25.
    Zibin, Y., Potanin, A., Ali, M., Artzi, S., Kieżun, A., Ernst, M.D.: Object and reference immutability using java generics. In: ESEC-FSE, pp. 75–84. ACM, New York (2007)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2008

Authors and Affiliations

  • K. Rustan M. Leino
    • 1
  • Peter Müller
    • 1
  • Angela Wallenburg
    • 2
  1. 1.Microsoft Research 
  2. 2.Chalmers University of Technology and Göteborg University 

Personalised recommendations