Surgical precision JIT compilers

Just-in-time (JIT) compilation of running programs provides more optimization opportunities than offline compilation. Modern JIT compilers, such as those in virtual machines like Oracle's HotSpot for Java or Google's V8 for JavaScript, rely on dynamic profiling as their key mechanism to guide optimizations. While these JIT compilers offer good average performance, their behavior is a black box and the achieved performance is highly unpredictable. In this paper, we propose to turn JIT compilation into a precision tool by adding two essential and generic metaprogramming facilities: First, allow programs to invoke JIT compilation explicitly. This enables controlled specialization of arbitrary code at run-time, in the style of partial evaluation. It also enables the JIT compiler to report warnings and errors to the program when it is unable to compile a code path in the demanded way. Second, allow the JIT compiler to call back into the program to perform compile-time computation. This lets the program itself define the translation strategy for certain constructs on the fly and gives rise to a powerful JIT macro facility that enables "smart" libraries to supply domain-specific compiler optimizations or safety checks. We present Lancet, a JIT compiler framework for Java bytecode that enables such a tight, two-way integration with the running program. Lancet itself was derived from a high-level Java bytecode interpreter: staging the interpreter using LMS (Lightweight Modular Staging) produced a simple bytecode compiler. Adding abstract interpretation turned the simple compiler into an optimizing compiler. This fact provides compelling evidence for the scalability of the staged-interpreter approach to compiler construction. In the case of Lancet, JIT macros also provide a natural interface to existing LMS-based toolchains such as the Delite parallelism and DSL framework, which can now serve as accelerator macros for arbitrary JVM bytecode.

[1]  Paul H. J. Kelly,et al.  Runtime Code Generation in C++ as a Foundation for Domain-Specific Optimisation , 2003, Domain-Specific Program Generation.

[2]  Akihiko Takano Y.Futamura : Partial Evaluation of Computation Process : An Approach to a Compiler-Compiler , 2002 .

[3]  Olivier Danvy,et al.  Representing Control: a Study of the CPS Transformation , 1992, Mathematical Structures in Computer Science.

[4]  Markus Mock,et al.  DyC: an expressive annotation-directed dynamic compiler for C , 2000, Theor. Comput. Sci..

[5]  Samuele Pedroni,et al.  PyPy's approach to virtual machine construction , 2006, OOPSLA '06.

[6]  WimmerChristian,et al.  Design of the Java HotSpot client compiler for Java 6 , 2008 .

[7]  Michael Haupt,et al.  Maxine: An approachable virtual machine for, and in, java , 2013, TACO.

[8]  Matthew Arnold,et al.  Adaptive optimization in the Jalapeño JVM , 2000, OOPSLA '00.

[9]  Peter Thiemann Partially static operations , 2013, PEPM '13.

[10]  Andrei V. Klimov,et al.  A Java Supercompiler and Its Application to Verification of Cache-Coherence Protocols , 2009, Ershov Memorial Conference.

[11]  Gilad Bracha,et al.  Strongtalk: typechecking Smalltalk in a production environment , 1993, OOPSLA '93.

[12]  Carl Friedrich Bolz,et al.  Tracing the meta-level: PyPy's tracing JIT compiler , 2009, ICOOOLPS@ECOOP.

[13]  Kunle Olukotun,et al.  Optimizing data structures in high-level programs: new directions for extensible compilers based on staging , 2013, POPL.

[14]  Thomas Würthinger,et al.  Extending the graal compiler to optimize libraries , 2011, OOPSLA Companion.

[15]  Craig Chambers,et al.  Debugging optimized code with dynamic deoptimization , 1992, PLDI '92.

[16]  Walid Taha,et al.  MetaML and multi-stage programming with explicit annotations , 2000, Theor. Comput. Sci..

[17]  Vivek Sarkar,et al.  The Jikes Research Virtual Machine project: Building an open-source research community , 2005, IBM Syst. J..

[18]  Kunle Olukotun,et al.  Composition and Reuse with Compiled Domain-Specific Languages , 2013, ECOOP.

[19]  Siau-Cheng Khoo,et al.  Parameterized partial evaluation , 1993, TOPL.

[20]  Cliff Click,et al.  The Java HotSpot Server Compiler , 2001, Java Virtual Machine Research and Technology Symposium.

[21]  Peter Thiemann,et al.  Realistic compilation by partial evaluation , 1996, PLDI '96.

[22]  Kunle Olukotun,et al.  OptiML: An Implicitly Parallel Domain-Specific Language for Machine Learning , 2011, ICML.

[23]  Urs Hölzle,et al.  Optimizing dynamically-dispatched calls with run-time type feedback , 1994, PLDI '94.

[24]  Martin Odersky,et al.  JavaScript as an Embedded DSL , 2012, ECOOP.

[25]  Walid Taha,et al.  Implementing Multi-stage Languages Using ASTs, Gensym, and Reflection , 2003, GPCE.

[26]  Olivier Danvy,et al.  From Interpreter to Compiler and Virtual Machine: A Functional Derivation , 2003 .

[27]  William R. Cook,et al.  Hybrid partial evaluation , 2011, OOPSLA '11.

[28]  Craig Chambers,et al.  Optimizing Dynamically-Typed Object-Oriented Languages With Polymorphic Inline Caches , 1991, ECOOP.

[29]  Valentin F. Turchin,et al.  The concept of a supercompiler , 1986, TOPL.

[30]  Matthias Felleisen,et al.  The calculi of lambda-nu-cs conversion: a syntactic theory of control and state in imperative higher-order programming languages , 1987 .

[31]  Walid Taha,et al.  A methodology for generating verified combinatorial circuits , 2004, EMSOFT '04.

[32]  Lieven Eeckhout,et al.  Statistically rigorous java performance evaluation , 2007, OOPSLA.

[33]  Kunle Olukotun,et al.  Building-Blocks for Performance Oriented DSLs , 2011, DSL.

[34]  Hanspeter Mössenböck,et al.  Design of the Java HotSpot#8482; client compiler for Java 6 , 2008, TACO.

[35]  Urs Hölzle,et al.  Reconciling responsiveness with performance in pure object-oriented languages , 1996, TOPL.

[36]  Kunle Olukotun,et al.  Implementing Domain-Specific Languages for Heterogeneous Parallel Computing , 2011, IEEE Micro.

[37]  William R. Cook,et al.  Remote Batch Invocation for SQL Databases , 2011, DBPL.

[38]  Urs Hölzle,et al.  Dynamic versus Static Optimization Techniques for Object-Oriented Languages , 1995, Theory Pract. Object Syst..

[39]  StatePeter Thiemann Partial Evaluation for Higher-Order Languages with , 1996 .

[40]  Sorin Lerner,et al.  Composing dataflow analyses and transformations , 2002, POPL '02.

[41]  Alvin Cheung,et al.  StatusQuo: Making Familiar Abstractions Perform Using Program Analysis , 2013, CIDR.

[42]  Martin Odersky,et al.  Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs , 2010, GPCE '10.

[43]  Brian Beckman,et al.  LINQ: reconciling object, relations and XML in the .NET framework , 2006, SIGMOD Conference.

[44]  Yoshihiko Futamura,et al.  Partial Evaluation of Computation Process--An Approach to a Compiler-Compiler , 1999, High. Order Symb. Comput..

[45]  Kunle Olukotun,et al.  A Heterogeneous Parallel Framework for Domain-Specific Languages , 2011, 2011 International Conference on Parallel Architectures and Compilation Techniques.

[46]  Christian Wimmer,et al.  Self-optimizing AST interpreters , 2012, DLS.

[47]  Torsten Grust,et al.  Avalanche-safe LINQ compilation , 2010, Proc. VLDB Endow..

[48]  OlukotunKunle,et al.  Optimizing data structures in high-level programs , 2013 .

[49]  Christian Wimmer,et al.  One VM to rule them all , 2013, Onward!.

[50]  Ulrik Pagh Schultz,et al.  Automatic program specialization for Java , 2000, TOPL.

[51]  Craig Chambers,et al.  An efficient implementation of SELF, a dynamically-typed object-oriented language based on prototypes , 1989, OOPSLA '89.

[52]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.