Supporting Concurrency Abstractions in High-Level Language Virtual Machines
Total Page:16
File Type:pdf, Size:1020Kb
Faculty of Science and Bio-Engineering Sciences Department of Computer Science Software Languages Lab Supporting Concurrency Abstractions in High-level Language Virtual Machines Dissertation Submitted for the Degree of Doctor of Philosophy in Sciences Stefan Marr Promotor: Prof. Dr. Theo D’Hondt Copromotor: Dr. Michael Haupt January 2013 Print: Silhouet, Maldegem © 2013 Stefan Marr 2013 Uitgeverij VUBPRESS Brussels University Press VUBPRESS is an imprint of ASP nv (Academic and Scientific Publishers nv) Ravensteingalerij 28 B-1000 Brussels Tel. +32 (0)2 289 26 50 Fax +32 (0)2 289 26 59 E-mail: [email protected] www.vubpress.be ISBN 978 90 5718 256 3 NUR 989 Legal deposit D/2013/11.161/010 All rights reserved. No parts of this book may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the author. DON’T PANIC ABSTRACT During the past decade, software developers widely adopted JVM and CLI as multi-language virtual machines (VMs). At the same time, the multicore revolution burdened developers with increasing complexity. Language im- plementers devised a wide range of concurrent and parallel programming concepts to address this complexity but struggle to build these concepts on top of common multi-language VMs. Missing support in these VMs leads to tradeoffs between implementation simplicity, correctly implemented lan- guage semantics, and performance guarantees. Departing from the traditional distinction between concurrency and paral- lelism, this dissertation finds that parallel programming concepts benefit from performance-related VM support, while concurrent programming concepts benefit from VM support that guarantees correct semantics in the presence of reflection, mutable state, and interaction with other languages and libraries. Focusing on these concurrent programming concepts, this dissertation finds that a VM needs to provide mechanisms for managed state, managed execution, ownership, and controlled enforcement. Based on these requirements, this disser- tation proposes an ownership-based metaobject protocol (OMOP) to build novel multi-language VMs with proper concurrent programming support. This dissertation demonstrates the OMOP’s benefits by building concur- rent programming concepts such as agents, software transactional memory, actors, active objects, and communicating sequential processes on top of the OMOP. The performance evaluation shows that OMOP-based implementa- tions of concurrent programming concepts can reach performance on par with that of their conventionally implemented counterparts if the OMOP is supported by the VM. To conclude, the OMOP proposed in this dissertation provides a unifying and minimal substrate to support concurrent programming on top of multi- language VMs. The OMOP enables language implementers to correctly im- plement language semantics, while simultaneously enabling VMs to provide efficient implementations. iii SAMENVATTING Over de laatste jaaren hebben softwareontikkelaars de JVM en CLI beginnen gebruiken als multi-language virtual machines (VM). Gelyktydig werd door de multicore revolutie de taak van de softwareontwikkelaar vermoeilijkt. Pro- grammeertaalontwerpers ontwikkelden een grote variëteit aan concurrente en parallelle programmeerconcepten, maar het implementeren van deze con- cepten bovenop de multi-language VM’s blijft een penibel probleem. Gebrek- kige ondersteuning hiervoor in de VM’s leidt tot afwegingen in de program- meertaalimplementaties tussen simpliciteit, correctheid en performantie. Vertrekkende van de traditionele verdeling tussen concurrent en parallel programmeren vindt deze verhandeling dat parallelle programmeerconcepten voordeel halen uit performantie-gerelateerde VM ondersteuning, gelykaardig halen concurrente programmeerconcepten voordeel halen uit correctheids- garanties van semantiek onder reflectie, mutable state en interactie met an- dere programmeertalen en libraries. Door het toe te spitsen op deze concurrente programmeerconcepten vindt deze verhandeling dat een VM mechanismen moet aanbieden voor managed state, managed execution, ownership en controlled enforcement. Daarop gebaseerd stelt deze verhandeling een ownership-based metaobject protocol (OMOP) voor om vernieuwende multi-language VM’s te bouwen met fatsoenlijke onderste- uning voor concurrente programmeerconcepten. We demonstreeren de voordelen van de OMOP door er concurrente pro- grammeerconcepten bovenop te bouwen, zoals agents, software transactional memory, actors, active object en communicating sequential processes. De per- formantieëvaluatie toont aan dat implementaties bovenop de OMOP van deze concurrente programmeerconcepten de performantie kan evenaren van con- ventionele implementaties, zolang de OMOP ondersteund is door de VM. In conclusie, de OMOP biedt een verenigd substraat aan om concurrent pro- grammeren te ondersteunen bovenop multi-language VM’s. De OMOP laat programmeertaalontwikkelaars toe om op een correcte manier de semantiek van een taal te implementeren, maar het laat ook deze VM’s toe om hiervoor een efficiënte implementatie te voorzien. v ACKNOWLEDGMENTS First and foremost, I would like to heartily thank my promotors Theo D’Hondt and Michael Haupt for their advice and support. I am truly grateful to Theo for the opportunity and freedom to pursue my research interests at his lab. I am greatly indebted to Michael for sparking my interest in virtual machines with his lectures and for his continuous support throughout the years. I sincerely thank the members of my Ph.D. committee for the time and effort they put into the evaluation of this work: David Ungar, Shigeru Chiba, Tom Van Cutsem, Wolfgang De Meuter, and Jacques Tiberghien. I am earnestly thankful to David Ungar and IBM Research for their collab- oration as part of the Renaissance project. His persistence in searching for the fundamental roots of a problem greatly influenced my work and thinking. To all of my colleagues of the Software Languages Lab, I am equally grate- ful. Your feedback guided my investigations for this dissertation. Moreover, I am truly indebted for your support from the very beginning. Your help was essential for me to successfully write and defend my scholarship proposal. Special thanks goes to the Parallel Programming Group for all of our insight- ful debates. I would especially like to thank Charlotte Herzeel and Bruno De Fraine for their feedback on the very first drafts of this dissertation. My personal thanks go to Stijn Timbermont and Elisa González Boix for “getting ze German started” at the lab and helping me to find my way in Brussels. I also want to thank Andoni, Andy, Carlos, Christophe, Coen, Eline, Engineer, Jorge, Lode, Nicolás, Wolf, et al. for their friendship and support. Ganz besonders möchte ich mich auch bei meinen Eltern und Schwestern für ihre bedingungslose Liebe, stetige Unterstützung und beständigen Rückhalt bedanken. I want to thank my friends in Brussels from all over the world. Brussels is a wonderful place to learn about cultural differences and I would not want to miss this experience, nor the beach volleyball during rainy summers. Thanks! Last but not least, I would like to thank Kimberly for her patience and understanding and the time we have together. This work is funded by a Ph.D. scholarship of IWT, for which I am grateful. vii CONTENTS 1. Introduction 1 1.1. Research Context . 2 1.2. Problem Statement . 3 1.3. Research Goals . 5 1.4. Dissertation Outline . 6 1.5. Supporting Publications and Technical Contributions . 8 2. Context and Motivation 13 2.1. Multi-Language Virtual Machines . 14 2.2. The Multicore Revolution . 17 2.3. Concurrent vs. Parallel Programming: Definitions . 18 2.3.1. Concurrency and Parallelism . 18 2.3.2. Concurrent Programming and Parallel Programming . 20 2.3.3. Conclusion . 23 2.4. Common Approaches to Concurrent and Parallel Programming 23 2.4.1. Taxonomies . 24 2.4.2. Threads and Locks . 26 2.4.3. Communicating Threads . 27 2.4.4. Communicating Isolates . 30 2.4.5. Data Parallelism . 33 2.4.6. Summary . 35 2.5. Building Applications: The Right Tool for the Job . 36 2.6. Summary . 37 3. Which Concepts for Concurrent and Parallel Progr. does a VM need to Support? 39 3.1. VM Support for Concurrent and Parallel Programming . 40 3.1.1. Survey Design . 40 3.1.1.1. Survey Questions . 40 ix Contents 3.1.1.2. Survey Subjects . 41 3.1.1.3. Survey Execution . 42 3.1.2. Results . 44 3.1.2.1. Threads and Locks . 45 3.1.2.2. Communicating Threads . 49 3.1.2.3. Communicating Isolates . 50 3.1.2.4. Data Parallelism . 53 3.1.2.5. Threats to Validity . 53 3.1.3. Conclusion . 55 3.2. A Survey of Parallel and Concurrent Programming Concepts . 56 3.2.1. Survey Design . 57 3.2.1.1. Survey Questions . 57 3.2.1.2. Selecting Subjects and Identifying Concepts . 58 3.2.2. Results . 59 3.2.3. Threats to Validity . 67 3.2.4. Summary . 67 3.2.4.1. General Requirements . 69 3.2.4.2. Connection with Concurrent and Parallel Pro- gramming . 70 3.2.4.3. Conclusions . 71 3.3. Common Problems for the Implementation of Concurrency Ab- stractions . 71 3.3.1. Overview . 71 3.3.2. Isolation . 72 3.3.3. Scheduling Guarantees . 75 3.3.4. Immutability . 77 3.3.5. Reflection . 79 3.3.6. Summary . 81 3.4. Requirements for a Unifying Substrate for Concurrent Program- ming . 82 3.5. Conclusions . 86 4. Experimentation Platform 89 4.1. Requirements for the Experimentation Platform . 90 4.2. SOM: Simple Object Machine . 90 4.2.1. Language Overview and Smalltalk Specifics . 91 4.2.2. Execution Model and Bytecode Set . 94 4.3. Squeak and Pharo Smalltalk . 100 x Contents 4.4. RoarVM . 101 4.4.1. Execution Model, Primitives, and Bytecodes . 102 4.4.2. Memory Systems Design . 104 4.4.3. Process-based Parallel VM . 107 4.4.4. Final Remarks . 107 4.5. Summary . 108 5. An Ownership-based MOP for Expressing Concurrency Abstractions109 5.1. Open Implementations and Metaobject Protocols . 110 5.2. Design of the OMOP . 113 5.3. The OMOP By Example . 118 5.3.1. Enforcing Immutability . 118 5.3.2.