Lock Inference for Java
Total Page:16
File Type:pdf, Size:1020Kb
Imperial College London Department of Computing Lock Inference for Java Khilan Gudka December 2012 Submitted in part fulfilment of the requirements for the degree of Doctor of Philosophy in Computing of Imperial College London and the Diploma of Imperial College London Abstract Atomicity is an important property for concurrent software, as it provides a stronger guarantee against errors caused by unanticipated thread interactions than race-freedom does. However, concurrency control in general is tricky to get right because current techniques are too low-level and error-prone. With the introduction of multicore processors, the problems are compounded. Consequently, a new software abstraction is gaining popularity to take care of concurrency control and the enforcing of atomicity properties, called atomic sections. One possible implementation of their semantics is to acquire a global lock upon entry to each atomic section, ensuring that they execute in mutual exclusion. However, this cripples con- currency, as non-interfering atomic sections cannot run in parallel. Transactional memory is another automated technique for providing atomicity, but relies on the ability to rollback con- flicting atomic sections and thus places restrictions on the use of irreversible operations, such as I/O and system calls, or serialises all sections that use such features. Therefore, from a language designer's point of view, the challenge is to implement atomic sections without compromising performance or expressivity. This thesis explores the technique of lock inference, which infers a set of locks for each atomic section, while attempting to balance the requirements of maximal concurrency, minimal locking overhead and freedom from deadlock. We focus on lock-inference techniques for tackling large Java programs that make use of mature libraries. This improves upon existing work, which either (i) ignores libraries, (ii) requires library implementors to annotate which locks to take, or (iii) only considers accesses performed up to one-level deep in library call chains. As a result, each of these prior approaches may result in atomicity violations. This is a problem because even simple uses of I/O in Java programs can involve large amounts of library code. Our approach is the first to analyse library methods in full and thus able to soundly handle atomic sections involving complicated real-world side effects, while still permitting atomic sections to run concurrently in cases where their lock sets are disjoint. To validate our claims, we have implemented our techniques in Lockguard, a fully automatic tool that translates Java bytecode containing atomic sections to an equivalent program that uses locks instead. We show that our techniques scale well and despite protecting all library accesses, we obtain performance comparable to the original locking policy of our benchmarks. i ii Dedication I would like to dedicate this thesis to Bhagwan Swaminarayan and to my guru, His Holiness Pramukh Swami Maharaj. I would like to thank them from the bottom of my heart for blessing me with this human body, for constantly inspiring me throughout my life and for giving me inner strength and intellect, only with which have I been able to pursue this PhD. Bhagwan Swaminarayan His Holiness Pramukh Swami Maharaj Brief biography of Bhagwan Swaminarayan Bhagwan Swaminarayan was born on 3rd April 1781, in the village of Chhapaiya, near Ayodhya, North India. Having mastered the scriptures by the age of seven, he renounced home at 11 to embark upon a seven-year spiritual pilgrimage on foot across the length and breadth of India. Eventually settling in Gujarat, he spent the next 30 years spearheading a spiritual revolution. He established the Swaminarayan Sampradaya to reinforce the Vedic philosophy of Akshar- Purushottam. This philosophy essentially means: to devote oneself to God by becoming like his choicest disciple. He introduced religious and humanitarian reforms, serving the poor and the needy, challenging superstition, addictions and blind faith. His work concentrated on promoting personal morality, moulding spiritual character and most importantly, showing countless souls the means to attain ultimate redemption from the cycle of birth and death. In his own lifetime, he was worshipped as the supreme God by hundreds of thousands of devotees. He promised to remain ever present on earth through a succession of spiritual gurus: Aksharbrahman Gunatitanand Swami, Bhagatji Maharaj, Shastriji Maharaj, Yogiji Maharaj and presently His Holiness Pramukh Swami Maharaj. iii Brief biography of His Holiness Pramukh Swami Maharaj His Holiness Pramukh Swami Maharaj is the present spiritual leader of Bochasanwasi Shri Akshar Purushottam Swaminarayan Sanstha (BAPS). He leads an austere life of lifetime celibacy, without personal wealth or comfort. Representing the essence of Hinduism, his compassion for humanity, universal wisdom and striking simplicity, have touched many individuals, including religious, national and international leaders. However, most important is his quiet, undisturbed love for God, which rises beyond all borders of nation, race and religion. This resonates in his lifelong motto of `In the joy of others, lies our own.' Alongside spiritual activities, BAPS also has a charitable trust called BAPS Charities. Their noble activities include sponsored walks and bike-ride challenges, blood-donation drives, hospitals and mobile medical services, anti-addiction camps, welfare services for tribal communities, educational institutions and disaster-relief work like earthquakes, tsunamis, hurricanes and floods. Please visit http://www.baps.org for more information. iv Acknowledgements I would like to express my sincere gratitude to: • My supervisor Professor Susan Eisenbach, for being such a great advisor and friend over the last few years. Her trust in my ability and patience have enabled me to gradually develop into a confident researcher. I would not have been able to reach such a successful conclusion to my thesis without her support and guidance. • My second supervisor Professor Sophia Drossopoulou, for our discussions and her enthu- siasm in all aspects of my work. • Microsoft Research Cambridge, for funding my PhD as part of their PhD Scholarship Programme. In particular, I would like to thank my sponsor Tim Harris, for being a great mentor. I have enjoyed the many chats we have had about the work. • David Cunningham, who first introduced me to atomic sections and lock inference. He also had the original idea of representing object accesses as lvalue expressions. I feel fortunate to have been able to work with him during my Masters thesis and first year of my PhD. His helpful nature, ability to think very quickly and motto of \functionality first” inspired me in many ways. • The SLURP research group, for the immensely useful feedback for various aspects of my work and the interesting discussions over the years. In particular, I would like to thank my office mate Tristan, for the many whiteboard sessions and suggestions about how to develop my ideas. • Members of the Soot, Jikes RVM, concurrency-interest and trans-memory mailing lists for their advice on technical matters. Their help has saved me a lot of time and hair pulling. • My PhD examiners for making my viva experience a very positive and enjoyable one. I would also like to thank them for their thorough review of my thesis and resulting suggested improvements, which have boosted its quality tremendously. v • Pujya Tyagprakash Swami, a sadhu from the BAPS Shri Swaminarayan Mandir in Neas- den, London, for his guidance, support and encouragement throughout. I first met him in the summer of 2007 in Los Angeles, just before commencing my PhD. During this first meeting, he advised me at great length about the attitude and organisation that I would need to keep, having completed a PhD himself. He is one of the most intelligent people I have had the fortune to meet, and I feel blessed to have been able to benefit from his vast knowledge and experience. • My parents, for nurturing me into the person that I am today. They have constantly encouraged and supported me, both emotionally and financially, to achieve higher and reach my true potential. There is no way that I can repay them. • Finally, my dear wife Meha, for always being there for me and constantly showering her love and support. Thank you for patiently tolerating the many months that I spent writing this thesis. You are my best friend and life partner. I pray that may our love for each other only grow stronger with every passing moment. vi Statement of Originality The implementation of lockguard and the algorithms described in this thesis are my own work. The original idea of representing object accesses as lvalue expressions originates from David Cunningham. David Cunningham, Professor Susan Eisenbach and I co-authored a paper, entitled \Keep Off The Grass: Locking the Right Path for Atomicity" [CGE08] describing this approach and the idea of representing lvalue expressions as nondeterministic finite automata. This work is part of David's PhD, but we jointly came up with the idea during my Master's thesis and the second year of his PhD. Using type locks for protecting unbounded accesses and multi-granularity locking to simultaneously support instance and type locking were also David's ideas. Professor Susan Eisenbach, Tim Harris and I co-authored a paper, entitled \Lock Inference in the Presence of Large Libraries" [GHE12]. This formed the technical basis of Chapter 3, Chapter 4 and Chapter 5. The technical contributions of the paper are my own. Professor Susan Eisenbach and I co-authored a paper, entitled \Fast Multi-Level Locks for Java" [GE10]. The technical contributions of this paper are also my own and form the basis of Section 5.2. The multi-granularity locking protocol is borrowed from Gray et al. [GLP75]. Professor Sophia Drossopoulou provided detailed feedback about this paper. In Chapter 4, the control flow graph summarisation technique is borrowed from Rountev et al. [RSX08]. Their paper also gave us the inspiration to use the IDE analysis framework for our object-access inference analysis.