Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

More Intel machine language and one more look at other architectures.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Virtual Machines Matthew Dwyer 324E Nichols Hall
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
1 Registers and MAL - Part I. Motivation So far there are some details that we have ignored instructions can have different formats most computers have.
CPSC Compiler Tutorial 8 Code Generator (unoptimized)
Aarhus University, 2005Esmertec AG1 Implementing Object-Oriented Virtual Machines Lars Bak & Kasper Lund Esmertec AG
Tentative Schedule 20/12 Interpreter+ Code Generation 27/12 Code Generation for Control Flow 3/1 Activation Records 10/1 Program Analysis 17/1 Register.
Run time vs. Compile time
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
1/28/2004CSCI 315 Operating Systems Design1 Operating System Structures & Processes Notice: The slides for this lecture have been largely based on those.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
Introduction to Java.
CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Intro to Java The Java Virtual Machine. What is the JVM  a software emulation of a hypothetical computing machine that runs Java bytecodes (Java compiler.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
7. Just In Time Compilation Prof. O. Nierstrasz Jan Kurs.
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)
Introduction to the Java Virtual Machine 井民全. JVM (Java Virtual Machine) the environment in which the java programs execute The specification define an.
O VERVIEW OF THE IBM J AVA J UST - IN -T IME C OMPILER Presenters: Zhenhua Liu, Sanjeev Singh 1.
Research supported by IBM CAS, NSERC, CITO Context Threading: A flexible and efficient dispatch technique for virtual machine interpreters Marc Berndl.
1 Introduction to JVM Based on material produced by Bill Venners.
Game Scripting by: Nicholas Haines. What is Scripting? Interpreted Language Interpreted Language –As the game runs.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 7 OS System Structure.
How to select superinstructions for Ruby ZAKIROV Salikh*, CHIBA Shigeru*, and SHIBAYAMA Etsuya** * Tokyo Institute of Technology, dept. of Mathematical.
Chapter 4 Memory Management Virtual Memory.
Alternative Dispatch Techniques for the Tcl VM Benjamin Vitale Mathew Zaleski.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CS 598 Scripting Languages Design and Implementation 12. Interpreter implementation.
Language Implementation Overview John Keyser Spring 2016.
Procedures and Functions Procedures and Functions – subprograms – are named fragments of program they can be called from numerous places  within a main.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
RealTimeSystems Lab Jong-Koo, Lim
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
(Not too) Real-Time JVM (Progress Report)
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
Smalltalk Implementation Harry Porter, October 2009 Smalltalk Implementation: Optimization Techniques Prof. Harry Porter Portland State University 1.
INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Compiler Chapter 9. Intermediate Languages Sung-Dong Kim Dept. of Computer Engineering, Hansung University.
Lecture 3 Translation.
Efficient Software-Based Fault Isolation
Advanced Computer Systems
Introduction to Operating Systems
Chapter 1 Introduction.
Names and Attributes Names are a key programming language feature
The Java Virtual Machine (JVM)
Vijay Janapa Reddi The University of Texas at Austin Interpretation 2
Compiler Chapter 9. Intermediate Languages
Compilers.
Chapter 1 Introduction.
Introduction Enosis Learning.
Java Virtual Machine Complete subject details are available at:
Introduction Enosis Learning.
CSc 453 Interpreters & Interpretation
.Net Framework Details Imran Rashid CTO at ManiWeber Technologies.
Lecture 4: Instruction Set Design/Pipelining
Procedure Linkages Standard procedure linkage Procedure has
CSc 453 Interpreters & Interpretation
Dynamic Binary Translators and Instrumenters
Presentation transcript:

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers2 Virtual Machines Virtual machines (VMs) provide an intermediate stage for the compilation of programming languages. VMs are machines because they permit a step-by-step execution of programs. VMs are virtual (abstract) because typically they –are not implemented in hardware –omit many details of real (hardware) machines VMs are tailored to the particular operations required to implement a particular (class of) source language(s)

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers3 Virtual Machines: Pros Bridge the gap between the high level of a programming language and the low level of a real machine. Require less implementation effort Easier to experiment and modify (crucial for new PLs) Portability is enhanced –VM interpreters are typically implemented in C –VM code can be transferred over the net and run in most machines –VM code is (often significantly) smaller than object code Easier to be formally proven correct Various safety features of VM code can be verified

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers4 Virtual Machines: Cons Inferior performance of VM interpreters compared with a native code compiler for the same language –Cost of interpretation –Significantly more difficult to take advantage of modern hardware features (e.g. hardware-based branch prediction)

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers5 Implementation of Interpreters There are various ways to implement interpreters: 1.Direct string interpretation 2.Compilation into a (typically abstract syntax) tree and interpretation of that tree 3.Compilation into a virtual machine and interpretation of the VM code Source level interpreters are very slow because they spend much of their time in doing lexical analysis Such interpreters avoid lexical analysis costs, but they still have to do much list scanning ( e.g. when implementing a ‘goto’ or ‘call’)

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers6 Virtual Machine Interpreters By compiling the program to the instruction set of a virtual machine and adding a table that maps names and labels to addresses in this program, some of the interpretation overhead can be reduced For convenience, most VM instruction sets use integral numbers of bytes to represent everything –opcodes, register numbers, stack slot numbers, indices into the function or constant table, etc. Opcode Example: The GET_CONST2 instruction Reg #CONSTANT

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers7 Components of Virtual Machine Implementations Program store (code area) –Program is a sequence of instructions –Loader State (of execution) –Stack –Heap –Registers Special register (program counter) pointing to the next instruction to be executed Runtime system component –Memory allocator –Garbage collector

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers8 Basic Structure of a Bytecode Interpreter byte *pc = &byte_program[0]; while(TRUE) { opcode = pc[0]; switch (opcode) { … case GET_CONST2: source_reg_num = pc[1]; const_num_to_match = get_2_bytes(&pc[2]); … pc += 4; break; … case JUMP: jump_addr = get_4_bytes(&pc[1]); pc = &byte_program[jump_addr]; break; … }

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers9 To align or to not align VM instructions? Opcode Jump Address Opcode Jump Address Unused Bytes NOTE: Padding of instructions can be done by the loader. The size of the bytecode files need not be affected.

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers10 Bytecode Interpreter with Aligned Instructions byte *pc = &byte_program[0]; while(TRUE) { opcode = pc[0]; switch (opcode) { … case GET_CONST2: source_reg_num = pc[1]; const_num_to_match = get_2_bytes(&pc[2]); … pc += 4; break; … case JUMP: // aligned version jump_addr = get_4_bytes(&pc[4]); pc = &byte_program[jump_addr]; break; … }

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers11 Interpreter with Abstracted Instruction Encoding byte *pc = &byte_program[0]; while(TRUE) { opcode = pc[0]; switch (opcode) { … case GET_CONST2: source_reg_num = pc[GET_CONST2_ARG1]; const_num_to_match = get_2_bytes(&pc[GET_CONST2_ARG2]); … pc += GET_CONST2_SIZEOF; break; … case JUMP: // aligned version jump_addr = get_4_bytes(&pc[JUMP_ARG1]); pc = &byte_program[jump_addr]; break; … } #define GET_CONST2_SIZEOF 4 #define JUMP_SIZEOF 8 #define GET_CONST2_ARG1 1 #define GET_CONST2_ARG2 2 #define JUMP_ARG1 4

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers12 Interpreter with Abstracted Control byte *pc = &byte_program[0]; while(TRUE) { next_instruction: opcode = pc[0]; switch (opcode) { … case GET_CONST2: source_reg_num = pc[GET_CONST2_ARG1]; const_num_to_match = get_2_bytes(&pc[GET_CONST2_ARG2]); … pc += GET_CONST2_SIZEOF; NEXT_INSTRUCTION; … case JUMP: // aligned version jump_addr = get_4_bytes(&pc[JUMP_ARG1]); pc = &byte_program[jump_addr]; NEXT_INSTRUCTION; … } #define NEXT_INSTRUCTION \ goto next_instruction

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers13 Structure of Indirectly Threaded Interpreter byte *pc = &byte_program[0]; while(TRUE) { next_instruction: opcode = pc[0]; switch (opcode) { … case GET_CONST2: get_const2_label: source_reg_num = pc[GET_CONST2_ARG1]; const_num_to_match = get_2_bytes(&pc[GET_CONST2_ARG2]); … pc += GET_CONST2_SIZEOF; NEXT_INSTRUCTION; … case JUMP: // aligned version jump_label: jump_addr = get_4_bytes(&pc[JUMP_ARG1]); pc = &byte_program[jump_addr]; NEXT_INSTRUCTION; … } static void *label_tab[] { … &&get_const2_label; … &&jump_label; … } #define NEXT_INSTRUCTION \ goto **(void **)(label_tab[*pc])

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers14 Structure of Directly Threaded Interpreter byte *pc = &byte_program[0]; while(TRUE) { next_instruction: opcode = pc[0]; switch (opcode) { … case GET_CONST2: get_const2_label: source_reg_num = pc[GET_CONST2_ARG1]; const_num_to_match = get_2_bytes(&pc[GET_CONST2_ARG2]); … pc += GET_CONST2_SIZEOF; NEXT_INSTRUCTION; … case JUMP: // aligned version jump_label: pc = get_4_bytes(&pc[JUMP_ARG1]); NEXT_INSTRUCTION; … } static void *label_tab[] { … &&get_const2_label; … &&jump_label; … } #define NEXT_INSTRUCTION \ goto **(void **)(pc)

Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers15 Instruction Merging and Specialization Instruction Merging: A sequence of VM instructions is replaced by a single (mega-)instruction –Reduces interpretation overhead –Code locality is enhanced –Results in more compact bytecode –C compiler has bigger basic blocks to perform optimizations on Instruction Specialization: A special case of a VM instruction is created, typically one where some arguments have a known value which is hard-coded –Eliminates the cost of argument decoding –Results in more compact bytecode representation –Reduces the register pressure from some basic blocks