Safe Locking for Multi-threaded Java

  • Einar Broch Johnsen
  • Thi Mai Thuong Tran
  • Olaf Owe
  • Martin Steffen
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7141)


There are many mechanisms for concurrency control in high-level programming languages. In Java, the original mechanism for concurrency control, based on synchronized blocks, is lexically scoped. For more flexible control, Java 5 introduced non-lexical operators, supporting lock primitives on re-entrant locks. These operators may lead to run-time errors and unwanted behavior; e.g., taking a lock without releasing it, which could lead to a deadlock, or trying to release a lock without owning it. This paper develops a static type and effect system to prevent the mentioned lock errors for non-lexical locks. The effect type system is formalized for an object-oriented calculus which supports non-lexical lock handling. Based on an operational semantics, we prove soundness of the effect type analysis. Challenges in the design of the effect type system are dynamic creation of threads, objects, and especially of locks, aliasing of lock references, passing of lock references between threads, and reentrant locks as found in Java.


Operational Semantic Mutual Exclusion Concurrency Control Method Body Program Language Design 
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.
    Amtoft, T., Nielson, H.R., Nielson, F.: Type and Effect Systems: Behaviours for Concurrency. Imperial College Press (1999)Google Scholar
  2. 2.
    Bigliardi, G., Laneve, C.: A type system for JVM threads. In: Proceedings of 3rd ACM SIGPLAN Workshop on Types in Compilation, TIC 2000, p. 2003 (2000)Google Scholar
  3. 3.
    DeLine, R., Fähndrich, M.: Enforcing high-level protocols in low-level software. In: Proceedings of the 2001 ACM Conference on Programming Language Design and Implementation, pp. 59–69 (June 2001)Google Scholar
  4. 4.
    Foster, J.S., Terauchi, T., Aiken, A.: Flow-sensitive type qualifiers. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (2002)Google Scholar
  5. 5.
    Gerakios, P., Papaspyrou, N., Sagonas, K.: A concurrent language with a uniform treatment of regions and locks. In: Programming Language Approaches to Concurrency and Communication-eCentric Software. EPTCS, vol. 17, pp. 79–93 (2010)Google Scholar
  6. 6.
    Igarashi, A., Kobayashi, N.: Resource usage analysis. ACM Transactions on Programming Languages and Systems 27(2), 264–313 (2005)CrossRefGoogle Scholar
  7. 7.
    Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight Java: A minimal core calculus for Java and GJ. In: Object Oriented Programming: Systems, Languages, and Applications, OOPSLA 1999, pp. 132–146. ACM (1999); SIGPLAN NoticesGoogle Scholar
  8. 8.
    Iwama, F., Kobayashi, N.: A new type system for JVM lock primitives. In: ASIA-PEPM 2002: Proceedings of the ASIAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, pp. 71–82. ACM, New York (2002)CrossRefGoogle Scholar
  9. 9.
    Jagannathan, S., Vitek, J., Welc, A., Hosking, A.: A transactional object calculus. Science of Computer Programming 57(2), 164–186 (2005)MathSciNetzbMATHCrossRefGoogle Scholar
  10. 10.
    Johnsen, E.B., Tran, T.M.T, Owe, O., Steffen, M.: Safe locking for multi-threaded Java. Technical Report (revised version) 402, University of Oslo, Dept. of Computer Science (January 2011),; A shorter version (extended abstract) has been presented at the NWPT 2010
  11. 11.
    Tran, T.M.T., Owe, O., Steffen, M.: Safe typing for transactional vs. lock-based concurrency in multi-threaded Java. In: Pham, S.B., Hoang, T.-H., McKay, B., Hirota, K. (eds.) Proceedings of the Second International Conference on Knowledge and Systems Engineering, KSE 2010, pp. 188-193. IEEE Computer Society (October 2010)Google Scholar
  12. 12.
    Tran, T.M.T., Steffen, M.: Safe Commits for Transactional Featherweight Java. In: Méry, D., Merz, S. (eds.) IFM 2010. LNCS, vol. 6396, pp. 290–304. Springer, Heidelberg (2010); An earlier and longer version has appeared as UiO, Dept. of Comp. Science Technical Report 392, October 2009 and appeared as extended abstract in the Proceedings of NWPT 2009 CrossRefGoogle Scholar
  13. 13.
    Oaks, S., Wong, H.: Java Threads, 3rd edn. O’Reilly (September 2004)Google Scholar
  14. 14.
    Stata, R., Abadi, M.: A type system for Java bytecode subroutines. ACM Transactions on Programming Languages and Systems 21(1), 90–137 (1999)CrossRefGoogle Scholar
  15. 15.
    Suenaga, K.: Type-Based Deadlock-Freedom Verification for Non-Block-Structured Lock Primitives and Mutable References. In: Ramalingam, G. (ed.) APLAS 2008. LNCS, vol. 5356, pp. 155–170. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  16. 16.
    Terauchi, T.: Checking race freedom via linear programming. In: Proceedings of the 2008 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2008, pp. 1–10. ACM, New York (2008)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Einar Broch Johnsen
    • 1
  • Thi Mai Thuong Tran
    • 1
  • Olaf Owe
    • 1
  • Martin Steffen
    • 1
  1. 1.Department of InformaticsUniversity of OsloNorway

Personalised recommendations