Just-In-Time Compilation

Similar documents
Just In Time Compilation

Running class Timing on Java HotSpot VM, 1

CSc 453 Interpreters & Interpretation

Compiler construction 2009

Implementing Higher-Level Languages. Quick tour of programming language implementation techniques. From the Java level to the C level.

Just-In-Time Compilers & Runtime Optimizers

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler

Lecture 9 Dynamic Compilation

Compiler Design Spring 2018

Introduction. CS 2210 Compiler Design Wonsun Ahn

JAVA PERFORMANCE. PR SW2 S18 Dr. Prähofer DI Leopoldseder

Trace Compilation. Christian Wimmer September 2009

Truffle A language implementation framework

Introduction to Machine-Independent Optimizations - 1

EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised:

Compilers and Interpreters

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

LECTURE 2. Compilers and Interpreters

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

What do Compilers Produce?

Dynamic Binary Translation for Generation of Cycle AccurateOctober Architecture 28, 2008 Simulators 1 / 1

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16

<Insert Picture Here> Symmetric multilanguage VM architecture: Running Java and JavaScript in Shared Environment on a Mobile Phone

ART JIT in Android N. Xueliang ZHONG Linaro ART Team

Deriving Code Coverage Information from Profiling Data Recorded for a Trace-based Just-in-time Compiler

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

BEAMJIT: An LLVM based just-in-time compiler for Erlang. Frej Drejhammar

LESSON 13: LANGUAGE TRANSLATION

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

Exploiting Hardware Resources: Register Assignment across Method Boundaries

Delft-Java Link Translation Buffer

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

BEAMJIT, a Maze of Twisty Little Traces

History of Compilers The term

Ahead of Time (AOT) Compilation

Copyright 2014 Oracle and/or its affiliates. All rights reserved.

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation

Jupiter: A Modular and Extensible JVM

LLVM: A Compilation Framework. Transformation

What is software testing? Software testing is designing, executing and evaluating test cases in order to detect faults.

Sista: Improving Cog s JIT performance. Clément Béra

02 B The Java Virtual Machine

Java TM. Multi-Dispatch in the. Virtual Machine: Design and Implementation. Computing Science University of Saskatchewan

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2

Method-Level Phase Behavior in Java Workloads

Correctness of Speculative Optimizations with Dynamic Deoptimization

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

On the Algorithm for Specializing Java Programs with Generic Types

Soot A Java Bytecode Optimization Framework. Sable Research Group School of Computer Science McGill University

H.-S. Oh, B.-J. Kim, H.-K. Choi, S.-M. Moon. School of Electrical Engineering and Computer Science Seoul National University, Korea

Java On Steroids: Sun s High-Performance Java Implementation. History

LLVM for a Managed Language What we've learned

Managed runtimes & garbage collection

Jazelle ARM. By: Adrian Cretzu & Sabine Loebner

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Future of JRockit & Tools

Improving Java Code Performance. Make your Java/Dalvik VM happier

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

JOVE. An Optimizing Compiler for Java. Allen Wirfs-Brock Instantiations Inc.

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Compiler-guaranteed Safety in Code-copying Virtual Machines

Towards future method hotness prediction for Virtual Machines

Compiler Optimization

JAVA MOCK TEST JAVA MOCK TEST III

Program Dynamic Analysis. Overview

3/15/18. Overview. Program Dynamic Analysis. What is dynamic analysis? [3] Why dynamic analysis? Why dynamic analysis? [3]

Learning from Executions

Exceptions. One-Slide Summary. Language System Structure

Operating System: Chap2 OS Structure. National Tsing-Hua University 2016, Fall Semester

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Compilers and Code Optimization EDOARDO FUSELLA

Usually, target code is semantically equivalent to source code, but not always!

Structure of a Compiler. We looked at each stage in turn. Exceptions. Language Design and Implementation Issues

Interaction of JVM with x86, Sparc and MIPS

Object-oriented Compiler Construction

Trace-based JIT Compilation

On the Design of the Local Variable Cache in a Hardware Translation-Based Java Virtual Machine

Evolution of a Java just-in-time compiler for IA-32 platforms

Expressing high level optimizations within LLVM. Artur Pilipenko

SSA Based Mobile Code: Construction and Empirical Evaluation

Java: framework overview and in-the-small features

Introduction to Mobile Development

Mixed Mode Execution with Context Threading

Android Debugging ART

The role of semantic analysis in a compiler

Java Performance: The Definitive Guide

JamaicaVM Java for Embedded Realtime Systems

When do We Run a Compiler?

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Scala Benchmark: Invariant Verifier

CS 406/534 Compiler Construction Putting It All Together

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

HydraVM: Mohamed M. Saad Mohamed Mohamedin, and Binoy Ravindran. Hot Topics in Parallelism (HotPar '12), Berkeley, CA

AOT Vs. JIT: Impact of Profile Data on Code Quality

A JVM Does What? Eva Andreasson Product Manager, Azul Systems

Untyped Memory in the Java Virtual Machine

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano

Compiling Techniques

Transcription:

Just-In-Time Compilation Thiemo Bucciarelli Institute for Software Engineering and Programming Languages 18. Januar 2016 T. Bucciarelli 18. Januar 2016 1/25

Agenda Definitions Just-In-Time Compilation Comparing JIT, AOT and Interpreters Profiling Optimization The Java Virtual Machine Conclusion T. Bucciarelli 18. Januar 2016 2/25

Definitions: Compiler Definition: Compiler Translation of source code from one programming language to another. Lexical Analysis Split the input into atomic units. Syntax Analysis Check if the syntax is correct (parser). Semantic Analysis E.g. type checking. Typically results in an intermediate representation. Optimization Increase the effectivity of the code without changing the semantics. T. Bucciarelli 18. Januar 2016 3/25

Definitions: AOT Compiler Definition: Ahead-of-Time (AOT) Compiler Compilation before runtime Typically called by the programmer Often produces native code for direct execution Mostly platform dependent! T. Bucciarelli 18. Januar 2016 4/25

Definitions: Interpreters Definition: Interpreter Does not create any output Processes at runtime Directly executes the code on the processor (=interpreting) Mostly platform independent! T. Bucciarelli 18. Januar 2016 5/25

Just-In-Time Compilation Goals: Tries to fill the gap between Interpreter and AOT compilers Efficiency and platform independency Structure: Performs compilation during runtime Trace-based or method-based Has to be as fast as possible Can use additional information for better optimizations Knows the underlying hardware T. Bucciarelli 18. Januar 2016 6/25

Just-In-Time Compilation Method-based: Only analyses the calls, no further analysis Similar to static AOT compilers Less efficient, but less overhead Trace-based: Analyses what paths (traces) are often used, and to which methods they belong Can effectively be combined with an interpreter Allows targeted optimizations More efficient, more overhead T. Bucciarelli 18. Januar 2016 7/25

Comparing JIT, AOT and Interpreters AOT-Compilers: + Can be arbitrary slow and thus perform time-consuming optimizations + No overhead at runtime Little platform independence Interpreters: + Platform independence ± Little overhead at runtime Inefficient for repetitive executions Little optimization possibilities JIT-Compilers: + Platform independence + Highly optimized and efficient code + Runtime optimizations High overhead at runtime T. Bucciarelli 18. Januar 2016 8/25

Profiling Necessary for the optimization Analysis of the execution and collection of information A good profiling is crucial for efficient optimizations static or dynamic Has to produce as less overhead as possible (especially for JIT) Next slides: How could a profiler be implemented? What information could be collected? T. Bucciarelli 18. Januar 2016 9/25

Profiling: How? Sampling-based: Statistical approach: Take samples of the execution state Less precise, but very efficient Does not affect memory management much Drawback: A method could be completely undetected Event-based: Profiler is triggered by certain events Very specified T. Bucciarelli 18. Januar 2016 10/25

Profiling: How? Instrumentation: Injection of profiling code Very flexible, better performance than profiling by another thread T. Bucciarelli 18. Januar 2016 11/25

Profiling: What? Call graph: Graph showing the call-dependencies of the methods Edges contain the amount of times this call was performed Execution Trace: A trace representing the execution, including timestamps. Most precise profile T. Bucciarelli 18. Januar 2016 12/25

Optimization Optimization: Static or dynamic/adaptive JIT compilers can use both types (but not every technique, because of their overhead) Examples for static optimization: Dead code elimination Constant folding and propagation Loop-invariant code motion Dynamic optimization on the basis of the Java Virtual Machine T. Bucciarelli 18. Januar 2016 13/25

JVM: Introduction Here: HotSpot and JRockit AOT compilation of Java source-code to Java bytecode JRockit uses JIT and HotSpot uses JIT& Interpreter Bytecode is assembly-like, and easy to process during runtime T. Bucciarelli 18. Januar 2016 14/25

JVM: Java Bytecode What Java bytecode looks like 1 Compiled from " t e s t. java " 2 p u b l i c class t e s t { 3 p u b l i c t e s t ( ) ; 4 Code : 5 0: aload_0 6 1: invokespecial #1 / / Method java / lang / Object." < i n i t > " : ( ) V 7 4: r e t u r n 8 9 p u b l i c s t a t i c void main ( java. lang. S t r i n g [ ] ) ; 10 Code : 11 0: iconst_ 5 12 1: i s t o r e _ 1 13 2: r e t u r n 14 } T. Bucciarelli 18. Januar 2016 15/25

JRockit structure T. Bucciarelli 18. Januar 2016 16/25

JVM: HotSpot Optimizations Hotspot Detection: Selective optimization: Only optimize parts of the code Assumption: the execution mostly resides in a small part of the code (80/20 rule) For 80% of the code, interpreting is probably more efficient than compiling Detect hot spots and focus on these for compilation and optimization T. Bucciarelli 18. Januar 2016 17/25

JVM: HotSpot Optimizations Method Inlining: Method invokations are time consuming Copy the code of frequently invokated methods inside their caller-methods Reduces overhead, allows more optimization Problems: Recursive calls (infinite inlining, the optimizer has to set a maximum for the inlining of recursive calls) Overriding (see next slide) T. Bucciarelli 18. Januar 2016 18/25

JVM: HotSpot Optimizations Dynamic deoptimization: Not every method can be inlined If a method is not final, it could possibly be overridden at runtime HotSpot speculatively inline methods which are not final (but not overridden at this moment) In certain cases, the inlining has to be undone, this is called dynamic deoptimization T. Bucciarelli 18. Januar 2016 19/25

JVM: Hotspot Optimizations Range check elimination: Java requires strict array bounding checks Reading, changing and overwriting a value would need two checks the JVM can check if it is possible for the index value to change between operations Reduces the range check amount T. Bucciarelli 18. Januar 2016 20/25

JVM: When to use JIT? As stated in HotSpot Detection, interpreting is in some cases better than JIT But: How to decide whether a method should be JIT-compiled or interpreted? HotSpot uses heuristic approaches T. Bucciarelli 18. Januar 2016 21/25

JVM: When to use JIT? The simple heuristics Often executed methods should be compiled Large methods should also be compiled, even when they are rarely executed Decision is based on the amount of executions and size of the methods T. Bucciarelli 18. Januar 2016 22/25

Example Example for a simple decision graph: JIT_MIN_SIZE method size compile don t compile amount of executions JIT_MIN_TIMES T. Bucciarelli 18. Januar 2016 23/25

Conclusion JIT compilation gives compilers the ability to be highly platform independent Optimizations mostly based on assumptions, which could also have negative effects Important decisions: Optimize? JIT or interpret? T. Bucciarelli 18. Januar 2016 24/25

Questions? Thank you for your attention. Questions? T. Bucciarelli 18. Januar 2016 25/25