Escape Analysis in the Context of Dynamic Compilation and Deoptimization∗

Total Page:16

File Type:pdf, Size:1020Kb

Escape Analysis in the Context of Dynamic Compilation and Deoptimization∗ Escape Analysis in the Context of Dynamic Compilation and Deoptimization∗ Thomas Kotzmann Hanspeter M¨ossenb¨ock Institute for System Software Institute for System Software Johannes Kepler University Linz Johannes Kepler University Linz Linz, Austria Linz, Austria [email protected] [email protected] ABSTRACT Keywords In object-oriented programming languages, an object is said Java, just-in-time compilation, optimization, escape analy- to escape the method or thread in which it was created if it sis, scalar replacement, stack allocation, synchronization re- can also be accessed by other methods or threads. Knowing moval, deoptimization which objects do not escape allows a compiler to perform aggressive optimizations. 1. INTRODUCTION This paper presents a new intraprocedural and interproce- dural algorithm for escape analysis in the context of dynamic In Java, each object is allocated on the heap and deallo- compilation where the compiler has to cope with dynamic cated by the garbage collector, which is invoked once in a class loading and deoptimization. It was implemented for while to examine the heap and release the memory of objects Sun Microsystems’ Java HotSpotTM client compiler and op- as soon as they are not referenced any longer. Allocation, erates on an intermediate representation in SSA form. We access and synchronization of objects involve considerable introduce equi-escape sets for the efficient propagation of costs: escape information between related objects. The analysis • is used for scalar replacement of fields and synchronization An object allocation does not only involve memory removal,aswellasforstack allocation of objects and fixed- reservation. The fields of the object must also be ini- sized arrays. The results of the interprocedural analysis sup- tialized, because the garbage collector presumes that port the compiler in inlining decisions and allow actual pa- unassigned references are null. Additionally, the Java rameters to be allocated on the caller stack. language specification defines default values for fields. Under certain circumstances, the Java HotSpotTM VM Therefore, the memory occupied by the newly created is forced to stop executing a method’s machine code and object is typically cleared out in a loop even if values transfer control to the interpreter. This is called deoptimiza- are explicitly assigned to the fields by the constructor tion. Since the interpreter does not know about the scalar afterwards. replacement and synchronization removal performed by the • Reading or writing a field of an object requires one compiler, the deoptimization framework was extended to re- or two memory accesses depending on whether the ad- allocate and relock objects on demand. dress of the object is already in a register or not. In the context of a generational garbage collector, the modifi- Categories and Subject Descriptors cation of a field that holds a pointer is more expensive. D.3.4 [Programming Languages]: Processors—Incremen- It is associated with a write barrier,becausepointers tal compilers, Optimization; D.4.1 [Operating Systems]: from older to younger generations must be recorded in Process Management—Synchronization; D.4.2 [Operating a remembered set so that younger generations can be Systems]: Storage Management—Allocation / deallocation collected without inspecting every object in the older strategies ones [12]. • General Terms Java programs typically coordinate multiple threads by synchronizing on a shared object. Much research Algorithms, Languages, Performance has been done to reduce the cost of synchronization ∗ in JVM implementations, but complete elimination of This work was supported by Sun Microsystems, Inc. useless synchronization is still a desirable goal. Scalar replacement. The costs described above can be re- Permission to make digital or hard copies of all or part of this work for duced by various compiler optimizations. An object that is personal or classroom use is granted without fee provided that copies are neither assigned to a non-local variable nor passed as a pa- not made or distributed for profit or commercial advantage and that copies rameter does not escape the method in which it is allocated. bear this notice and the full citation on the first page. To copy otherwise, to The compiler can eliminate the allocation and replace the republish, to post on servers or to redistribute to lists, requires prior specific object’s fields by scalars (see Figure 1). This optimization permission and/or a fee. VEE’05, June 11–12, 2005, Chicago, Illinois, USA. eliminates memory allocation, initialization, field access and Copyright 2005 ACM 1-59593-047-7/05/0006...$5.00. write barriers. 111 floatfoo( float d) { floatfoo( float d) { floatfoo( float d) { Circle c =new Circle(d / 2); Circle c =new Circle(); float r=d/2; return c.area(); c.r=d/2; return r*r*PI; } return c.r * c.r * PI; } } original method after inlining after scalar replacement Figure 1: Example for scalar replacement of fields Stack allocation. An object that is accessed only by the 2.1 Escape States and Fields Array creating method and its callees does not escape the current Before the compiler can optimize the allocation and syn- thread. Although it must not be eliminated because the chronization of objects, it has to know whether an object callees require a reference to the object, it can be allocated allocated in a method can be accessed from outside the on the stack. Its memory is released implicitly when the method. This knowledge is derived from the HIR via es- stack frame is removed at the end of the method. This cape analysis. If an object can be accessed by other meth- means that garbage collection runs faster and less frequently ods or threads, it is said to escape the current method or because the young generation of the heap does not fill up the current thread, respectively. In the context of our work, that fast. Moreover, synchronization on thread-local objects possible escape levels are: can be removed. In this paper we present a new algorithm for escape analy- • NoEscape: The object is accessible only from within sis and related optimizations. The analysis was implemented the method of creation. In most cases, the compiler for the client compiler of the Java HotSpotTM Virtual Ma- can eliminate the object and replace its fields by scalar chine [22] in the context of a research collaboration between variables (see Section 2.2). Objects with this escape Sun Microsystems and the Institute for System Software at level are called method-local. the Johannes Kepler University Linz. The paper contributes • MethodEscape: The object escapes the current method the following: but not the current thread, e.g. because it is passed to a callee which does not let the argument escape. • It presents an intraprocedural and interprocedural es- It is possible to allocate the object on the stack and cape analysis for a dynamic compiler. The results are eliminate any synchronization on it. Objects with this used for scalar replacement, stack allocation and syn- escape level are called thread-local. chronization removal. • GlobalEscape: The object escapes globally, typically • It introduces equi-escape sets for the representation of because it is assigned to a static variable or to a field dependencies between objects and the efficient propa- of a heap object. The object must be allocated on the gation of escape states. heap, because it can be referenced by other threads • It describes how the HotSpotTM deoptimization frame- and methods. work was extended to deal with eliminated object al- In contrast to the bytecodes of a method, the SSA-based locations and removedsynchronization. HIR does not contain any instructions for loading or stor- ing local variables. They are eliminated during the abstract Sun’s client compiler is a simple and fast compiler dedi- interpretation of the bytecodes. For this purpose, the com- cated to client programs, applets and graphical user inter- piler maintains a state object which contains a locals array faces [9]. Its objective is to achieve high compilation speed to keep track of the values most recently assigned to a local at a potential cost of peak performance. The front end op- variable [16]. If an instruction creates a value for the local erates on a SSA-based [5] high-level intermediate represen- variable with the number n, a pointer to this instruction is tation (HIR) and performs only few high-impact optimiza- stored in the locals array at position n. If an instruction tions, such as constant folding, method inlining and com- uses a local variable as an operand, it is provided with the mon subexpression elimination. The back end converts the corresponding value from the locals array, i.e. a pointer to HIR into a low-level intermediate representation, which is the instruction where the value was created. the basis for linear scan register allocation [24] and code Bytecodes refer to local variables via indices, and the max- generation. imum number of variables for a certain method is specified in the class file. As far as fields are concerned, we do not know 2. INTRAPROCEDURAL ANALYSIS in advance which or how many fields are accessed within a The HIR is built by parsing the bytecodes and performing method. Therefore, the state object is extended by a grow- an abstract interpretation [9]. At first, the boundaries of all able fields array which stores the current values of all fields. basic blocks are determined by examining the destinations of Figure 2 shows the contents of the locals array and the fields jumps and the successors of conditional jump instructions. array for a simple sequence of bytecodes. Then the basic blocks are filled with HIR instructions. Each At the end of the HIR construction, when we know which HIR instruction that loads or computes a value represents objects escape and which do not, we substitute the fields of both the operation and the result so that operands appear non-escaping objects by the values stored in the fields array.
Recommended publications
  • SJC – Small Java Compiler
    SJC – Small Java Compiler User Manual Stefan Frenz Translation: Jonathan Brase original version: 2011/06/08 latest document update: 2011/08/24 Compiler Version: 182 Java is a registered trademark of Oracle/Sun Table of Contents 1 Quick introduction.............................................................................................................................4 1.1 Windows...........................................................................................................................................4 1.2 Linux.................................................................................................................................................5 1.3 JVM Environment.............................................................................................................................5 1.4 QEmu................................................................................................................................................5 2 Hello World.......................................................................................................................................6 2.1 Source Code......................................................................................................................................6 2.2 Compilation and Emulation...............................................................................................................8 2.3 Details...............................................................................................................................................9
    [Show full text]
  • Java (Programming Langua a (Programming Language)
    Java (programming language) From Wikipedia, the free encyclopedialopedia "Java language" redirects here. For the natural language from the Indonesian island of Java, see Javanese language. Not to be confused with JavaScript. Java multi-paradigm: object-oriented, structured, imperative, Paradigm(s) functional, generic, reflective, concurrent James Gosling and Designed by Sun Microsystems Developer Oracle Corporation Appeared in 1995[1] Java Standard Edition 8 Update Stable release 5 (1.8.0_5) / April 15, 2014; 2 months ago Static, strong, safe, nominative, Typing discipline manifest Major OpenJDK, many others implementations Dialects Generic Java, Pizza Ada 83, C++, C#,[2] Eiffel,[3] Generic Java, Mesa,[4] Modula- Influenced by 3,[5] Oberon,[6] Objective-C,[7] UCSD Pascal,[8][9] Smalltalk Ada 2005, BeanShell, C#, Clojure, D, ECMAScript, Influenced Groovy, J#, JavaScript, Kotlin, PHP, Python, Scala, Seed7, Vala Implementation C and C++ language OS Cross-platform (multi-platform) GNU General Public License, License Java CommuniCommunity Process Filename .java , .class, .jar extension(s) Website For Java Developers Java Programming at Wikibooks Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few impimplementation dependencies as possible.ble. It is intended to let application developers "write once, run ananywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to rurun on another. Java applications ns are typically compiled to bytecode (class file) that can run on anany Java virtual machine (JVM)) regardless of computer architecture. Java is, as of 2014, one of tthe most popular programming ng languages in use, particularly for client-server web applications, witwith a reported 9 million developers.[10][11] Java was originallyy developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems'Micros Java platform.
    [Show full text]
  • The Java® Language Specification Java SE 8 Edition
    The Java® Language Specification Java SE 8 Edition James Gosling Bill Joy Guy Steele Gilad Bracha Alex Buckley 2015-02-13 Specification: JSR-337 Java® SE 8 Release Contents ("Specification") Version: 8 Status: Maintenance Release Release: March 2015 Copyright © 1997, 2015, Oracle America, Inc. and/or its affiliates. 500 Oracle Parkway, Redwood City, California 94065, U.S.A. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. The Specification provided herein is provided to you only under the Limited License Grant included herein as Appendix A. Please see Appendix A, Limited License Grant. To Maurizio, with deepest thanks. Table of Contents Preface to the Java SE 8 Edition xix 1 Introduction 1 1.1 Organization of the Specification 2 1.2 Example Programs 6 1.3 Notation 6 1.4 Relationship to Predefined Classes and Interfaces 7 1.5 Feedback 7 1.6 References 7 2 Grammars 9 2.1 Context-Free Grammars 9 2.2 The Lexical Grammar 9 2.3 The Syntactic Grammar 10 2.4 Grammar Notation 10 3 Lexical Structure 15 3.1 Unicode 15 3.2 Lexical Translations 16 3.3 Unicode Escapes 17 3.4 Line Terminators 19 3.5 Input Elements and Tokens 19 3.6 White Space 20 3.7 Comments 21 3.8 Identifiers 22 3.9 Keywords 24 3.10 Literals 24 3.10.1 Integer Literals 25 3.10.2 Floating-Point Literals 31 3.10.3 Boolean Literals 34 3.10.4 Character Literals 34 3.10.5 String Literals 35 3.10.6 Escape Sequences for Character and String Literals 37 3.10.7 The Null Literal 38 3.11 Separators
    [Show full text]
  • Incrementalized Pointer and Escape Analysis Frédéric Vivien, Martin Rinard
    Incrementalized Pointer and Escape Analysis Frédéric Vivien, Martin Rinard To cite this version: Frédéric Vivien, Martin Rinard. Incrementalized Pointer and Escape Analysis. PLDI ’01 Proceedings of the ACM SIGPLAN 2001 conference on Programming language design and implementation, Jun 2001, Snowbird, United States. pp.35–46, 10.1145/381694.378804. hal-00808284 HAL Id: hal-00808284 https://hal.inria.fr/hal-00808284 Submitted on 14 Oct 2018 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Incrementalized Pointer and Escape Analysis∗ Fred´ eric´ Vivien Martin Rinard ICPS/LSIIT Laboratory for Computer Science Universite´ Louis Pasteur Massachusetts Institute of Technology Strasbourg, France Cambridge, MA 02139 [email protected]­strasbg.fr [email protected] ABSTRACT to those parts of the program that offer the most attrac- We present a new pointer and escape analysis. Instead of tive return (in terms of optimization opportunities) on the analyzing the whole program, the algorithm incrementally invested resources. Our experimental results indicate that analyzes only those parts of the program that may deliver this approach usually delivers almost all of the benefit of the useful results. An analysis policy monitors the analysis re- whole-program analysis, but at a fraction of the cost.
    [Show full text]
  • Building Useful Program Analysis Tools Using an Extensible Java Compiler
    Building Useful Program Analysis Tools Using an Extensible Java Compiler Edward Aftandilian, Raluca Sauciuc Siddharth Priya, Sundaresan Krishnan Google, Inc. Google, Inc. Mountain View, CA, USA Hyderabad, India feaftan, [email protected] fsiddharth, [email protected] Abstract—Large software companies need customized tools a specific task, but they fail for several reasons. First, ad- to manage their source code. These tools are often built in hoc program analysis tools are often brittle and break on an ad-hoc fashion, using brittle technologies such as regular uncommon-but-valid code patterns. Second, simple ad-hoc expressions and home-grown parsers. Changes in the language cause the tools to break. More importantly, these ad-hoc tools tools don’t provide sufficient information to perform many often do not support uncommon-but-valid code code patterns. non-trivial analyses, including refactorings. Type and symbol We report our experiences building source-code analysis information is especially useful, but amounts to writing a tools at Google on top of a third-party, open-source, extensible type-checker. Finally, more sophisticated program analysis compiler. We describe three tools in use on our Java codebase. tools are expensive to create and maintain, especially as the The first, Strict Java Dependencies, enforces our dependency target language evolves. policy in order to reduce JAR file sizes and testing load. The second, error-prone, adds new error checks to the compilation In this paper, we present our experience building special- process and automates repair of those errors at a whole- purpose tools on top of the the piece of software in our codebase scale.
    [Show full text]
  • SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs
    SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs Introduction to Java programming JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code. Bytecode javac compiler of JDK compiles the java source code into bytecode so that it can be executed by JVM. The bytecode is saved in a .class file by compiler. Java Virtual Machine (JVM) This is generally referred as JVM. Before, we discuss about JVM lets see the phases of program execution. Phases are as follows: we write the program, then we compile the program and at last we run the program. 1) Writing of the program is of course done by java programmer. 2) Compilation of program is done by javac compiler, javac is the primary java compiler included in java development kit (JDK). It takes java program as input and generates java bytecode as output. 3) In third phase, JVM executes the bytecode generated by compiler. This is called program run phase. So, now that we understood that the primary function of JVM is to execute the bytecode produced by compiler. Characteristics of Java Simple Java is very easy to learn, and its syntax is simple, clean and easy to understand. Multi-threaded Multithreading capabilities come built right into the Java language. This means it is possible to build highly interactive and responsive apps with a number of concurrent threads of activity.
    [Show full text]
  • Coqjvm: an Executable Specification of the Java Virtual Machine Using
    CoqJVM: An Executable Specification of the Java Virtual Machine using Dependent Types Robert Atkey LFCS, School of Informatics, University of Edinburgh Mayfield Rd, Edinburgh EH9 3JZ, UK [email protected] Abstract. We describe an executable specification of the Java Virtual Machine (JVM) within the Coq proof assistant. The principal features of the development are that it is executable, meaning that it can be tested against a real JVM to gain confidence in the correctness of the specification; and that it has been written with heavy use of dependent types, this is both to structure the model in a useful way, and to constrain the model to prevent spurious partiality. We describe the structure of the formalisation and the way in which we have used dependent types. 1 Introduction Large scale formalisations of programming languages and systems in mechanised theorem provers have recently become popular [4–6, 9]. In this paper, we describe a formalisation of the Java virtual machine (JVM) [8] in the Coq proof assistant [11]. The principal features of this formalisation are that it is executable, meaning that a purely functional JVM can be extracted from the Coq development and – with some O’Caml glue code – executed on real Java bytecode output from the Java compiler; and that it is structured using dependent types. The motivation for this development is to act as a basis for certified consumer- side Proof-Carrying Code (PCC) [12]. We aim to prove the soundness of program logics and correctness of proof checkers against the model, and extract the proof checkers to produce certified stand-alone tools.
    [Show full text]
  • Generalized Escape Analysis and Lightweight Continuations
    Generalized Escape Analysis and Lightweight Continuations Abstract Might and Shivers have published two distinct analyses for rea- ∆CFA and ΓCFA are two analysis techniques for higher-order soning about programs written in higher-order languages that pro- functional languages (Might and Shivers 2006b,a). The former uses vide first-class continuations, ∆CFA and ΓCFA (Might and Shivers an enrichment of Harrison’s procedure strings (Harrison 1989) to 2006a,b). ∆CFA is an abstract interpretation based on a variation reason about control-, environment- and data-flow in a program of procedure strings as developed by Sharir and Pnueli (Sharir and represented in CPS form; the latter tracks the degree of approxi- Pnueli 1981), and, most proximately, Harrison (Harrison 1989). mation inflicted by a flow analysis on environment structure, per- Might and Shivers have applied ∆CFA to problems that require mitting the analysis to exploit extra precision implicit in the flow reasoning about the environment structure relating two code points lattice, which improves not only the precision of the analysis, but in a program. ΓCFA is a general tool for “sharpening” the precision often its run-time as well. of an abstract interpretation by tracking the amount of abstraction In this paper, we integrate these two mechanisms, showing how the analysis has introduced for the specific abstract interpretation ΓCFA’s abstract counting and collection yields extra precision in being performed. This permits the analysis to opportunistically ex- ∆CFA’s frame-string model, exploiting the group-theoretic struc- ploit cases where the abstraction has introduced no true approxi- ture of frame strings. mation.
    [Show full text]
  • Escape from Escape Analysis of Golang
    Escape from Escape Analysis of Golang Cong Wang Mingrui Zhang Yu Jiang∗ KLISS, BNRist, School of Software, KLISS, BNRist, School of Software, KLISS, BNRist, School of Software, Tsinghua University Tsinghua University Tsinghua University Beijing, China Beijing, China Beijing, China Huafeng Zhang Zhenchang Xing Ming Gu Compiler and Programming College of Engineering and Computer KLISS, BNRist, School of Software, Language Lab, Huawei Technologies Science, ANU Tsinghua University Hangzhou, China Canberra, Australia Beijing, China ABSTRACT KEYWORDS Escape analysis is widely used to determine the scope of variables, escape analysis, memory optimization, code generation, go pro- and is an effective way to optimize memory usage. However, the gramming language escape analysis algorithm can hardly reach 100% accurate, mistakes ACM Reference Format: of which can lead to a waste of heap memory. It is challenging to Cong Wang, Mingrui Zhang, Yu Jiang, Huafeng Zhang, Zhenchang Xing, ensure the correctness of programs for memory optimization. and Ming Gu. 2020. Escape from Escape Analysis of Golang. In Software In this paper, we propose an escape analysis optimization ap- Engineering in Practice (ICSE-SEIP ’20), May 23–29, 2020, Seoul, Republic of proach for Go programming language (Golang), aiming to save Korea. ACM, New York, NY, USA, 10 pages. https://doi.org/10.1145/3377813. heap memory usage of programs. First, we compile the source code 3381368 to capture information of escaped variables. Then, we change the code so that some of these variables can bypass Golang’s escape 1 INTRODUCTION analysis mechanism, thereby saving heap memory usage and reduc- Memory management is very important for software engineering.
    [Show full text]
  • Chapter 9: Java
    ,ch09.6595 Page 159 Friday, March 25, 2005 2:47 PM Chapter 9 CHAPTER 9 Java Many Java developers like Integrated Development Environments (IDEs) such as Eclipse. Given such well-known alternatives as Java IDEs and Ant, readers could well ask why they should even think of using make on Java projects. This chapter explores the value of make in these situations; in particular, it presents a generalized makefile that can be dropped into just about any Java project with minimal modification and carry out all the standard rebuilding tasks. Using make with Java raises several issues and introduces some opportunities. This is primarily due to three factors: the Java compiler, javac, is extremely fast; the stan- dard Java compiler supports the @filename syntax for reading “command-line param- eters” from a file; and if a Java package is specified, the Java language specifies a path to the .class file. Standard Java compilers are very fast. This is primarily due to the way the import directive works. Similar to a #include in C, this directive is used to allow access to externally defined symbols. However, rather than rereading source code, which then needs to be reparsed and analyzed, Java reads the class files directly. Because the symbols in a class file cannot change during the compilation process, the class files are cached by the compiler. In even medium-sized projects, this means the Java com- piler can avoid rereading, parsing, and analyzing literally millions of lines of code compared with C. A more modest performance improvement is due to the bare mini- mum of optimization performed by most Java compilers.
    [Show full text]
  • Escape Analysis for Java
    Escape Analysis for Java Jong-Deok Choi Manish Gupta Mauricio Serrano Vugranam C. Sreedhar Sam Midkiff IBM T. J. Watson Research Center P. O. Box 218, Yorktown Heights, NY 10598 jdchoi, mgupta, mserrano, vugranam, smidkiff ¡ @us.ibm.com ¢¤£¦¥¨§ © ¦ § § © § This paper presents a simple and efficient data flow algorithm Java continues to gain importance as a language for general- for escape analysis of objects in Java programs to determine purpose computing and for server applications. Performance (i) if an object can be allocated on the stack; (ii) if an object is an important issue in these application environments. In is accessed only by a single thread during its lifetime, so that Java, each object is allocated on the heap and can be deallo- synchronization operations on that object can be removed. We cated only by garbage collection. Each object has a lock asso- introduce a new program abstraction for escape analysis, the ciated with it, which is used to ensure mutual exclusion when connection graph, that is used to establish reachability rela- a synchronized method or statement is invoked on the object. tionships between objects and object references. We show that Both heap allocation and synchronization on locks incur per- the connection graph can be summarized for each method such formance overhead. In this paper, we present escape analy- that the same summary information may be used effectively in sis in the context of Java for determining whether an object (1) different calling contexts. We present an interprocedural al- may escape the method (i.e., is not local to the method) that gorithm that uses the above property to efficiently compute created the object, and (2) may escape the thread that created the connection graph and identify the non-escaping objects for the object (i.e., other threads may access the object).
    [Show full text]
  • Making Collection Operations Optimal with Aggressive JIT Compilation
    Making Collection Operations Optimal with Aggressive JIT Compilation Aleksandar Prokopec David Leopoldseder Oracle Labs Johannes Kepler University, Linz Switzerland Austria [email protected] [email protected] Gilles Duboscq Thomas Würthinger Oracle Labs Oracle Labs Switzerland Switzerland [email protected] [email protected] Abstract 1 Introduction Functional collection combinators are a neat and widely ac- Compilers for most high-level languages, such as Scala, trans- cepted data processing abstraction. However, their generic form the source program into an intermediate representa- nature results in high abstraction overheads – Scala collec- tion. This intermediate program representation is executed tions are known to be notoriously slow for typical tasks. We by the runtime system. Typically, the runtime contains a show that proper optimizations in a JIT compiler can widely just-in-time (JIT) compiler, which compiles the intermediate eliminate overheads imposed by these abstractions. Using representation into machine code. Although JIT compilers the open-source Graal JIT compiler, we achieve speedups of focus on optimizations, there are generally no guarantees up to 20× on collection workloads compared to the standard about the program patterns that result in fast machine code HotSpot C2 compiler. Consequently, a sufficiently aggressive – most optimizations emerge organically, as a response to JIT compiler allows the language compiler, such as Scalac, a particular programming paradigm in the high-level lan- to focus on other concerns. guage. Scala’s functional-style collection combinators are a In this paper, we show how optimizations, such as inlin- paradigm that the JVM runtime was unprepared for. ing, polymorphic inlining, and partial escape analysis, are Historically, Scala collections [Odersky and Moors 2009; combined in Graal to produce collections code that is optimal Prokopec et al.
    [Show full text]