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

Size: px
Start display at page:

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

Transcription

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

2 Who am I? Senior researcher at the Swedish Institute of Computer Science (SICS) working on programming languages, tools and distributed systems.

3 Acknowledgments Project funded by Ericsson AB. Joint work with Lars Rasmusson

4 What this talk is About Automatic synthesis of a JIT-compiling VM for Erlang. Our experiences with LLVM and MCJIT.

5 Outline Background Just-In-Time Compilation Erlang BEAM: Specification & Implementation Project Goals JIT:ing as it applies to BEAM Profiling Tracing Generating and Calling Native Code Future Work LLVM s Strengths and Weaknesses Questions

6 Just-In-Time (JIT) Compilation Decide at runtime to compile hot parts to native code. Fairly common implementation technique. Python (Psyco, PyPy) Smalltalk (Cog) Java (HotSpot) JavaScript (SquirrelFish Extreme, SpiderMonkey)

7 Erlang Functional language developed by Ericsson. Soft real-time. Multi-threaded with share-nothing semantics. Message passing. Powerful supervision primitives. Hot code loading and replacement. OTP: Framework for writing fault-tolerant applications. Compiled to virtual machine (VM), BEAM.

8 BEAM: Specification & Implementation BEAM is the name of the Erlang VM. A register machine. Approximately 150 instructions which are specialized to around 450 macro-instructions using a peephole optimizer during code loading. Instructions are CISC-like. Hand-written C (mostly) directly threaded interpreter. No authoritative description of the semantics of the VM except the implementation source code! HiPE a ahead-of-time native compiler Traditional back-end for x86, PowerPC, SPARC, ARM ErLLVM back-end based on LLVM

9 Motivation A JIT compiler increases flexibility. Compiled BEAM modules are platform independent. Cross-module optimization. Integrates naturally with code upgrade.

10 Project Goals Goals: Plan: Do as little manual work as possible. Preserve the semantics of plain BEAM. Automatically stay in sync with the plain BEAM, i.e. if bugs are fixed in the interpreter the JIT should not have to be modified manually. Have a native code generator which is state-of-the-art. Parse and extract semantics from the C implementation. Transform the parsed C source to C fragments which are then reassembled into a replacement VM which includes a JIT-compiler.

11 Outline Background Just-In-Time Compilation Erlang BEAM: Specification & Implementation Project Goals JIT:ing as it applies to BEAM Profiling Tracing Generating and Calling Native Code Future Work LLVM s Strengths and Weaknesses Questions

12 Just-In-Time (JIT) Compilation as it Applies to BEAM Use light-weight profiling to detect when we are at a place which is frequently executed. Trace the flow of execution until we get back to the same place. Compile trace to native code. NOTE: We are tracing the execution flow in the interpreter, the granularity is finer than BEAM opcodes. Profile Trace Generate Native Code Run Native

13 BEAMJIT: What is Needed? Three basic execution modes Profiling Tracing Native Interpreter loop has to be modified to support mode switching: Turn on/off tracing. Passing state to/from native code. Native code generation: Need the semantics for each instruction.

14 Profiling First step in figuring out what to JIT-compile Let Erlang compiler insert profile instructions at locations which can be the head of a loop Maintain a time stamp and counter for each location Measure execution intensity by incrementing a counter if the location was visited recently, reset otherwise Trigger tracing when count is high enough Blacklist locations which: Never produce a successful trace. Where we, when executing native code, leave the trace without executing the loop at least once.

15 Outline Background Just-In-Time Compilation Erlang BEAM: Specification & Implementation Project Goals JIT:ing as it applies to BEAM Profiling Tracing Generating and Calling Native Code Future Work LLVM s Strengths and Weaknesses Questions

16 Extracting the Semantics of the BEAM Opcodes bb_3944 bb_3950 i_bs_get_utf8_xfd is_function_fr bb_3784 bb_3788 bb_4130 bb_3776 bb_3783 i_bs_get_utf8_rfd bb_3936 bb_3794 bb_3792 bb_3790 i_bs_get_binary2_fxisid bb_4126 bb_3921 bb_4138 bb_4162 bb_3775 bb_4141 bb_4149 bb_4128 bb_4097 bb_4164 bb_3919 bb_3923 bb_4155 bb_3911 bb_4140 bb_4143 bb_3925 bb_4372 bb_4161 i_bs_get_binary2_frisid bb_4063 bb_4099 bb_4178 bb_4096 bb_4174 bb_4061 i_bs_skip_bits2_fxyi bb_4176 bb_4132 bb_4565 bb_4568 bb_4374 bb_4073 bb_4371 bb_4065 bb_4180 bb_4566 bb_4574 bb_4561 bb_4109 i_bs_get_float2_fxisid bb_4356 bb_4360 bb_4358 bb_4580 bb_4365 bb_4384 bb_4115 bb_4113 bb_4111 bb_4067 bb_4521 bb_4557 bb_4090 bb_4527 bb_4517 bb_4390 bb_4075 bb_4077 bb_4540 bb_4401 bb_4362 i_bs_skip_bits2_fxxi bb_4525 bb_4526 bb_4406 bb_4533 bb_4397 bb_4386 bb_4076 bb_4084 bb_4388 bb_4413 bb_4408 bb_4420 bb_2488 bb_3851 i_bs_skip_bits2_frxi bb_4405 bb_4486 bb_4493 i_bs_start_match2_rfiid i_bs_skip_bits2_fxri bb_4485 bb_4500 bb_3854 bb_4488 bb_4481 bb_4477 i_bs_get_integer_fiid i_bs_start_match2_yfiid i_bs_skip_bits2_fryi bb_4446 bb_4445 bb_4454 bb_4460 bb_3538 bb_4441 bb_4437 i_bs_start_match2_xfiid bb_4448 bb_3866 bb_3860 i_bs_match_string_xfii bb_4008 bb_3900 bb_3852 bb_4009 bb_4015 bb_4014 bb_4313 bb_4016 bb_3898 bb_4311 i_bs_match_string_rfii i_bs_get_float2_frisid bb_3872 bb_3894 bb_3896 bb_3883 bb_4343 bb_4315 bb_4320 bb_3884 bb_4326 bb_4339 bb_4327 bb_4329 bb_3878 do_is_ne_exact_literal bb_4345 bb_4317 bb_3847 bb_1636 bb_3880 i_is_ne_exact_literal_yfc bb_4341 bb_3762 bb_3745 bb_3746 bb_3752 bb_3758 bb_3764 bb_3584 bb_3753 bb_3760 Use libclang to parse and simplify the interpreter source: Use Erlang binding for libclang. Flatten variable scopes. Remove loops, replace by if + goto. Make fall-troughs explicit. Turn structured C into a spaghetti of Basic Blocks (BB), CFG Control Flow Graph. Do liveness-analysis of variables.

17 Naïve Tracing Use a new version of the interpreter, generated from the CFG. Generate a tracing and non-tracing version of each opcode. For each basic block we pass through, record basic block identity and PC. Abort trace if too long. If we reach the profile instruction we started the trace from We have found a loop!

18 Naïve Profiling to Tracing Mode Switch Direct threading PC 0xCDAADEF0 0xCDAADEFF 0xCDAACAF8 0xCDAAD432 Indirect threading PC xDEADBEEF 0XCDAACAF8 x = x + 1;... Profiling Opcodes 95: 0xCBAADEF0 96: 0xCDAEDEFF 97: 0xCDAACAF8 98: 0xCDAAD432 99: 0xDEADBEEF Tracing Opcodes 95: 0xCBBADEF0 96: 0xCBAEDEFF 97: 0xCBAACAF8 98: 0xCBAAD432 99: 0xDBADBEEF 0XCDAACAF8 x = x + 1;... 0XCBAACAF8 Have two implementations of each opcode. Switch the table of opcodes. record_trace_bb(4711, PC) x = x + 1;... Compiler has to assume that a mode switch can take place at any block performance suffers

19 Refined Tracing Modify the interpreter loop as little as possible. Have separate trace interpreter. Limit entry to the interpreter at instruction boundaries. Have separate cleanup-interpreter to continue execution to the next instruction boundary. Reuse cleanup-interpreter when returning from native mode. Profiling Tracing Native Cleanup

20 Further Tracing Refinements Ensure that we have a representative trace: Follow along a previously created trace. Allow multi-path traces. Generate native code when the trace has not grown for N successive iterations. Enforce limit on total size of trace.

21 Trace Compression Large CFGs slow down LLVM optimization and native code generation significantly. Solution: Compress traces to remove shared segments. BB=0 ip=0x4567 BB=0 ip=0x4567 BB=1 BB=2 BB=1 BB=2 ip=0x4567 ip=0x4567 ip=0x4567 ip=0x4567 BB=3 ip=0x4568 BB=3 ip=0x4568 BB=3 ip=0x4568 BB=4 ip=0x4569 BB=4 ip=0x4569 BB=4 ip=0x4569

22 Outline Background Just-In-Time Compilation Erlang BEAM: Specification & Implementation Project Goals JIT:ing as it applies to BEAM Profiling Tracing Generating and Calling Native Code Future Work LLVM s Strengths and Weaknesses Questions

23 Native-code Generation Glue together LLVM-IR-fragments for the trace. Guards are inserted to make sure we stay on the traced path. Fragments are extracted from the CFG as C-source, compiled to IR using clang (at build-time) and loaded during system initialization. Hand the resulting IR off to LLVM for the rest. jit_emu.c Trace beam_emu.c CFG Bitcode IR generator LLVM optimizer Native code fragments.c

24 Calling Native Code Switching from interpreter to native code: Use liveness information from the CFG. Package native-code as a function where the arguments are the live variables. Switching from native code to interpreter: The cleanup-interpreter is a set of functions, one for each BB, which tail-recursively calls the next BB. Arguments are the live variables. Cleanup-interpreter packs up live variables in a structure which the interpreter unpacks on return.

25 Performance Improvements Run native-code generation in separate thread. Erlang-aware constant propagation: Eliminate loads from code (constant at compile time). Will eliminate loading of immediates. Will eliminate many of the guards.

26 Performance Steady state: Eliminates most of the instruction decode overhead. Up to 50% reduction in runtime. Well-behaved programs: around 25%. Programs using cute tricks such as unrolling: up to 200% increase in runtime.

27 Future Work Full SMP support. Box/unboxing-aware constant propagation. Extend JIT support to fold in primitives.

28 Outline Background Just-In-Time Compilation Erlang BEAM: Specification & Implementation Project Goals JIT:ing as it applies to BEAM Profiling Tracing Generating and Calling Native Code Future Work LLVM s Strengths and Weaknesses Questions

29 LLVM s Strengths Access to the C AST via libclang. Quality of generated code. The optimization framework.

30 LLVM s Weaknesses No thread-safety Extra housekeeping to do things in the correct context. Compilation could be much faster. Native code has to be packaged as C-function Would really like to have enough control to patch generated native code. Clang/LLVM does bad job on the main interpreter: Allocates the VM s stack- and instruction-pointers on the stack. Inserts extra instruction sequence before indirect jumps (when dispatching to next VM instruction), GCC appears to insert it at the branch target and only if needed. Costs us 15-20%

31 Outline Background Just-In-Time Compilation Erlang BEAM: Specification & Implementation Project Goals JIT:ing as it applies to BEAM Profiling Tracing Generating and Calling Native Code Future Work LLVM s Strengths and Weaknesses Questions

32 Questions?

BEAMJIT, a Maze of Twisty Little Traces

BEAMJIT, a Maze of Twisty Little Traces BEAMJIT, a Maze of Twisty Little Traces A walk-through of the prototype just-in-time (JIT) compiler for Erlang. Frej Drejhammar 130613 Who am I? Senior researcher at the Swedish Institute

More information

A Status Update of BEAMJIT, the Just-in-Time Compiling Abstract Machine. Frej Drejhammar and Lars Rasmusson

A Status Update of BEAMJIT, the Just-in-Time Compiling Abstract Machine. Frej Drejhammar and Lars Rasmusson A Status Update of BEAMJIT, the Just-in-Time Compiling Abstract Machine Frej Drejhammar and Lars Rasmusson 140609 Who am I? Senior researcher at the Swedish Institute of Computer Science

More information

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

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1 SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine David Bélanger dbelan2@cs.mcgill.ca Sable Research Group McGill University Montreal, QC January 28, 2004 SABLEJIT: A Retargetable

More information

Just-In-Time Compilers & Runtime Optimizers

Just-In-Time Compilers & Runtime Optimizers COMP 412 FALL 2017 Just-In-Time Compilers & Runtime Optimizers Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved.

More information

Accelerating Ruby with LLVM

Accelerating Ruby with LLVM Accelerating Ruby with LLVM Evan Phoenix Oct 2, 2009 RUBY RUBY Strongly, dynamically typed RUBY Unified Model RUBY Everything is an object RUBY 3.class # => Fixnum RUBY Every code context is equal RUBY

More information

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

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler Hiroshi Inoue, Hiroshige Hayashizaki, Peng Wu and Toshio Nakatani IBM Research Tokyo IBM Research T.J. Watson Research Center April

More information

CSc 453 Interpreters & Interpretation

CSc 453 Interpreters & Interpretation CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson Interpreters An interpreter is a program that executes another program. An interpreter implements a virtual machine,

More information

Introduction. CS 2210 Compiler Design Wonsun Ahn

Introduction. CS 2210 Compiler Design Wonsun Ahn Introduction CS 2210 Compiler Design Wonsun Ahn What is a Compiler? Compiler: A program that translates source code written in one language to a target code written in another language Source code: Input

More information

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

Sista: Improving Cog s JIT performance. Clément Béra Sista: Improving Cog s JIT performance Clément Béra Main people involved in Sista Eliot Miranda Over 30 years experience in Smalltalk VM Clément Béra 2 years engineer in the Pharo team Phd student starting

More information

Trace-based JIT Compilation

Trace-based JIT Compilation Trace-based JIT Compilation Hiroshi Inoue, IBM Research - Tokyo 1 Trace JIT vs. Method JIT https://twitter.com/yukihiro_matz/status/533775624486133762 2 Background: Trace-based Compilation Using a Trace,

More information

CS553 Lecture Dynamic Optimizations 2

CS553 Lecture Dynamic Optimizations 2 Dynamic Optimizations Last time Predication and speculation Today Dynamic compilation CS553 Lecture Dynamic Optimizations 2 Motivation Limitations of static analysis Programs can have values and invariants

More information

Intermediate Code & Local Optimizations

Intermediate Code & Local Optimizations Lecture Outline Intermediate Code & Local Optimizations Intermediate code Local optimizations Compiler Design I (2011) 2 Code Generation Summary We have so far discussed Runtime organization Simple stack

More information

For our next chapter, we will discuss the emulation process which is an integral part of virtual machines.

For our next chapter, we will discuss the emulation process which is an integral part of virtual machines. For our next chapter, we will discuss the emulation process which is an integral part of virtual machines. 1 2 For today s lecture, we ll start by defining what we mean by emulation. Specifically, in this

More information

Intermediate Representations

Intermediate Representations Intermediate Representations Intermediate Representations (EaC Chaper 5) Source Code Front End IR Middle End IR Back End Target Code Front end - produces an intermediate representation (IR) Middle end

More information

Just-In-Time Compilation

Just-In-Time Compilation 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

More information

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

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation Language Implementation Methods The Design and Implementation of Programming Languages Compilation Interpretation Hybrid In Text: Chapter 1 2 Compilation Interpretation Translate high-level programs to

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

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

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1 Table of Contents About the Authors... iii Introduction... xvii Chapter 1: System Software... 1 1.1 Concept of System Software... 2 Types of Software Programs... 2 Software Programs and the Computing Machine...

More information

ART JIT in Android N. Xueliang ZHONG Linaro ART Team

ART JIT in Android N. Xueliang ZHONG Linaro ART Team ART JIT in Android N Xueliang ZHONG Linaro ART Team linaro-art@linaro.org 1 Outline Android Runtime (ART) and the new challenges ART Implementation in Android N Tooling Performance Data & Findings Q &

More information

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace Project there are a couple of 3 person teams regroup or see me or forever hold your peace a new drop with new type checking is coming using it is optional 1 Compiler Architecture source code Now we jump

More information

Intermediate Representation (IR)

Intermediate Representation (IR) Intermediate Representation (IR) Components and Design Goals for an IR IR encodes all knowledge the compiler has derived about source program. Simple compiler structure source code More typical compiler

More information

CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages CSc 520 Principles of Programming Languages 44: Interpreters Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1] Compiler

More information

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program. Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile program compiler Compiled program Step 2: run input Compiled program output Language Translation compilation is translation

More information

KOTLIN/NATIVE + CLANG, TRAVEL NOTES NIKOLAY IGOTTI, JETBRAINS

KOTLIN/NATIVE + CLANG, TRAVEL NOTES NIKOLAY IGOTTI, JETBRAINS KOTLIN/NATIVE + CLANG, TRAVEL NOTES NIKOLAY IGOTTI, JETBRAINS KOTLIN IS NOT JUST AN ISLAND KOTLIN LANGUAGE FP and OOP language Type inference, smart casts, nullability checks Generics (erased, with reification

More information

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

H.-S. Oh, B.-J. Kim, H.-K. Choi, S.-M. Moon. School of Electrical Engineering and Computer Science Seoul National University, Korea H.-S. Oh, B.-J. Kim, H.-K. Choi, S.-M. Moon School of Electrical Engineering and Computer Science Seoul National University, Korea Android apps are programmed using Java Android uses DVM instead of JVM

More information

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

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation CSE 501: Compiler Construction Course outline Main focus: program analysis and transformation how to represent programs? how to analyze programs? what to analyze? how to transform programs? what transformations

More information

Compiler-guaranteed Safety in Code-copying Virtual Machines

Compiler-guaranteed Safety in Code-copying Virtual Machines Compiler-guaranteed Safety in Code-copying Virtual Machines Gregory B. Prokopski Clark Verbrugge School of Computer Science Sable Research Group McGill University Montreal, Canada International Conference

More information

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters CSc 453 Compiler source Lexer tokens Parser AST Compilers and Systems Software 18 : Interpreters VM Code Gen IR Interm. Code Gen AST Semantic Analyser Department of Computer Science University of Arizona

More information

Running class Timing on Java HotSpot VM, 1

Running class Timing on Java HotSpot VM, 1 Compiler construction 2009 Lecture 3. A first look at optimization: Peephole optimization. A simple example A Java class public class A { public static int f (int x) { int r = 3; int s = r + 5; return

More information

Just In Time Compilation in PostgreSQL 11 and onward

Just In Time Compilation in PostgreSQL 11 and onward Just In Time Compilation in PostgreSQL 11 and onward Andres Freund PostgreSQL Developer & Committer Email: andres@anarazel.de Email: andres.freund@enterprisedb.com Twitter: @AndresFreundTec anarazel.de/talks/2018-09-07-pgopen-jit/jit.pdf

More information

What do Compilers Produce?

What do Compilers Produce? What do Compilers Produce? Pure Machine Code Compilers may generate code for a particular machine, not assuming any operating system or library routines. This is pure code because it includes nothing beyond

More information

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. IR Generation Announcements My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. This is a hard deadline and no late submissions will be

More information

Summary: Open Questions:

Summary: Open Questions: Summary: The paper proposes an new parallelization technique, which provides dynamic runtime parallelization of loops from binary single-thread programs with minimal architectural change. The realization

More information

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

Operational Semantics of Cool

Operational Semantics of Cool Operational Semantics of Cool Lecture 23 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 3 due on Friday Project 4 assigned on Friday. Due June 5, 11:55pm Office Hours this week Fri at 11am No Class

More information

Low level security. Andrew Ruef

Low level security. Andrew Ruef Low level security Andrew Ruef What s going on Stuff is getting hacked all the time We re writing tons of software Often with little regard to reliability let alone security The regulatory environment

More information

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

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator CS 412/413 Introduction to Compilers and Translators Andrew Myers Cornell University Administration Design reports due Friday Current demo schedule on web page send mail with preferred times if you haven

More information

CSc 553. Principles of Compilation. 2 : Interpreters. Department of Computer Science University of Arizona

CSc 553. Principles of Compilation. 2 : Interpreters. Department of Computer Science University of Arizona CSc 553 Principles of Compilation 2 : Interpreters Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg Compiler source Lexer tokens Parser AST VM

More information

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

Soot A Java Bytecode Optimization Framework. Sable Research Group School of Computer Science McGill University Soot A Java Bytecode Optimization Framework Sable Research Group School of Computer Science McGill University Goal Provide a Java framework for optimizing and annotating bytecode provide a set of API s

More information

Run-time Program Management. Hwansoo Han

Run-time Program Management. Hwansoo Han Run-time Program Management Hwansoo Han Run-time System Run-time system refers to Set of libraries needed for correct operation of language implementation Some parts obtain all the information from subroutine

More information

Optimization Prof. James L. Frankel Harvard University

Optimization Prof. James L. Frankel Harvard University Optimization Prof. James L. Frankel Harvard University Version of 4:24 PM 1-May-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reasons to Optimize Reduce execution time Reduce memory

More information

Tizen/Artik IoT Lecture Chapter 3. JerryScript Parser & VM

Tizen/Artik IoT Lecture Chapter 3. JerryScript Parser & VM 1 Tizen/Artik IoT Lecture Chapter 3. JerryScript Parser & VM Sungkyunkwan University Contents JerryScript Execution Flow JerryScript Parser Execution Flow Lexing Parsing Compact Bytecode (CBC) JerryScript

More information

Trace Compilation. Christian Wimmer September 2009

Trace Compilation. Christian Wimmer  September 2009 Trace Compilation Christian Wimmer cwimmer@uci.edu www.christianwimmer.at September 2009 Department of Computer Science University of California, Irvine Background Institute for System Software Johannes

More information

An Overview of Compilation

An Overview of Compilation An Overview of Compilation (www.cse.iitb.ac.in/ uday) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay January 2014 cs306 Compilation Overview: Outline 1/18 Outline

More information

Intermediate Representations

Intermediate Representations COMP 506 Rice University Spring 2018 Intermediate Representations source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

Combining Analyses, Combining Optimizations - Summary

Combining Analyses, Combining Optimizations - Summary Combining Analyses, Combining Optimizations - Summary 1. INTRODUCTION Cliff Click s thesis Combining Analysis, Combining Optimizations [Click and Cooper 1995] uses a structurally different intermediate

More information

Design & Implementation Overview

Design & Implementation Overview P Fall 2017 Outline P 1 2 3 4 5 6 7 P P Ontological commitments P Imperative l Architecture: Memory cells variables Data movement (memory memory, CPU memory) assignment Sequential machine instruction execution

More information

Compiler construction 2009

Compiler construction 2009 Compiler construction 2009 Lecture 3 JVM and optimization. A first look at optimization: Peephole optimization. A simple example A Java class public class A { public static int f (int x) { int r = 3; int

More information

Outline Smalltalk Overview Pragmatic Smalltalk Closing. Pragmatic Smalltalk. David Chisnall. February 7,

Outline Smalltalk Overview Pragmatic Smalltalk Closing. Pragmatic Smalltalk. David Chisnall. February 7, February 7, 2009 http://etoileos.com Outline Using The Smalltalk Family Smalltalk - first dynamic, object-oriented, language. Self - Smalltalk without classes. JavaScript - Self with Java syntax. A Quick

More information

Mixed Mode Execution with Context Threading

Mixed Mode Execution with Context Threading Mixed Mode Execution with Context Threading Mathew Zaleski, Marc Berndl, Angela Demke Brown University of Toronto {matz,berndl,demke}@cs.toronto.edu (CASCON 2005, Oct 19/2005.) Overview Introduction Background:

More information

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture Liang Liu liang.liu@eit.lth.se 1 Outline Reiteration Instruction Set Principles The Role of Compilers MIPS 2 Main Content Computer

More information

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

Usually, target code is semantically equivalent to source code, but not always! What is a Compiler? Compiler A program that translates code in one language (source code) to code in another language (target code). Usually, target code is semantically equivalent to source code, but

More information

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization. Where We Are Source Code Lexical Analysis Syntax Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Machine Code Where We Are Source Code Lexical Analysis Syntax Analysis

More information

Dynamic Control Hazard Avoidance

Dynamic Control Hazard Avoidance Dynamic Control Hazard Avoidance Consider Effects of Increasing the ILP Control dependencies rapidly become the limiting factor they tend to not get optimized by the compiler more instructions/sec ==>

More information

HiPE Copyright Ericsson AB. All Rights Reserved. HiPE March 11, 2019

HiPE Copyright Ericsson AB. All Rights Reserved. HiPE March 11, 2019 Copyright 2006-2019 Ericsson AB. All Rights Reserved. 3.18.3 March 11, 2019 Copyright 2006-2019 Ericsson AB. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may

More information

PyPy - How to not write Virtual Machines for Dynamic Languages

PyPy - How to not write Virtual Machines for Dynamic Languages PyPy - How to not write Virtual Machines for Dynamic Languages Institut für Informatik Heinrich-Heine-Universität Düsseldorf ESUG 2007 Scope This talk is about: implementing dynamic languages (with a focus

More information

Tour of common optimizations

Tour of common optimizations Tour of common optimizations Simple example foo(z) { x := 3 + 6; y := x 5 return z * y } Simple example foo(z) { x := 3 + 6; y := x 5; return z * y } x:=9; Applying Constant Folding Simple example foo(z)

More information

Intermediate Code & Local Optimizations. Lecture 20

Intermediate Code & Local Optimizations. Lecture 20 Intermediate Code & Local Optimizations Lecture 20 Lecture Outline Intermediate code Local optimizations Next time: global optimizations 2 Code Generation Summary We have discussed Runtime organization

More information

YETI. GraduallY Extensible Trace Interpreter VEE Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto)

YETI. GraduallY Extensible Trace Interpreter VEE Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto) YETI GraduallY Extensible Trace Interpreter Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto) VEE 2007 1 Goal Create a VM that is more easily extended with a just

More information

Virtual Machines and Dynamic Translation: Implementing ISAs in Software

Virtual Machines and Dynamic Translation: Implementing ISAs in Software Virtual Machines and Dynamic Translation: Implementing ISAs in Software Krste Asanovic Laboratory for Computer Science Massachusetts Institute of Technology Software Applications How is a software application

More information

Alternatives for semantic processing

Alternatives for semantic processing Semantic Processing Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies

More information

Truffle A language implementation framework

Truffle A language implementation framework Truffle A language implementation framework Boris Spasojević Senior Researcher VM Research Group, Oracle Labs Slides based on previous talks given by Christian Wimmer, Christian Humer and Matthias Grimmer.

More information

15-411: LLVM. Jan Hoffmann. Substantial portions courtesy of Deby Katz

15-411: LLVM. Jan Hoffmann. Substantial portions courtesy of Deby Katz 15-411: LLVM Jan Hoffmann Substantial portions courtesy of Deby Katz and Gennady Pekhimenko, Olatunji Ruwase,Chris Lattner, Vikram Adve, and David Koes Carnegie What is LLVM? A collection of modular and

More information

Relay: a high level differentiable IR. Jared Roesch TVMConf December 12th, 2018

Relay: a high level differentiable IR. Jared Roesch TVMConf December 12th, 2018 Relay: a high level differentiable IR Jared Roesch TVMConf December 12th, 2018!1 This represents months of joint work with lots of great folks:!2 TVM Stack Optimization Relay High-Level Differentiable

More information

LLVM: A Compilation Framework. Transformation

LLVM: A Compilation Framework. Transformation Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA LLVM: A Compilation Framework

More information

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

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano Building a Runnable Program and Code Improvement Dario Marasco, Greg Klepic, Tess DiStefano Building a Runnable Program Review Front end code Source code analysis Syntax tree Back end code Target code

More information

Jazelle ARM. By: Adrian Cretzu & Sabine Loebner

Jazelle ARM. By: Adrian Cretzu & Sabine Loebner Jazelle ARM By: Adrian Cretzu & Sabine Loebner Table of Contents Java o Challenge o Acceleration Techniques ARM Overview o RISC o ISA o Background Jazelle o Background o Jazelle mode o bytecode execution

More information

High-Level Language VMs

High-Level Language VMs High-Level Language VMs Outline Motivation What is the need for HLL VMs? How are these different from System or Process VMs? Approach to HLL VMs Evolutionary history Pascal P-code Object oriented HLL VMs

More information

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz Compiler Design Fall 2015 Control-Flow Analysis Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292

More information

Compiler Optimization

Compiler Optimization Compiler Optimization The compiler translates programs written in a high-level language to assembly language code Assembly language code is translated to object code by an assembler Object code modules

More information

Code Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University

Code Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University Code Generation Frédéric Haziza Department of Computer Systems Uppsala University Spring 2008 Operating Systems Process Management Memory Management Storage Management Compilers Compiling

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

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

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002 Outline 5 Fall 2002 Lecture 17: Putting it all together From parsing to code generation Saman Amarasinghe 2 6.035 MIT Fall 1998 How to make the computer understand? Write a program using a programming

More information

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

More information

Compiler Design Spring 2018

Compiler Design Spring 2018 Compiler Design Spring 2018 Thomas R. Gross Computer Science Department ETH Zurich, Switzerland 1 Logistics Lecture Tuesdays: 10:15 11:55 Thursdays: 10:15 -- 11:55 In ETF E1 Recitation Announced later

More information

ECE 5775 (Fall 17) High-Level Digital Design Automation. Static Single Assignment

ECE 5775 (Fall 17) High-Level Digital Design Automation. Static Single Assignment ECE 5775 (Fall 17) High-Level Digital Design Automation Static Single Assignment Announcements HW 1 released (due Friday) Student-led discussions on Tuesday 9/26 Sign up on Piazza: 3 students / group Meet

More information

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

More information

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

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2 Building a Compiler with JoeQ AKA, how to solve Homework 2 Outline of this lecture Building a compiler: what pieces we need? An effective IR for Java joeq Homework hints How to Build a Compiler 1. Choose

More information

Under the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world.

Under the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world. Under the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world. Supercharge your PS3 game code Part 1: Compiler internals.

More information

6. Intermediate Representation

6. Intermediate Representation 6. Intermediate Representation Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/

More information

Pyrlang: A High Performance Erlang Virtual Machine Based on RPython

Pyrlang: A High Performance Erlang Virtual Machine Based on RPython TOKYO INSTITUTE OF TECHNOLOGY MASTER THESIS Pyrlang: A High Performance Erlang Virtual Machine Based on RPython Author: Ruochen HUANG 14M54036 Supervisor: Prof. Hidehiko MASUHARA A thesis submitted in

More information

Lecture 4: Instruction Set Design/Pipelining

Lecture 4: Instruction Set Design/Pipelining Lecture 4: Instruction Set Design/Pipelining Instruction set design (Sections 2.9-2.12) control instructions instruction encoding Basic pipelining implementation (Section A.1) 1 Control Transfer Instructions

More information

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis Synthesis of output program (back-end) Intermediate Code Generation Optimization Before and after generating machine

More information

Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code

Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code BILL BLUNDEN Apress About the Author Acknowledgments Introduction xi xiii xv Chapter 1 Preventative Medicine 1 1.1 Core Problems 2

More information

INTRODUCTION TO LLVM Bo Wang SA 2016 Fall

INTRODUCTION TO LLVM Bo Wang SA 2016 Fall INTRODUCTION TO LLVM Bo Wang SA 2016 Fall LLVM Basic LLVM IR LLVM Pass OUTLINE What is LLVM? LLVM is a compiler infrastructure designed as a set of reusable libraries with well-defined interfaces. Implemented

More information

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

An Introduction to Erlang

An Introduction to Erlang Erlang Solutions Ltd An Introduction to Erlang From behind the trenches GOTO Copenhagen May 13 th, 2011 Francesco Cesarini Founder, Technical Director @FrancescoC francesco@erlang-solutions.com So Here

More information

HSA Foundation! Advanced Topics on Heterogeneous System Architectures. Politecnico di Milano! Seminar Room (Bld 20)! 15 December, 2017!

HSA Foundation! Advanced Topics on Heterogeneous System Architectures. Politecnico di Milano! Seminar Room (Bld 20)! 15 December, 2017! Advanced Topics on Heterogeneous System Architectures HSA Foundation! Politecnico di Milano! Seminar Room (Bld 20)! 15 December, 2017! Antonio R. Miele! Marco D. Santambrogio! Politecnico di Milano! 2

More information

Advanced Computer Architecture

Advanced Computer Architecture ECE 563 Advanced Computer Architecture Fall 2007 Lecture 14: Virtual Machines 563 L14.1 Fall 2009 Outline Types of Virtual Machine User-level (or Process VMs) System-level Techniques for implementing all

More information

CS577 Modern Language Processors. Spring 2018 Lecture Interpreters

CS577 Modern Language Processors. Spring 2018 Lecture Interpreters CS577 Modern Language Processors Spring 2018 Lecture Interpreters 1 MAKING INTERPRETERS EFFICIENT VM programs have an explicitly specified binary representation, typically called bytecode. Most VM s can

More information

IBM Research - Tokyo 数理 計算科学特論 C プログラミング言語処理系の最先端実装技術. Trace Compilation IBM Corporation

IBM Research - Tokyo 数理 計算科学特論 C プログラミング言語処理系の最先端実装技術. Trace Compilation IBM Corporation 数理 計算科学特論 C プログラミング言語処理系の最先端実装技術 Trace Compilation Trace JIT vs. Method JIT https://twitter.com/yukihiro_matz/status/533775624486133762 2 Background: Trace-based Compilation Using a Trace, a hot path identified

More information

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 22: Remote Procedure Call (RPC)

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 22: Remote Procedure Call (RPC) CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2002 Lecture 22: Remote Procedure Call (RPC) 22.0 Main Point Send/receive One vs. two-way communication Remote Procedure

More information

History of Compilers The term

History of Compilers The term History of Compilers The term compiler was coined in the early 1950s by Grace Murray Hopper. Translation was viewed as the compilation of a sequence of machine-language subprograms selected from a library.

More information

CS 406/534 Compiler Construction Putting It All Together

CS 406/534 Compiler Construction Putting It All Together CS 406/534 Compiler Construction Putting It All Together Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy

More information

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree.

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree. Group B Assignment 9 Att (2) Perm(3) Oral(5) Total(10) Sign Title of Assignment: Code generation using DAG. 9.1.1 Problem Definition: Code generation using DAG / labeled tree. 9.1.2 Perquisite: Lex, Yacc,

More information

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

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

SPIN Operating System

SPIN Operating System SPIN Operating System Motivation: general purpose, UNIX-based operating systems can perform poorly when the applications have resource usage patterns poorly handled by kernel code Why? Current crop of

More information

6. Intermediate Representation!

6. Intermediate Representation! 6. Intermediate Representation! Prof. O. Nierstrasz! Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.! http://www.cs.ucla.edu/~palsberg/!

More information

Adaptive Multi-Level Compilation in a Trace-based Java JIT Compiler

Adaptive Multi-Level Compilation in a Trace-based Java JIT Compiler Adaptive Multi-Level Compilation in a Trace-based Java JIT Compiler Hiroshi Inoue, Hiroshige Hayashizaki, Peng Wu and Toshio Nakatani IBM Research Tokyo IBM Research T.J. Watson Research Center October

More information

Lecture 3 Overview of the LLVM Compiler

Lecture 3 Overview of the LLVM Compiler LLVM Compiler System Lecture 3 Overview of the LLVM Compiler The LLVM Compiler Infrastructure - Provides reusable components for building compilers - Reduce the time/cost to build a new compiler - Build

More information