Abstract
With the keyword synchronized, Java provides a simple but often over-used synchronization mechanism. Many programmers tend to use a big synchronized section to protect a large block of statements even if many of them are unnecessarily synchronized. Such coarse-gained synchronizations may increase lock contention and thereby decrease the performance of a program, especially in a multi-core environment. The decrease in performance may affect the quality of service provided by the software and hence make the software less trustworthy. To ensure trustworthiness, this paper proposes a source-code level refactoring approach to optimize coarse-gained synchronizations. It exploits dependence and escape information to search for shrinkable critical sections and can transform them into smaller ones automatically. The approach can be used to gradually evolve concurrent code for better quality. In the approach, to achieve more optimizations, we develop a new escape analysis, named escape state analysis, which can not only tell us whether an object finally escapes but also determine the escape states of objects at each program site. With such an analysis, more refactoring opportunities can be found. We build a tool and test our refactoring approach on several benchmark programs. The results show that the proposed approach does make effective refactoring suggestions for the users.
Similar content being viewed by others
Explore related subjects
Find the latest articles, discoveries, and news in related topics.References
Aldrich J, Chambers C, Sirer E G, et al. Static analyses for eliminating unnecessary synchronization from Java programs. In: Proceedings of the Static Analysis Symposium (SAS), Venezia, 1999. 19–38
Blanchet B. Escape analysis for object oriented languages: application to Java. In: Proceedings of the ACM Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), Colorado, 1999. 20–34
Bogda J, Hölzle U. Removing unnecessary synchronization in Java. In: Proceedings of the ACM Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), Colorado, 1999. 35–46
Choi J-D, Gupta M, Serrano M, et al. Escape analysis for Java. In: Proceedings of the ACM Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), Colorado, 1999. 1–19
Kotzmann T, Mossenbock H. Escape analysis in the context of dynamic compilation and deoptimization. In: Proceedings of the 1st ACM/USENIX International Conference on Virtual Execution Environments (VEE), Chicago, 2005. 111–120
Lee K, Fang X, Midkiff S P. Practical escape analyses: how good are they? In: Proceedings of the 3rd International Conference on Virtual Execution Environments (VEE), San Diego, 2007. 180–190
Ruf E. Effective synchronization removal for Java. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), Berlin, 2002. 208–218
Sǎalcianu A, Rinard M. Pointer and escape analysis for multithreaded programs. In: Proceedings of the 8th ACM SIGPLAN Symposium on Principles and Practices of Parallel Programming (PPoPP), Snowbird, 2001. 12–23
Stoodley M, Sundaresan V. Automatically reducing repetitive synchronization with a just-in-time compiler for Java. In: Proceedings of the International Symposium on Code Generation and Optimization (CGO), San Jose, 2005. 27–36
Whaley J, Rinard M. Compositional pointer and escape analysis for Java programs. In: Proceedings of the ACM Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), Colorado, 1999. 187–206
Wong C-L. Thread escape analysis for a memory consistency-aware compiler. Dissertation for the Doctoral Degree. University of Illinois at Urbana-Champaign, 2005
Goetz B, Peierls T, Bloch J, et al. Java Concurrency in Practice. Addison Wesley Professional, 2006
Greenhouse A, Halloran T J, Scherlis W L. Observations on the assured evolution of concurrent Java programs. Sci Comput Program, 2005, 58: 384–411
Lea D. Concurrent Programming in Java: Design Principles and Patterns, 2nd ed. Addision-Wesley, 1999
Dig D, Tarce M, Radoi C, et al. Relooper: refactoring for loop parallelism in Java. In: Proceeding of the 24th ACM SIGPLAN Conference on Object Oriented Programming Systems, Languages, and Applications (OOPSLA), Orlando, 2009. 793–794
Dig D, Marrero J, Ernst M D. Refactoring sequential Java code for concurrency via concurrent libraries. In: Proceedings of the 31st IEEE International Conference on Software Engineering (ICSE), Vancouver, 2009. 397–407
Sixth and Red River Software. LockSmith: Powerful concurrency-oriented refactorings for IntelliJ IDEA. http://www.sixthandredriver.com/locksmith.html
Schäfer M, Sridharan M, Dolby J, et al. Refactoring Java programs for flexible locking. In: Proceedings of the 33rd IEEE International Conference on Software Engineering (ICSE), Waikiki, Honolulu, HI, 2011. 71–80
Naik M. Effective static race detection for Java. Dissertation for the Doctoral Degree. Stanford University, 2008
Prabhu P, Shankar P. Field flow sensitive pointer and escape analysis for Java using heap array SSA. In: Proceedings of the Static Analysis Symposium (SAS), Valencia, 2008. 110–127
Vivien F, Rinard M. Incrementalized pointer and escape analysis. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), Snowbird, 2001. 35–46
Vallée-Rai R, Hendren L, Sundaresan V, et al. Soot-a Java bytecode optimization framework. In: Proceedings of the Conference of the Centre for Advanced Studies on Collaborative Research (CASCON), Mississauga, 1999. 125–135
Fowler M. Refactoring: Improving the Design of Existing Programs. Addison-Wesley, 1999.
Hind M. Pointer analysis: Haven’t we solved this problem yet? In: Proceedings of the ACM Workshop on Program Analysis for Software Tools and Engineering (PASTE), Snowbird, 2001. 54–61
Chatterjee R, Ryder B G, Landi W A. Relevant context inference. In: Proceedings of the 26th ACM SIGPLANSIGACT Symposium on Principles of Programming Languages (POPL), San Antonio, 1999. 133–146
Cheng B C, Hwu W W. Modular interprocedural pointer analysis using access paths: design, implementation, and evaluation. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), Britith Columbia, 2000. 57–69
Diwan A, McKinley K S, Eliot J, et al. Type-based alias analysis. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), Montreal, 1998. 106–117
Cooper K D, Kennedy K. Interprocedural side-effect analysis in linear time. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), Atlanta, 1988. 57–66
Gay D, Steensgaard B. Fast escape analysis and stack allocation for object-based programs. In: Proceedings of the 9th International Conference on Compiler Construction (CC), Paphos, 2000. 82–93
Muchnick S S. Advanced Compiler Design and Implementation. Academic Press, 1997
Chen Z, Xu B, Zhao J. An overview of methods for dependence analysis of concurrent programs. ACM Sigplan Not, 2002, 37: 45–52
Manson J, Pugh W, Adve S V. The Java memory model. In: Proceedings of the 32nd ACM Symposium on Principles of Programming Languages (POPL), Long Beach, 2005. 378–391
Gosling J, Joy B, Steele G, et al. JavaTMLanguage Specification, 7th ed. Oracle, 2011
Eclipse Foundation, Inc. Eclipse Java development tools (JDT). http://www.eclipse.org/jdt/
Blackburn S M, Garner R, Hoffman C, et al. The DaCapo benchmarks: Java benchmarking development and analysis. In: Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), Portland, 2006. 169–190
Diniz P, Rinard M. Synchronization transformations for parallel computing. In: Proceedings of the ACM Symposium on Principle of Programming Languages (POPL), Paris, 1997. 187–200
Diniz P, Rinard M. Lock coarsening: eliminating lock overhead in automatically parallelized object-based programs. J Parallel Distrib Comput, 1998, 49: 218–244
Schäfer M, Dolby J, Sridharan M, et al. Correct refactoring of concurrent java code. In: Proceedings of the European Conference on Object-Oriented Programming (ECOOP), Maribor, 2010. 225–249
Markstrum S, Fuhrer R, Millstein T. Towards concurrency refactoring for X10. In: Proceedings of the ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP), Raleigh, 2009. 303–304
Wloka J, Sridharan M, Tip F. Refactoring for reentrancy. In: Proceedings of the ACM SIGSOFT Symposium on the Foundations of Software Engineering (FSE), Amsterdam, 2009. 173–182
Damevski K, Muralimanohar M. A refactoring tool to extract GPU kernels. In: Proceedings of the 4th Workshop on Refactoring Tools (WRT), Waikiki, Honolulu, HI, 2011. 29–32
Brown C, Hammond K, Danelutto M, et al. A language-independent parallel refactoring framework. In: Proceedings of the 5th ACM Workshop on Refactoring Tools (WRT), Rapperswil, 2012. 54–58
Cherem S, Rugina R. A practical escape and effect analysis for building lightweight method summaries. In: Proceedings of the International Conference on Compiler Construction (CC), Braga, 2007. 172–186
Edvinsson M, Lundberg J, Lowe W. Parallel reachability and escape analyses. In: Proceedings of the 10th IEEE International Workshop on Source Code Analysis and Manipulation (SCAM), Timişoara, 2010. 125–134
Beers M Q, Stork C H, Franz M. Efficiently verifiable escape analysis. In: Proceedings of the European Conference on Object-Oriented Programming (ECOOP), Oslo, 2004. 60–81
von Praun C, Gross T R. Static conflict analysis for multi-threaded object oriented programs. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), San Diego, 2003. 115–128
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
About this article
Cite this article
Qian, J., Chen, L. & Xu, B. Finding shrink critical section refactoring opportunities for the evolution of concurrent code in trustworthy software. Sci. China Inf. Sci. 56, 1–20 (2013). https://doi.org/10.1007/s11432-012-4743-z
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11432-012-4743-z