7. Just In Time Compilation Prof. O. Nierstrasz Jan Kurs.

Slides:



Advertisements
Similar presentations
Virtual Machines Matthew Dwyer 324E Nichols Hall
Advertisements

8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
12. Common Errors, a few Puzzles. © O. Nierstrasz P2 — Common Errors, a few Puzzles 12.2 Common Errors, a few Puzzles Sources  Cay Horstmann, Computing.
Overview Motivations Basic static and dynamic optimization methods ADAPT Dynamo.
ESE Einführung in Software Engineering 7. Modeling Behaviour Prof. O. Nierstrasz.
CP — Concurrent Programming 8. Liveness and Asynchrony Prof. O. Nierstrasz Wintersemester 2005 / 2006.
Online Performance Auditing Using Hot Optimizations Without Getting Burned Jeremy Lau (UCSD, IBM) Matthew Arnold (IBM) Michael Hind (IBM) Brad Calder (UCSD)
Object-Oriented Reengineering Patterns and Techniques Prof. O. Nierstrasz Prof. S. Ducasse T.
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
ESE Einführung in Software Engineering N. XXX Prof. O. Nierstrasz Fall Semester 2009.
Aarhus University, 2005Esmertec AG1 Implementing Object-Oriented Virtual Machines Lars Bak & Kasper Lund Esmertec AG
© Oscar Nierstrasz ST — Smalltalk Basics 2.1 Change sets  Make sure your changes are logged to a new change set.
The Software Composition Group Prof. O. Nierstrasz
13. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Summary, Trends, Research...  Summary: functional, logic and object-oriented.
ESE Einführung in Software Engineering X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
CP — Concurrent Programming 12. Petri Nets Prof. O. Nierstrasz Wintersemester 2005 / 2006.
Metamodeling Seminar X. CHAPTER Prof. O. Nierstrasz Spring Semester 2008.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
© Oscar Nierstrasz ST — Smalltalk Basics 2.1 Change sets  Make sure your changes are logged to a new change set.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
ESE Einführung in Software Engineering X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
N. XXX Prof. O. Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap Overview  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed.
12. Common Errors, a few Puzzles. © O. Nierstrasz P2 — Common Errors, a few Puzzles 12.2 Common Errors, a few Puzzles Sources  Cay Horstmann, Computing.
7. Liveness and Asynchrony Prof. O. Nierstrasz. Roadmap  Asynchronous invocations  Simple Relays —Direct invocations —Thread-based messages —Command-based.
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
10. The PyPy translation tool chain Toon Verwaest Thanks to Carl Friedrich Bolz for his kind permission to reuse and adapt his notes.
© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.1 MakeMoney Corp. C*O of MakeMoney Corp. Our Vision  We invest in software  We do not know software 
OORPT Object-Oriented Reengineering Patterns and Techniques X. CHAPTER Prof. O. Nierstrasz.
CP — Concurrent Programming X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
12. eToys. © O. Nierstrasz PS — eToys 12.2 Denotational Semantics Overview:  … References:  …
CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson.
Adaptive Optimization in the Jalapeño JVM M. Arnold, S. Fink, D. Grove, M. Hind, P. Sweeney Presented by Andrew Cove Spring 2006.
380C Lecture 15 Where are we & where we are going –Global Analysis & Optimization Dataflow & SSA Constants, Expressions, Scheduling, Register Allocation.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Dynamic Compilation II John Cavazos University.
Arpit Jain Mtech1. Outline Introduction Dalvik VM Java VM Examples Comparisons Experimental Evaluation.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
Adaptive Optimization in the Jalapeño JVM Matthew Arnold Stephen Fink David Grove Michael Hind Peter F. Sweeney Source: UIUC.
Lecture 10 : Introduction to Java Virtual Machine
CSC 310 – Imperative Programming Languages, Spring, 2009 Virtual Machines and Threaded Intermediate Code (instead of PR Chapter 5 on Target Machine Architecture)
O VERVIEW OF THE IBM J AVA J UST - IN -T IME C OMPILER Presenters: Zhenhua Liu, Sanjeev Singh 1.
1 Introduction to JVM Based on material produced by Bill Venners.
Adaptive Optimization with On-Stack Replacement Stephen J. Fink IBM T.J. Watson Research Center Feng Qian (presenter) Sable Research Group, McGill University.
Java Virtual Machine Case Study on the Design of JikesRVM.
Assembly Code Optimization Techniques for the AMD64 Athlon and Opteron Architectures David Phillips Robert Duckles Cse 520 Spring 2007 Term Project Presentation.
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Dynamic Compilation I John Cavazos University.
CS 598 Scripting Languages Design and Implementation 14. Self Compilers.
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
Just-In-Time Compilation Keith W. Krajewski 3/4/2011 paper: A Brief History of Just-In-Time (2003) John Aycock.
CP — Concurrent Programming 6. Liveness and Guarded Methods Prof. O. Nierstrasz Wintersemester 2005 / 2006.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Method Profiling John Cavazos University.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Smalltalk Implementation Harry Porter, October 2009 Smalltalk Implementation: Optimization Techniques Prof. Harry Porter Portland State University 1.
Optimization Code Optimization ©SoftMoore Consulting.
CSc 453 Interpreters & Interpretation
Inlining and Devirtualization Hal Perkins Autumn 2011
Inlining and Devirtualization Hal Perkins Autumn 2009
Instruction Level Parallelism (ILP)
Trace-based Just-in-Time Type Specialization for Dynamic Languages
How to improve (decrease) CPI
CSc 453 Interpreters & Interpretation
Just In Time Compilation
Presentation transcript:

7. Just In Time Compilation Prof. O. Nierstrasz Jan Kurs

© Oscar Nierstrasz Just-In-Time Compilation 2 Roadmap > What is Just-In-Time Compilation (JIT)? > History of JIT > JIT Overhead > Optimization Techniques in JIT

© Oscar Nierstrasz Just-In-Time Compilation 3 Roadmap > What is Just-In-Time Compilation (JIT)? > History of JIT > JIT Overhead > Optimization Techniques in JIT

© Oscar Nierstrasz Just-In-Time Compilation 4 Compilation vs Interpretation Pros > Programs run faster Cons > Compilation overhead > Programs are typically bigger > Programs are not portable > No run-time information Compilation Pros > Programs are typically smaller > Programs tend to be more portable > Access to run-time information Cons > Programs run slower Interpretation

What is Just-In-Time Compilation? © Oscar Nierstrasz Just-In-Time Compilation 5 Dynamic Translation: Compilation done during execution of a program – at run time – rather than prior to execution CompilationInterpretation JIT

What is Just-In-Time Compilation? © Oscar Nierstrasz Just-In-Time Compilation 6 Is Just-In-Time > dead code elimination during program execution? > generation of native code during program execution? > static analysis and subsequent optimization? > compile-time generation of native code? > Is JIT compile-time optimization based on previous program execution?

Why Just-In-Time Compilation? © Oscar Nierstrasz Just-In-Time Compilation 7 Improve time and space efficiency of programs utilizing: > portable and space-efficient byte-code > run-time information → feedback directed optimizations > speculative optimization

Why Just-In-Time Compilation? © Oscar Nierstrasz Just-In-Time Compilation 8

© Oscar Nierstrasz Just-In-Time Compilation 9 Roadmap > What is Just-In-Time Compilation (JIT)? > History of JIT > JIT Overhead > Optimization Techniques in JIT

History of Just-In-time © Oscar Nierstrasz Just-In-Time Compilation 10 First Just-In-Time > 1960 > McCarthy's LISP paper about dynamic compilation Fortran > 1974 > Optimization of “hot spots” Smalltalk > 1980 – 1984 > Bytecode to native code translation > First modern VM

History of Just-In-time © Oscar Nierstrasz Just-In-Time Compilation 11 Self > 1986 – 1994 > New Advanced VM techniques Java > 1995 – present > First VM with mainstream market penetration Android RunTime (ART) > 2014 > No JIT ;-)

© Oscar Nierstrasz Just-In-Time Compilation 12 Roadmap > What is Just-In-Time Compilation (JIT)? > History of JIT > JIT Overhead > Optimization Techniques in JIT

© Oscar Nierstrasz Just-In-Time Compilation 13 Just-In-Time Overhead Matthew Arnold, Stephen Fink, David Grove, and Michael Hind, ACACES'06, 2006 JIT: 4x speedup, but 20x initial overhead

© Oscar Nierstrasz Just-In-Time Compilation 14 Selective Optimization > Start program in interpreted mode > Find “hot spots” > compile only hot spots

© Oscar Nierstrasz Just-In-Time Compilation 15 Selective Optimization Matthew Arnold, Stephen Fink, David Grove, and Michael Hind, ACACES'06, 2006 > JIT1, JIT2 and JIT3: the better startup, the worse steady state performance. > Selective optimization with JIT3: reaches best startup and best steady state performance

© Oscar Nierstrasz Just-In-Time Compilation 16 NB: Java Virtual Machine > HotSpot > server mode (-server) —aggressive and complex optimizations —slow startup —fast execution > client mode (-client) —less optimizations —fast startup —slower execution

© Oscar Nierstrasz Just-In-Time Compilation 17 What To Optimize > Method Counters > Call Stack Sampling

© Oscar Nierstrasz Just-In-Time Compilation 18 What To Optimize: Method Counters > Approximation of time spent in each method > Popular > Might have significant overhead public void foo() { fooCounter++; if (fooCounter > threshold) { recompile(); } public void foo() { fooCounter++; if (fooCounter > threshold) { recompile(); }

© Oscar Nierstrasz Just-In-Time Compilation 19 What To Optimize: Call Stack Sampling > Call stack inspected in regular intervals as the program is running > Approximation of time spent in each method > Not deterministic

© Oscar Nierstrasz Just-In-Time Compilation 20 Roadmap > What is Just-In-Time Compilation (JIT)? > History of JIT > JIT Overhead > Optimization Techniques in JIT

© Oscar Nierstrasz Just-In-Time Compilation 21 Optimization Techniques > Loop Unrolling > Register Allocation > Global Code Motion > Machine Code Generation > Inlining > Code Positioning > Multi-Versioning > Dynamic Class Hierarchy Mutation

© Oscar Nierstrasz Just-In-Time Compilation 22 Standard Techniques Revised > Loop Unrolling —unroll “hot” loops only > Register Allocation —assign register to “hot path” variables first > Global Code Motion —move code from “hot” block > Machine Code Generation —generate code for the particular architecture

© Oscar Nierstrasz Just-In-Time Compilation 23 Inlining (Pros & Cons) > Pros —removes cost of a function call and return instruction —improves locality of code —once performed, additional optimizations can become possible > Cons —may degrade performance (code size overflows cache) —increases code size

© Oscar Nierstrasz Just-In-Time Compilation 24 Speculative Inlining  Inline Circle.computeArea() > Monitor class hierarchy  Recompile if Shape has more subclasses for (Shape shape : shapes) { shape.computeArea(); } for (Shape shape : shapes) { shape.computeArea(); } ShapeCircle

© Oscar Nierstrasz Just-In-Time Compilation 25 On Stack Replacement (OSR) for (Shape shape : shapes) { area = ((Circle)shape).r() * pi^2; } Square appears in the shapes. We cannot wait for loop to finish. Transfers execution from code A to code B even while code1 runs somewhere.

© Oscar Nierstrasz Just-In-Time Compilation 26 On Stack Replacement Applications > Invalidation of speculative optimization > De-optimization for debugging > Runtime optimization of long-running activations

© Oscar Nierstrasz Just-In-Time Compilation 27 Multiversioning > Multiple implementations of a code > The best implementation is chosen at runtime for (Shape shape : shapes) { area = shape.area(); } for (Shape shape : shapes) { area = ((Circle)shape).r() * pi^2; } for (Shape shape : shapes) { area = shape.area(); } homogeneous heterogeneous

© Oscar Nierstrasz Just-In-Time Compilation 28 Code Positioning > Linearizes the most common path > Improves code locality > Eliminates jumps > Improves cache performance F E D CB A F D B A C E

© Oscar Nierstrasz Just-In-Time Compilation 29 Inline Caches (ILC) > Improves performance by remembering the result of previous method lookup at the call site. Object[] values = { 1, "a", 2, "b"}; values[0].toString(); values[1].toString(); for (val : values) { val.toString(); } if (receiver.class == Integer) invoke #Integer.toString else invokevirtual values[0] #toString IC1 if (receiver.class == String) invoke #String.toString else invokevirtual values[1] #toString IC2 if (receiver.class == Integer) invoke #Integer.toString else invokevirtual val #toString IC3

© Oscar Nierstrasz Just-In-Time Compilation Instruction Scheduling > Improves Performance with instruction pipelines > Heavily dependent on underlying architecture load r1 load r2 add r3 load r1 add r3 load r2

© Oscar Nierstrasz Just-In-Time Compilation What Should You Know!  What is and what is not Just-In-Time?  What are advantages of JIT?  What are drawbacks of JIT?  What techniques can you use to reduce a JIT compilation overhead?  What extra information does the JIT compiler have compared to static compiler?  What is speculative inlining?  What is code positioning?  What is On Stack Replacement?  What is Inline Cache?

© Oscar Nierstrasz Just-In-Time Compilation Can You Answer These Questions?  When would you prefer not to use a JIT compiler?  Why can JIT compiler generate faster code than static compiler?  How does code positioning improve performance?  Why is OSR important for speculative optimizations?  What happens if you dynamically load class in Java (from optimizations point of view)?  What is is a time overhead of dynamic dispatch?  What is the time overhead of dynamic dispatch with ILC?

© Oscar Nierstrasz Just-In-Time Compilation 33 License > Attribution-ShareAlike 2.5 You are free: to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above.