Heap-Based Reasoning About Asynchronous Programs

Heap-Based Reasoning About Asynchronous Programs

Heap-based reasoning about asynchronous programs Vom Fachbereich Informatik der Technischen Universität Kaiserslautern zur Verleihung des akademischen Grades Doktor der Ingenieurwissenschafen (Dr.-Ing.) genehmigte Dissertation von Johannes Kloos Datum der wissenschaftlichen Aussprache: 14.06.2018 Dekan: Stefan Deßloch Berichterstatter: Rupak Majumdar Berichterstatter: Ranjit Jhala Berichterstatter: Viktor Vafeiadis D 386 Contents 1. Introduction1 1.1. How does asynchronous programming differ from other models? . .2 1.2. State of the art . .3 1.3. Contributions of this thesis . .4 2. Related work7 2.1. Asynchronous and event-driven programming . .7 2.2. Analysis and testing of asynchronous programs . .9 2.3. Deductive verification and semantics . 10 2.4. Type systems . 13 2.5. Optimization and parallelisation . 14 2.6. Proving refinement and behavior inclusion . 15 2.7. Automated program analysis . 16 3. Asynchronous Liquid Separation Types 19 3.1. Examples and Overview . 20 3.1.1. A core calculus for asynchronous programming . 20 3.1.2. Promise types . 21 3.1.3. Refinement types . 21 3.1.4. Refinements and state: strong updates . 22 3.1.5. Asynchrony and shared resources . 24 3.1.6. Detecting concurrency pitfalls . 25 3.2. The Type System . 26 3.2.1. Typing rules . 28 3.2.2. Value and expression typing . 29 3.2.3. Type safety . 31 3.3. Type Inference . 32 3.4. Case Studies . 36 3.4.1. The double-buffering example, revisited . 37 3.4.2. Another asynchronous copying loop . 38 3.4.3. Coordination in a parallel SAT solver . 40 3.4.4. The MirageOS FAT file system . 41 3.5. Limitations . 42 4. DontWaitForMe 43 4.1. A core calculus and type system . 44 4.1.1. A program logic for asynchronous programs . 46 iii Contents 4.1.2. Semantics of types . 49 4.2. Relational reasoning for asynchronous programs . 55 4.2.1. The rewrite rules . 55 4.2.2. Why existing methods are not sufficient . 57 4.2.3. Delayed refinement . 64 4.2.4. Closure properties and the fundamental lemma . 70 4.2.5. Soundness of DontWaitForMe . 73 4.2.6. Connection to standard soundness criteria . 75 5. Loading JavaScript asynchronously — JSDefer 77 5.1. Background: Loading JavaScript . 78 5.2. Deferrability analysis . 80 5.2.1. A hypothetical static approach . 81 5.2.2. Background: Event traces and races in web pages . 82 5.2.3. When is a set of scripts deferrable? . 83 5.2.4. JSDefer: A dynamic analysis for deferrability . 84 5.3. Evaluation . 86 5.3.1. Tools and environment . 86 5.3.2. How are async and defer used so far? . 87 5.3.3. Are our assumptions justified? . 88 5.3.4. Can we derive deferrability annotations for scripts? . 89 5.3.5. Does deferring actually gain performance? . 91 5.3.6. Threats to validity . 96 5.4. Soundness of the analysis . 96 6. Conclusion 101 A. Type safety for ALST 121 A.1. Adapting the type system . 121 A.2. The statement of type preservation . 122 A.3. The type preservation proof . 124 B. Delayed refinement and soundness of DWFM 131 B.1. Overview of the development . 131 B.1.1. corecalculus . 133 B.1.2. types . 134 B.1.3. specification . 134 B.1.4. typetranslation . 135 B.1.5. delayed . 136 B.2. Interesting proofs . 137 C. Curriculum Vitae 147 iv Summary Asynchronous concurrency is a wide-spread way of writing programs that deal with many short tasks. It is the programming model behind event-driven concurrency, as exemplified by GUI applications, where the tasks correspond to event handlers, web applications based around JavaScript, the implementation of web browsers, but also of server-side software or operating systems. This model is widely used because it provides the performance benefits of concurrency together with easier programming than multi-threading. While there is ample work on how to implement asynchronous programs, and significant work on testing and model checking, little research has been done on handling asynchronous programs that involve heap manipulation, nor on how to automatically optimize code for asynchronous concurrency. This thesis addresses the question of how we can reason about asynchronous programs while considering the heap, and how to use this this to optimize programs. The work is organized along the main questions: (i) How can we reason about asynchronous programs, without ignoring the heap? (ii) How can we use such reasoning techniques to optimize programs involving asynchronous behavior? (iii) How can we transfer these reasoning and optimization techniques to other settings? The unifying idea behind all the results in the thesis is the use of an appropriate model encompassing global state and a promise-based model of asynchronous concurrency. For the first question, We start from refinement type systems for sequential programs and extend them to perform precise resource-based reasoning in terms of heap contents, known outstanding tasks and promises. This extended type system is known as Asynchronous Liquid Separation Types, or ALST for short. We implement ALST in for OCaml programs using the Lwt library. For the second question, we consider a family of possible program optimizations, described by a set of rewriting rules, the DWFM rules. The rewriting rules are type- driven: We only guarantee soundness for programs that are well-typed under ALST. We give a soundness proof based on a semantic interpretation of ALST that allows us to show behavior inclusion of pairs of programs. For the third question, we address an optimization problem from industrial practice: Normally, JavaScript files that are referenced in an HTML file are be loaded synchronously, i.e., when a script tag is encountered, the browser must suspend parsing, then load and execute the script, and only after will it continue parsing HTML. But in practice, there are numerous JavaScript files for which asynchronous loading would be perfectly sound. First, we sketch a hypothetical optimization using the DWFM rules and a static analysis. To actually implement the analysis, we modify the approach to use a dynamic analysis. This analysis, known as JSDefer, enables us to analyze real-world web pages, and provide experimental evidence for the efficiency of this transformation. v Zusammenfassung Asynchrone Nebenläufigkeit ist ein gängiger Weg, Programm zu schreiben, die aus vielen kleinen Tätigkeiten (“Tasks”) bestehen. Es ist das Programmiermodell hinter ereignisgetrie- bener Nebenläufigkeit, wie in: GUI-Anwendungen, wo die Tasks die Ereignis-Behandlung erledigen; Web-Anwendungen auf Basis von JavaScript; Web-Browsern sowie Servern und Betriebssystemen. Das Modell ist weit verbreitet, da es die Leistungsvorteile der Nebenläufigkeit mit einem einfacheren Programmiermodell als Multi-Threading verbindet. Zwar gibt es viele Arbeiten über die Implementierung asynchroner Programme, wie auch über Testen und Model Checking, doch wurde wenig in die Richtung geforscht, wie man mit asynchronen Programmen, die den Heap manipulieren, umgeht, noch wie man Programme automatisch für asynchrone Nebenläufigkeit optimieren kann. Diese Dissertation behandelt die Frage, wie man über asynchrone Programme unter Einbeziehung des Heaps argumentieren kann, und wie man damit Programm optimiert. Die Arbeit ist auf drei Grundfragen aufgebaut: (i) Wie kann man über asynchrone Programme argumentieren, ohne den Heap zu ignorieren? (ii) Wie kann man mit solchen Techniken Programm mit asynchronem Verhalten optimieren? (iii) Wie kann man solche Techniken auf andere Gebiete übertragen? Die vereinheitlichende Idee hinter allen Resultaten der Dissertation ist die Verwen- dung eines geeigneten Modells, das den globalen Programmzustand und ein promise- basiertes Modell asynchroner Nebenläufigkeit enthält. Für die erste Frage gehen wir von Verfeinerungs-Typsystemen für sequentielle Programme aus und erweitern sie um ein präzises Resourcenmodell aus Heap-Inhalt, bekanntermaßen ausstehenden Tasks und Promises. Dieses erweiterte Typsystem heißt Asynchronous Liquid Separation Types, kurz ALST. Wir implementieren ALST für OCaml-Programme mit der Lwt-Bibliothek. Für die zweite Frage betrachten wir eine Familie potentieller Programm-Optimierungen in Form von Rewriting-Regeln, die DWFM-Regeln. Die regeln sind typgetrieben: Wir garantieren Korrektheit nur für Programme, die ALST-wohltypisiert sind. Wir führen einen Korrektheitsbeweis auf Basis einer semantischen Interpretation von ALST, die uns erlaubt, Verhaltensinklusion von Programmpaaren zu zeigen. Für die dritte Frage gehen wir ein Optimierungsproblem aus der Praxis an: Norma- lerweise werden JavaScript-Dateien, die in einer HTML-Datei verlinkt sind, synchron geladen, d.h., wenn ein script-Tag gelesen wird, muss der Browser anhalten, das Skript laden und ausführen, und darf dann erst das HTML-Parsing fortsetzen. Aber in der Praxis gibt es viele JavaScript-Dateien, für die asynchrones Laden unproblematisch wäre. Wir zeigen zuerst eine hypothetische Optimierung auf Basis von DWFM und einer statischen Analyse. Um die Analyse tatsächlich zu implementieren, ändern wir den Ansatz, indem wir eine dynamische Analyse verwenden. Diese Analyse, JSDefer, erlaubt uns, realistische Webseiten zu analysieren, und liefert experimentelle Daten für die Effizienz dieser Trans- formation. vii Contents Acknowledgements The work that went into this PhD thesis could not have been completed without the help of a great number of individualsl. First of all, I thank my supervisor Rupak Majumdar for his continued guidance and support during my PhD time. He was a wise mentor and a great supervisor, and helped me learn a lot of what I know today. It has to be said that the depth of his knowledge is truly awe-inspiring. Second, I wish to thank my co-author and reviewer Viktor Vafeiadis. He was always willing to have a scientific discussion, and would provide me with important insights. I also wish to thank my third reviewer, Prof. Ranjit Jhala, and my PhD committee, Professors Schweitzer, Poetzsch-Heffter and Schneider, for the work they put into reviewing my thesis and hold my PhD defense. Next, I want to thank all the many people that accompanied me on my way through my PhD, whether at MPI-SWS or at Instart Logic and Menlo Park Hacker Home.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    156 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us