Capabilities for Uniqueness and Borrowing

  • Philipp Haller
  • Martin Odersky
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6183)


An important application of unique object references is safe and efficient message passing in concurrent object-oriented programming. However, to prevent the ill effects of aliasing, practical systems often severely restrict the shape of messages passed by reference. Moreover, the problematic interplay between destructive reads–often used to implement unique references–and temporary aliasing through “borrowed” references is exacerbated in a concurrent setting, increasing the potential for unpredictable run-time errors.

This paper introduces a new approach to uniqueness. The idea is to use capabilities for enforcing both at-most-once consumption of unique references, and a flexible notion of uniqueness. The main novelty of our approach is a model of uniqueness and borrowing based on simple, unstructured capabilities. The advantages are: first, it provides simple foundations for uniqueness and borrowing. Second, it can be formalized using a relatively simple type system, for which we provide a complete soundness proof. Third, it avoids common problems involving borrowing and destructive reads, since unique references subsume borrowed references.

We have implemented our type system as an extension to Scala. Practical experience suggests that our system allows type checking real-world actor-based concurrent programs with only a small number of additional type annotations.


Type System Dynamic Capability Unique Object Ownership Type Linear Type 
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.
    Almeida, P.S.: Balloon types: Controlling sharing of state in data types. In: Aksit, M., Matsuoka, S. (eds.) ECOOP 1997. LNCS, vol. 1241, pp. 32–59. Springer, Heidelberg (1997)CrossRefGoogle Scholar
  2. 2.
    Anderson, Z.R., Gay, D., Naik, M.: Lightweight annotations for controlling sharing in concurrent data structures. In: PLDI, pp. 98–109. ACM, New York (2009)CrossRefGoogle Scholar
  3. 3.
    Armstrong, J., Virding, R., Wikström, C., Williams, M.: Concurrent Programming in Erlang, 2nd edn. Prentice-Hall, Englewood Cliffs (1996)Google Scholar
  4. 4.
    Auerbach, J.S., Bacon, D.F., Guerraoui, R., Spring, J.H., Vitek, J.: Flexible task graphs: a unified restricted thread programming model for java. In: LCTES, pp. 1–11. ACM, New York (2008)CrossRefGoogle Scholar
  5. 5.
    Beckman, N.E., Bierhoff, K., Aldrich, J.: Verifying correct usage of atomic blocks and typestate. In: Harris, G.E. (ed.) OOPSLA, pp. 227–244. ACM, New York (2008)Google Scholar
  6. 6.
    Bierhoff, K., Aldrich, J.: Modular typestate checking of aliased objects. In: OOPSLA, pp. 301–320. ACM, New York (2007)Google Scholar
  7. 7.
    Bornat, R., Calcagno, C., O’Hearn, P.W., Parkinson, M.J.: Permission accounting in separation logic. In: POPL, pp. 259–270. ACM, New York (2005)Google Scholar
  8. 8.
    Boyapati, C., Lee, R., Rinard, M.C.: Ownership types for safe programming: preventing data races and deadlocks. In: OOPSLA, pp. 211–230 (2002)Google Scholar
  9. 9.
    Boyland, J.T., Retert, W.: Connecting effects and uniqueness with adoption. In: POPL, pp. 283–295. ACM, New York (2005)Google Scholar
  10. 10.
    Caromel, D.: Towards a method of object-oriented concurrent programming. ACM Commun. 36(9), 90–102 (1993)CrossRefGoogle Scholar
  11. 11.
    Charguéraud, A., Pottier, F.: Functional translation of a calculus of capabilities. In: ICFP, pp. 213–224. ACM, New York (2008)CrossRefGoogle Scholar
  12. 12.
    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
  13. 13.
    Clarke, D., Wrigstad, T., Östlund, J., Johnsen, E.B.: Minimal ownership for active objects. In: APLAS, pp. 139–154. Springer, Heidelberg (2008)Google Scholar
  14. 14.
    Clarke, D.G., Potter, J., Noble, J.: Ownership types for flexible alias protection. In: OOPSLA, pp. 48–64 (1998)Google Scholar
  15. 15.
    Degen, M., Thiemann, P., Wehr, S.: Tracking linear and affine resources with java(X). In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 550–574. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  16. 16.
    Dietl, W., Drossopoulou, S., Müller, P.: Generic universe types. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 28–53. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  17. 17.
    Dietl, W., Müller, P.: Universes: Lightweight ownership for JML. Journal of Object Technology 4(8), 5–32 (2005)Google Scholar
  18. 18.
    Distefano, D., Parkinson, M.J.: jstar: towards practical verification for java. In: OOPSLA, pp. 213–226. ACM, New York (2008)Google Scholar
  19. 19.
    Ennals, R., Sharp, R., Mycroft, A.: Linear types for packet processing. In: Schmidt, D. (ed.) ESOP 2004. LNCS, vol. 2986, pp. 204–218. Springer, Heidelberg (2004)Google Scholar
  20. 20.
    Fähndrich, M., Aiken, M., Hawblitzel, C., Hodson, O., Hunt, G.C., Larus, J.R., Levi, S.: Language support for fast and reliable message-based communication in singularity OS. In: EuroSys, pp. 177–190. ACM, New York (2006)CrossRefGoogle Scholar
  21. 21.
    Fähndrich, M., DeLine, R.: Adoption and focus: Practical linear types for imperative programming. In: PLDI, pp. 13–24 (2002)Google Scholar
  22. 22.
    Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: PLDI, pp. 237–247 (1993)Google Scholar
  23. 23.
    Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns. Addison-Wesley, Reading (1995)Google Scholar
  24. 24.
    Haller, P., Odersky, M.: Capabilities for uniqueness and borrowing. Technical Report LAMP-REPORT-2009-004 EPFL, Lausanne, Switzerland (December 2009),
  25. 25.
    Haller, P., Odersky, M.: Scala actors: Unifying thread-based and event-based programming. Theor. Comput. Sci. 410(2-3), 202–220 (2009)zbMATHCrossRefMathSciNetGoogle Scholar
  26. 26.
    Harms, D.E., Weide, B.W.: Copying and swapping: Influences on the design of reusable software components. IEEE Trans. Software Eng. 17(5), 424–435 (1991)CrossRefGoogle Scholar
  27. 27.
    Hicks, M.W., Morrisett, J.G., Grossman, D., Jim, T.: Experience with safe manual memory-management in cyclone. In: ISMM, pp. 73–84 (2004)Google Scholar
  28. 28.
    Hogg, J.: Islands: Aliasing protection in object-oriented languages. In: OOPSLA (1991)Google Scholar
  29. 29.
    Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight java: a minimal core calculus for java and GJ. ACM Trans. Program. Lang. Syst. 23(3), 396–450 (2001)CrossRefGoogle Scholar
  30. 30.
    Kobayashi, N.: Quasi-linear types. In: POPL, pp. 29–42 (1999)Google Scholar
  31. 31.
    Lindholm, T., Yellin, F.: The Java Virtual Machine Specification. Addison-Wesley, Reading (1996)Google Scholar
  32. 32.
    Müller, P., Rudich, A.: Ownership transfer in universe types. In: OOPSLA (2007)Google Scholar
  33. 33.
    Noble, J., Vitek, J., Potter, J.: Flexible alias protection. In: Jul, E. (ed.) ECOOP 1998. LNCS, vol. 1445, pp. 158–185. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  34. 34.
    Odersky, M.: Observers for linear types. In: Krieg-Brückner, B. (ed.) ESOP 1992. LNCS, vol. 582, pp. 390–407. Springer, Heidelberg (1992)Google Scholar
  35. 35.
    Odersky, M., Spoon, L., Venners, B.: Programming in Scala. Artima Press, Mountain View (2008)Google Scholar
  36. 36.
    O’Hearn, P.W., Reynolds, J.C., Yang, H.: Local reasoning about programs that alter data structures. In: Fribourg, L. (ed.) CSL 2001 and EACSL 2001. LNCS, vol. 2142, pp. 1–19. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  37. 37.
    Parkinson, M.J., Bierman, G.M.: Separation logic, abstraction and inheritance. In: POPL, pp. 75–86. ACM, New York (2008)Google Scholar
  38. 38.
    Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)Google Scholar
  39. 39.
    Spring, J.H., Privat, J., Guerraoui, R., Vitek, J.: Streamflex: high-throughput stream programming in java. In: OOPSLA, pp. 211–228 (2007)Google Scholar
  40. 40.
    Srinivasan, S., Mycroft, A.: Kilim: Isolation-typed actors for java. In: Vitek, J. (ed.) ECOOP 2008. LNCS, vol. 5142, pp. 104–128. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  41. 41.
    Strnisa, R., Sewell, P., Parkinson, M.J.: The java module system: core design and semantic definition. In: OOPSLA, pp. 499–514 (2007)Google Scholar
  42. 42.
    Tofte, M., Talpin, J.-P.: Region-based memory management. Inf. Comput. 132(2), 109–176 (1997)zbMATHCrossRefMathSciNetGoogle Scholar
  43. 43.
    Wadler, P.: Linear types can change the world! In: Programming Concepts and Methods, IFIP TC 2 Working Conference, Israel (1990)Google Scholar
  44. 44.
    Walker, D., Crary, K., Morrisett, J.G.: Typed memory management via static capabilities. ACM Trans. Program. Lang. Syst. 22(4), 701–771 (2000)CrossRefGoogle Scholar
  45. 45.
    Walker, D., Morrisett, J.G.: Alias types for recursive data structures. In: Harper, R. (ed.) TIC 2000. LNCS, vol. 2071, pp. 177–206. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  46. 46.
    Walker, D., Watkins, K.: On regions and linear types. In: ICFP (2001)Google Scholar
  47. 47.
    Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Inf. Comput. 115(1), 38–94 (1994)zbMATHCrossRefMathSciNetGoogle Scholar
  48. 48.
    Wrigstad, T.: Ownership-Based Alias Managemant. PhD thesis, KTH, Sweden (2006)Google Scholar
  49. 49.
    Wrigstad, T., Clarke, D.: Existential owners for ownership types. Journal of Object Technology 6(4) (2007)Google Scholar
  50. 50.
    Wrigstad, T., Pizlo, F., Meawad, F., Zhao, L., Vitek, J.: Loci: Simple thread-locality for java. In: Drossopoulou, S. (ed.) ECOOP 2009. LNCS, vol. 5653, pp. 445–469. Springer, Heidelberg (2009)Google Scholar
  51. 51.
    Yonezawa, A., Briot, J.-P., Shibayama, E.: Object-oriented concurrent programming in ABCL/1. In: OOPSLA, pp. 258–268 (1986)Google Scholar
  52. 52.
    Zhao, T., Noble, J., Vitek, J.: Scoped types for real-time java. In: RTSS, pp. 241–251. IEEE Computer Society, Los Alamitos (2004)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Philipp Haller
    • 1
  • Martin Odersky
    • 1
  1. 1.EPFLSwitzerland

Personalised recommendations