Abstract:As coarse-grained locks have a negative impact on the scalability of concurrent programs, this study proposes an automatic refactoring approach to convert a coarse-grained lock into a fine-grained one. Several static analyses, such as visitor pattern analysis, alias analysis, and side-effect analysis are employed in this approach. The read and write pattern of a critical section is inferred by side effect analysis, and then a push down automaton is proposed to identify the read and write pattern. Finally, refactoring is conducted based on these results. An automatic tool FLock is implemented as the Eclipse plug-in. The proposed approach is evaluated by eleven open-source projects including HSQLDB, Jenkins, and Cassandra, by presenting results such as the number of refactored locks, changed lines of code, refactoring time, accuracy, program performance after refactoring. FLock is also compared with the existing tools Relocker and CLOCK. The experimental results show that a total of 1757 built-in monitors are refactored and each refactoring takes an average of 17.5 seconds. The experiments reveal that the proposed tool can help developers convert coarse-grained locks into fine-grained locks effectively.