Chap. 10, Intermediate Representations J. H. Wang Dec. 27, 2011.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
CS 153: Concepts of Compiler Design November 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Advice Weaving in AspectJ Alex Gontmakher. Outline Possible implementation approaches Quick JVM primer AJC implementation Performance Evaluation.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Lab 9 Java Bytecode & The Jasmin Assembler
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 31: Building a Runnable Program COMP 144 Programming Language Concepts Spring 2002.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006.
Compilation 2007 The What and Why of Compilers Michael I. Schwartzbach BRICS, University of Aarhus.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
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.
Compilation 2007 The Java Virtual Machine Michael I. Schwartzbach BRICS, University of Aarhus.
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
COP4020 Programming Languages
Code Generation Introduction. Compiler (scalac, gcc) Compiler (scalac, gcc) machine code (e.g. x86, arm, JVM) efficient to execute i=0 while (i < 10)
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.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
JVM And CLR Dan Agar April 16, Outline Java and.NET Design Philosophies Overview of Virtual Machines Technical Look at JVM and CLR Comparison of.
Arpit Jain Mtech1. Outline Introduction Dalvik VM Java VM Examples Comparisons Experimental Evaluation.
1 The Java Virtual Machine Yearly Programming Project.
The Java Virtual Machine 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Chapter 1. Introduction.
Implement High-level Program Language on JVM CSCE 531 ZHONGHAO LIU ZHONGHAO LIU XIAO LIN.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Lecture 10 : Introduction to Java Virtual Machine
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
1 Introduction to JVM Based on material produced by Bill Venners.
Syntax Directed Translation Compiler Design Lecture (03/16//98) Computer Science Rensselaer Polytechnic.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?
 Programming - the process of creating computer programs.
Chap. 10, Intermediate Representations J. H. Wang Dec. 14, 2015.
Building a Java Interpreter CS 142 (b) 01/14. Lab Sessions Monday, Wednesday – 10am – noon – ICS 189 Send an or make an appointment with the TA.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 18: Code Safety and Virtual Machines
UNDER THE HOOD: THE JAVA VIRTUAL MACHINE II CS2110 Fall 200 Lecture 25 1.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Review on Program Challenge CSc3210 Yuan Long.
Recap: Printing Trees into Bytecodes To evaluate e 1 *e 2 interpreter –evaluates e 1 –evaluates e 2 –combines the result using * Compiler for e 1 *e 2.
COP4020 Programming Languages Introduction Prof. Robert van Engelen (modified by Prof. Em. Chris Lacher)
RealTimeSystems Lab Jong-Koo, Lim
CS 536 © CS 536 Spring Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 15.
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.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Before You Begin Nahla Abuel-ola /WIT.
Introduction to Compiler Construction
The Java Virtual Machine (JVM)
CS216: Program and Data Representation
Compiler Chapter 9. Intermediate Languages
Java package classes Java package classes.
CS 153: Concepts of Compiler Design November 2 Class Meeting
Java Virtual Machine (JVM)
Lecture 19: 0xCAFEBABE (Java Byte Codes) CS201j: Engineering Software
Byte Code Verification
Course Overview PART I: overview material PART II: inside a compiler
CS 153: Concepts of Compiler Design November 6 Class Meeting
Building a Java Interpreter
Course Overview PART I: overview material PART II: inside a compiler
CMPE 152: Compiler Design April 16 Class Meeting
Presentation transcript:

Chap. 10, Intermediate Representations J. H. Wang Dec. 27, 2011

Outline Overview Java Virtual Machine Static Single Assignment Form

Overview Ch.7: AST Ch.8-9: Semantic analysis Ch.10: Intermediate representation Ch.11: Code generation for a virtual machine Ch.12: Runtime support Ch.13: Target code generation

Overview Semantic gap between high-level source languages and target machine language Examples –Early C++ compilers cpp: preprocessor cfront: translate C++ into C C compiler

Another Example LaTeX –TeX: designed by Donald Knuth –dvi: device-independent intermediate representation –Ps: PostScript –pixels Portability enhanced

Challenges –An intermediate language (IL) must be precisely defined –Translators and processors must be crafted for an IL –Connections must be made between levels so that feedback from intermediate steps can be related to the source program Other concerns –Efficiency

The Middle-End Front-end: parser Back-end: code generator Middle-end: components between front- and back-ends Compiler suites that host multiple source languages and target multiple instruction sets obtain great leverage from a middle-end –Ex: s source languages, t target languages s*t vs. s+t

Additional Advantages An IL allows various system components to interoperate by facilitating access to information about the program –E.g. variable names and types, and source line numbers could be useful in the debugger An IL simplifies development and testing of system components The middle-end contains phases that would otherwise be duplicated among the front- and back-ends It allows components and tools to interface with other products

It can simply the pioneering and prototyping of news ideas The ILs and its interpreter can serve as a reference definition of a language Interpreters written for a well-defined IL are helpful in testing and porting compilers An IL enables the crafting of a retargetable code generator, which greatly enhances its portability –Pascal: P-code –Java: JVM –Ada: DIANA (Descriptive Intermediate Attributed Notation for Ada)

Java Virtual Machine Class files: binary encodings of the data and instructions in a Java program Design principles –Compactness Instructions in nearly zero-address form –A runtime stack is used –Operands are implicit »E.g.: iadd instruction –A loss of runtime performance Multiple instructions to accomplish the same effect –To push 0 on TOS » iconst_0, ldc_w 0

–Safety An instruction can reference storage only if it is of the type allowed by the instruction, and only if the storage is located in an area appropriate for access From security’s point of view, purely zero-address form is problematic –The registers that could be accessed by a load instruction may not be known until runtime –JVM: not zero-address »E.g. iload 5 When a class file is loaded, many other checks are performed by the bytecode verifier

Contents of a Class File Attributes that contain various information about the compiled class –Types: primitive and reference types –(Fig. 10.4) Primitive type: a single character Reference type t: Lt –E.g.: String type in java.lang package: Ljava/lang/String; –

–Constant pools tagged union –int, float, java.lang.String Referenced by its ordinal position, not byte-offset

JVM Instructions Arithmetic Register traffic Registers and types Static fields Instance fields Branching Other method calls Stack operations

Arithmetic int: 32-bit, 2’s complement –iadd fadd(float) ladd(long) dadd(double)

Register Traffic JVM has an unlimited number of virtual registers JVM registers typically host a method’s local variables JVM registers are untyped –iload 2 iload_2: abbreviated –istore 10 –aload and astore: for reference types

Registers and Types Static analysis (or bytecode verification) –To ensure that values flow in and our of registers without compromising Java’s type systems Type conversion –i2f

Static Fields getstatic –E.g.: getstatic java/lang/System/out Ljava/io/PrintStream; putstatic

Instance Fields A class can declare instance field for which instance-specific storage is allocated getfield –getfiled Point/x I putfield –putfield Point/x I

Branching ifeq, ifne, iflt, ifle, ifgt, ifge if_icmpeq, if_icmpne, if_icmplt, if_icmple, if_icmpgt, if_icmpge

Static Method Calls invokestatic –invokestatic java/lang/Math/pow(DD)D

Instance-Specific Method Calls invokevirtual –invokevirtual java/io/PrintStream/print(Z)V

Static Single Assignment Form (omitted)

Thanks for Your Attention!