一句话:提出基于程序分析与下推自动机的自动重构工具 FineLock,将粗粒度锁转换为细粒度锁以降低锁竞争。
锁是共享资源互斥访问的常用同步机制,但基于锁的并发程序容易因锁竞争而性能低、扩展性差;锁粒度不当会进一步加剧竞争。细粒度锁可缓解竞争,却难以正确使用,手工将粗粒度锁转换为细粒度锁既繁琐易错,又需要大量专门经验。本文提出结合程序分析与下推自动机的自动化重构方法,将粗粒度锁转换为细粒度锁以降低锁竞争。作者实现原型工具 FineLock,并在5个项目上评估。结果显示,FineLock 平均27.6秒可重构1546个锁,其中129个粗粒度锁被转换为细粒度锁,1417个被转换为读写锁;自动给出潜在重构建议,为开发者节省大量精力。
Lock is a frequently-used synchronization mechanism to enforce exclusive access to a shared resource. However, lock-based concurrent programs are susceptible to lock contention, which leads to low performance and poor scalability. Furthermore, inappropriate granularity of a lock makes lock contention even worse. Compared to coarse-grained lock, fine-grained lock can mitigate lock contention but difficult to use. Converting coarse-grained lock into fine-grained lock manually is not only error-prone and tedious, but also requires a lot of expertise. In this paper, we propose to leverage program analysis techniques and pushdown automaton to automatically covert coarse-grained locks into fine-grained locks to reduce lock contention. We developed a prototype FineLock and evaluates it on 5 projects. The evaluation results demonstrate FineLock can refactor 1,546 locks in an average of 27.6 seconds, including converting 129 coarse-grained locks into fine-grained locks and 1,417 coarse-grained locks into read/write locks. By automatically providing potential refactoring recommendations, our tool saves a lot of efforts for developers.