Adaptive Optimization for Self: Reconciling High Performance with Exploratory Programming
Total Page:16
File Type:pdf, Size:1020Kb
ADAPTIVE OPTIMIZATION FOR SELF: RECONCILING HIGH PERFORMANCE WITH EXPLORATORY PROGRAMMING A DISSERTATION SUBMITTED TO THE DEPARTMENT OF COMPUTER SCIENCE AND THE COMMITTEE ON GRADUATE STUDIES IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF DOCTOR OF PHILOSOPHY Urs Hölzle August 1994 © Copyright by Urs Hölzle 1994 All rights reserved I certify that I have read this dissertation and that in my opinion it is fully adequate, in scope and quality, as a dissertation for the degree of Doctor of Philosophy. _______________________________________ David M. Ungar (Principal Advisor) I certify that I have read this dissertation and that in my opinion it is fully adequate, in scope and quality, as a dissertation for the degree of Doctor of Philosophy. _______________________________________ John L. Hennessy (Co-Advisor) I certify that I have read this dissertation and that in my opinion it is fully adequate, in scope and quality, as a dissertation for the degree of Doctor of Philosophy. _______________________________________ L. Peter Deutsch I certify that I have read this dissertation and that in my opinion it is fully adequate, in scope and quality, as a dissertation for the degree of Doctor of Philosophy. _______________________________________ John C. Mitchell Approved for the University Committee on Graduate Studies: _______________________________________ iii iv Abstract Object-oriented programming languages confer many benefits, including abstraction, which lets the programmer hide the details of an object’s implementation from the object’s clients. Unfortunately, crossing abstraction boundaries often incurs a substantial run-time overhead in the form of frequent procedure calls. Thus, pervasive use of abstrac- tion, while desirable from a design standpoint, may be impractical when it leads to inefficient programs. Aggressive compiler optimizations can reduce the overhead of abstraction. However, the long compilation times introduced by optimizing compilers delay the programming environment‘s responses to changes in the program. Furthermore, optimization also conflicts with source-level debugging. Thus, programmers are caught on the horns of two dilemmas: they have to choose between abstraction and efficiency, and between responsive programming envi- ronments and efficiency. This dissertation shows how to reconcile these seemingly contradictory goals by performing optimizations lazily. Four new techniques work together to achieve high performance and high responsiveness: • Type feedback achieves high performance by allowing the compiler to inline message sends based on information extracted from the runtime system. On average, programs run 1.5 times faster than the previous SELF system; compared to a commercial Smalltalk implementation, two medium-sized benchmarks run about three times faster. This level of performance is obtained with a compiler that is both simpler and faster than previous SELF compilers. • Adaptive optimization achieves high responsiveness without sacrificing performance by using a fast non- optimizing compiler to generate initial code while automatically recompiling heavily used parts of the program with an optimizing compiler. On a previous-generation workstation like the SPARCstation-2, fewer than 200 pauses exceeded 200 ms during a 50-minute interaction, and 21 pauses exceeded one second. On a current- generation workstation, only 13 pauses exceed 400 ms. • Dynamic deoptimization shields the programmer from the complexity of debugging optimized code by transparently recreating non-optimized code as needed. No matter whether a program is optimized or not, it can always be stopped, inspected, and single-stepped. Compared to previous approaches, deoptimization allows more debugging while placing fewer restrictions on the optimizations that can be performed. • Polymorphic inline caching generates type-case sequences on-the-fly to speed up messages sent from the same call site to several different types of object. More significantly, they collect concrete type information for the optimizing compiler. With better performance yet good interactive behavior, these techniques make exploratory programming possible both for pure object-oriented languages and for application domains requiring higher ultimate performance, recon- ciling exploratory programming, ubiquitous abstraction, and high performance. v vi Acknowledgments No Ph. D. thesis can be written without the help of others, and I am deeply indebted to the people who made this dissertation possible. I was fortunate to find a great advisor in David Ungar, who taught me how to do research and, equally important, how to write about it. He always asked the right questions early on and persisted until I had an answer. I would also like to thank my dissertation readers, Peter Deutsch, John Hennessy, and John Mitchell, for their advice and their comments on drafts of this thesis. It was Peter and Dave’s work on Smalltalk implementations that originally sparked my interest in the field many years ago. Craig Chambers and Bay-Wei Chang helped me get started on SELF by patiently answering many questions when I joined the SELF group in 1989. Together with the more recent members of the project—Ole Agesen, Lars Bak, John Maloney, Randy Smith, and Mario Wolczko—they made sure we never ran out of topics to discuss, and created the unique atmosphere that made working on SELF so much fun. I will miss you, guys. I have learned much from many interesting discussions with others, including Walter Bischofberger, Günther Blaschek, Bob Cmelik, Amer Diwan, Claus Gittinger, Robert Griesemer, Görel Hedin, Barry Hayes, David Keppel, Peter Kessler, Ole Lehrmann Madsen, Boris Magnusson, Eliot Moss, Stephan Murer, Jens Palsberg, Peter Schnorf, Michael Schwartzbach, Paul Wilson, and Ben Zorn. I would also like to thank Robert Griesemer for his comments on earlier drafts and for proofreading the final draft. Many others in CIS, at Stanford, and at Sun made my stay here so enjoyable, as well as my friends of the Dinner Club and DINAC (Dessert Is Never A Chore) whom I have to thank for many pleasant evenings. Last but not least, I am deeply indebted to Geeske who changed my life much more than graduate study ever could. Finally, I wish to thank all the organizations who generously provided financial support, especially Sun Microsystems Laboratories, the Swiss Nationalfonds, and the Fulbright program. vii viii Table of Contents Table of Contents ............................................................................................................................................ix List of Figures .............................................................................................................................................. xiii List of Tables .............................................................................................................................................. xvii 1. Introduction .....................................................................................................................................................1 2. Background and related work ..........................................................................................................................3 2.1 The SELF language ..................................................................................................................................3 2.2 The SELF system .....................................................................................................................................4 2.2.1 Overview of the implementation .......................................................................................................4 2.2.2 Efficiency ...........................................................................................................................................5 2.2.3 Source-level semantics ......................................................................................................................6 2.2.4 Direct execution semantics ................................................................................................................7 2.3 Overview of the compilation process .......................................................................................................7 2.4 Benefits of this work .................................................................................................................................8 2.5 Related work .............................................................................................................................................9 2.5.1 Dynamic compilation ........................................................................................................................9 2.5.2 Customization ....................................................................................................................................9 2.5.3 Previous SELF compilers ................................................................................................................10 2.5.4 Smalltalk-80 compilers ...................................................................................................................11 2.5.4.1 The Deutsch-Schiffman system ...............................................................................................11 2.5.4.2 SOAR .......................................................................................................................................11 2.5.4.3 Other Smalltalk compilers .......................................................................................................11