Correct Refactoring of Concurrent Java Code

  • Max Schäfer
  • Julian Dolby
  • Manu Sridharan
  • Emina Torlak
  • Frank Tip
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6183)

Abstract

Automated refactorings as implemented in modern IDEs for Java usually make no special provisions for concurrent code. Thus, refactored programs may exhibit unexpected new concurrent behaviors. We analyze the types of such behavioral changes caused by current refactoring engines and develop techniques to make them behavior-preserving, ranging from simple techniques to deal with concurrency-related language constructs to a framework that computes and tracks synchronization dependencies. By basing our development directly on the Java Memory Model, we can state and prove precise correctness results about refactoring concurrent programs. We show that a broad range of refactorings are not influenced by concurrency at all, whereas other important refactorings can be made behavior-preserving for correctly synchronized programs by using our framework. Experience with a prototype implementation shows that our techniques are easy to implement and require only minimal changes to existing refactoring engines.

Keywords

Original Program Concurrent Program Data Race Normal Access Change Program Behavior 
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.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
  2. 2.
    Balaban, I., Tip, F., Fuhrer, R.: Refactoring support for class library migration. In: OOPSLA, pp. 265–279 (2005)Google Scholar
  3. 3.
    Blackburn, S.M., Garner, R., Hoffman, C., Khan, A.M., McKinley, K.S., Bentzur, R., Diwan, A., Feinberg, D., Frampton, D., Guyer, S.Z., Hirzel, M., Hosking, A., Jump, M., Lee, H., Moss, J.E.B., Phansalkar, A., Stefanović, D., Van Drunen, T., von Dincklage, D., Wiedermann, B.: The DaCapo benchmarks: Java benchmarking development and analysis. In: OOPSLA (2006)Google Scholar
  4. 4.
    Burke, M.G., Choi, J.-D., Fink, S., Grove, D., Hind, M., Sarkar, V., Serrano, M.J., Sreedhar, V.C., Srinivasan, H., Whaley, J.: The Jalapeño dynamic optimizing compiler for Java. In: JAVA 1999, pp. 129–141 (1999)Google Scholar
  5. 5.
    Cenciarelli, P., Knapp, A., Sibilio, E.: The Java Memory Model: Operationally, Denotationally, Axiomatically. In: De Nicola, R. (ed.) ESOP 2007. LNCS, vol. 4421, pp. 331–346. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  6. 6.
    Cheng, J.: Slicing Concurrent Programs: A Graph-Theoretical Approach. In: Fritzson, P.A. (ed.) AADEBUG 1993. LNCS, vol. 749. Springer, Heidelberg (1993)CrossRefGoogle Scholar
  7. 7.
    Dig, D., Marrero, J., Ernst, M.D.: Refactoring sequential Java code for concurrency via concurrent libraries. In: ICSE, pp. 397–407 (2009)Google Scholar
  8. 8.
    Dig, D., Tarce, M., Radoi, C., Minea, M., Johnson, R.: RELOOPER: Refactoring for Loop Parallelism in Java. In: OOPSLA Companion (2009)Google Scholar
  9. 9.
    Ekman, T., Hedin, G.: The JastAdd Extensible Java Compiler. SIGPLAN Notices 42(10), 1–18 (2007)CrossRefGoogle Scholar
  10. 10.
    Ekman, T., Hedin, G.: The JastAdd system — modular extensible compiler construction. Science of Computer Programming 69(1-3), 14–26 (2007)MATHCrossRefMathSciNetGoogle Scholar
  11. 11.
    Fowler, M.: Refactoring. Improving the Design of Existing Code. Addison-Wesley, Reading (1999)Google Scholar
  12. 12.
    Fuhrer, R., Tip, F., Kieżun, A., Dolby, J., Keller, M.: Efficiently refactoring java applications to use generic libraries. In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 71–96. Springer, Heidelberg (2005)Google Scholar
  13. 13.
    Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 3rd edn. PrenticeHall, Englewood Cliffs (2005)Google Scholar
  14. 14.
    Griswold, W.G.: Program Restructuring as an Aid to Software Maintenance. Ph.D. thesis, University of Washington (1991)Google Scholar
  15. 15.
    Huynh, T.Q., Roychoudhury, A.: A memory model sensitive checker for C#. In: Misra, J., Nipkow, T., Sekerinski, E. (eds.) FM 2006. LNCS, vol. 4085, pp. 476–491. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  16. 16.
    Ševčík, J., Aspinall, D.: On Validity of Program Transformations in the Java Memory Model. In: Vitek, J. (ed.) ECOOP 2008. LNCS, vol. 5142, pp. 27–51. Springer, Heidelberg (2008)Google Scholar
  17. 17.
    Kegel, H., Steimann, F.: Systematically Refactoring Inheritance to Delegation in Java. In: ICSE, pp. 431–440 (2008)Google Scholar
  18. 18.
    Kieżun, A., Ernst, M., Tip, F., Fuhrer, R.: Refactoring for parameterizing Java classes. In: ICSE, pp. 437–446 (2007)Google Scholar
  19. 19.
    Krinke, J.: Static Slicing of Threaded Programs. SIGPLAN Not. 33(7) (1998)Google Scholar
  20. 20.
    Lamport, L.: Time, clocks, and the ordering of events in a distributed system. ACM Commun. 21(7), 558–565 (1978)MATHCrossRefGoogle Scholar
  21. 21.
    Lea, D.: The JSR-133 Cookbook for Compiler Writers (2008), http://gee.cs.oswego.edu/dl/jmm/cookbook.html
  22. 22.
    Manson, J., Pugh, W., Adve, S.V.: The Java Memory Model. In: POPL, pp. 378–391. ACM, New York (2005)Google Scholar
  23. 23.
    Markstrum, S., Fuhrer, R.M., Millstein, T.D.: Towards concurrency refactoring for X10. In: PPOPP, pp. 303–304 (2009)Google Scholar
  24. 24.
    Naik, M., Aiken, A.: Conditional must not aliasing for static race detection. In: POPL. ACM Press, New York (2007)Google Scholar
  25. 25.
    Nilsson-Nyman, E., Ekman, T., Hedin, G., Magnusson, E.: Declarative Intraprocedural Flow Analysis of Java Source Code. In: LDTA (2008)Google Scholar
  26. 26.
    Opdyke, W.F.: Refactoring Object-Oriented Frameworks. PhD thesis, University Of Illinois at Urbana-Champaign (1992)Google Scholar
  27. 27.
    Schäfer, M., Ekman, T., de Moor, O.: Sound and Extensible Renaming for Java. In: Kiczales, G. (ed.) OOPSLA. ACM Press, New York (2008)Google Scholar
  28. 28.
    Schäfer, M., Verbaere, M., Ekman, T., de Moor, O.: Stepping Stones over the Refactoring Rubicon – Lightweight Language Extensions to Easily Realise Refactorings. In: Drossopoulou, S. (ed.) ECOOP 2009 – Object-Oriented Programming. LNCS, vol. 5653, pp. 369–393. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  29. 29.
    Steimann, F., Thies, A.: From Public to Private to Absent: Refactoring Java Programs under Constrained Accessibility. In: Drossopoulou, S. (ed.) ECOOP 2009 – Object-Oriented Programming. LNCS, vol. 5653, pp. 419–443. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  30. 30.
    Tip, F.: Refactoring using type constraints. In: Riis Nielson, H., Filé, G. (eds.) SAS 2007. LNCS, vol. 4634, pp. 1–17. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  31. 31.
    Tip, F., Kieżun, A., Bäumer, D.: Refactoring for generalization using type constraints. In: OOPSLA, pp. 13–26 (2003)Google Scholar
  32. 32.
    Torlak, E., Vaziri, M., Dolby, J.: MemSAT: Checking Axiomatic Specifications of Memory Models. In: PLDI 2010 (2010)Google Scholar
  33. 33.
    Watson, T.J.: Libraries for Analysis (WALA), http://wala.sf.net
  34. 34.
    Wloka, J., Sridharan, M., Tip, F.: Refactoring for Reentrancy. In: ESEC/FSE (2009)Google Scholar
  35. 35.
    Zhao, J.: Multithreaded Dependence Graphs for Concurrent Java Program. In: Int. Symp. on Softw. Eng. for Parallel and Distr. Syst. (1999)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Max Schäfer
    • 1
  • Julian Dolby
    • 2
  • Manu Sridharan
    • 2
  • Emina Torlak
    • 2
  • Frank Tip
    • 2
  1. 1.Computing LaboratoryOxford UniversityUK
  2. 2.IBM T.J. Watson Research Center 

Personalised recommendations