COMP3131/9102: Programming Languages and Compilers
|
|
- Lisa Webster
- 6 years ago
- Views:
Transcription
1 COMP3131/9102: Programming Languages and Compilers Jingling Xue School of Computer Science and Engineering The University of New South Wales Sydney, NSW 2052, Australia Jingling Xue COMP3131/9102 Page 513 May 8, 2017
2 Lectures on Java Byte Code Generation 1. Lecture 10: Code generation (Assignment 5) 2. Lecture 11: Chris lecture 3. Lecture 12: Code generation + Revision COMP3131/9102 Page 514 May 8, 2017
3 Understanding Jasmin Assembly Language 1. Read syntax.bnf to understand Jasmin s syntax 2. Read Jasmin User Guide to Jasmin s syntax 3. Read Jasmin instruction reference manual to understand its instructions (1-to-1 mapped to JVM instructions) 4. To under a particular feature, do the following: (a) Design a Java program Test.java (b) javac -g Test.java (c) javap -c Test > Test.j (jasmind Test.class) (d) Study the Jasmin code in Test.j COMP3131/9102 Page 515 May 8, 2017
4 1. Translation: Lecture 10: Java Byte Code Generation Expressions (including actual parameters) Statements Declarations (including formal parameters) 2. Allocating variable indices for local variables 3. Some special code generation issues: lvalue (store) v.s rvalue (load) assignment expressions such as a = b[1+i] = 1 Expression statements such as 1 + (a = 2); Short-circuit evaluations break and continue return 4. Generating Jasmin assembler directives.limit stack.limit locals.var.line COMP3131/9102 Page 516 May 8, 2017
5 VC.lang.System.class The VC Compiler Source Code (gcd.vc) Assignment 1: Scanner Tokens Assignment 2 & 3: Parser AST Assignment 4: Semantic Analyser Decorated AST Assignment 5: Code Generator Jasmin Assembly Code (gcd.j) Jasmin Assembler Java Byte Code (gcd.class) Java Virtual Machine Results COMP3131/9102 Page 517 May 8, 2017
6 Object Code Generation for Register-Based Machines Three issues: register allocation instruction selection code scheduling These are simpler for stack-based machines, especially if the quality of the generated code is not a concern Advanced Compiler Construction: Code Optimisations Object code generation for register-based machines Research-oriented topics COMP3131/9102 Page 518 May 8, 2017
7 Example 1: gcd.vc int i = 2; int j = 4; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a - (a/b) *b); } int main() { putintln(gcd(i, j)); return 0; // optional in VC or C/C++ } COMP3131/9102 Page 519 May 8, 2017
8 Example 1: gcd.vc(red Assumed by the VC Compiler) public class gcd { static int i = 2; static int j = 4; public gcd() { } // the default constructor int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a - (a/b) *b); } } void main(string argv[]) { gcd vc$; vc$ = new gcd(); System.putIntLn(vc$.gcd(i, j)); return; } COMP3131/9102 Page 520 May 8, 2017
9 int main() is assumed to be: Example 1: gcd.vc (cont d) public static void main(string argv[]) {... } visitfuncdec: a return is always emitted just in case no return expr was present in the main of a VC program visitreturnstmt: emit a RETURN rather than IRETURN even if a return statement, e.g., return expr is present in the main of a VC program All VC functions are assumed to be instance methods with the package access All global variables are assumed to be static field variables with the package access All built-in VC functions are static COMP3131/9102 Page 521 May 8, 2017
10 .class public gcd.super java/lang/object.field static i I.field static j I Example 1: gcd.j ; standard class static initializer.method static <clinit>()v iconst_2 putstatic gcd/i I iconst_4 putstatic gcd/j I ; set limits used by this method.limit locals 0.limit stack 1 return.end method ; standard constructor initializer.method public <init>()v.limit stack 1.limit locals 1 aload_0 invokespecial java/lang/object/<init>()v return.end method.method gcd(ii)i L0:.var 0 is this Lgcd; from L0 to L1.var 1 is a I from L0 to L1 COMP3131/9102 Page 522 May 8, 2017
11 .var 2 is b I from L0 to L1 iload_2 iconst_0 if_icmpeq L5 iconst_0 goto L6 L5: iconst_1 L6: ifeq L3 iload_1 ireturn goto L4 L3: aload_0 iload_2 iload_1 iload_1 iload_2 idiv iload_2 imul isub invokevirtual gcd/gcd(ii)i ireturn L4: L1: nop ; set limits used by this method.limit locals 3.limit stack 5.end method.method public static main([ljava/lang/string;)v L0:.var 0 is argv [Ljava/lang/String; from L0 to L1.var 1 is vc$ Lgcd; from L0 to L1 new gcd dup COMP3131/9102 Page 523 May 8, 2017
12 L1: invokenonvirtual gcd/<init>()v astore_1 aload_1 getstatic gcd/i I getstatic gcd/j I invokevirtual gcd/gcd(ii)i invokestatic VC/lang/System/putIntLn(I)V ; The following return inserted by the VC compiler return ; set limits used by this method.limit locals 2.limit stack 3.end method COMP3131/9102 Page 524 May 8, 2017
13 The Translation of the gcd Method by the Java Compiler.method gcd(ii)i // more optimised!.limit stack 5.limit locals 3.var 0 is this Lgcd; from Label1 to Label2.var 1 is arg0 I from Label1 to Label2.var 2 is arg1 I from Label1 to Label2 Label1:.line 10 iload_2 ifne Label0.line 11 iload_1 ireturn Label0:.line 13 aload_0 iload_2 iload_1 iload_1 iload_2 idiv iload_2 imul isub invokevirtual gcd/gcd(ii)i Label2: ireturn.end method COMP3131/9102 Page 525 May 8, 2017
14 Code Generator as a Visitor Object Visitor (as an Object): implementing VC.ASTs.visitor Syntax-driven: traversing the AST to emit code in pre-, inor post-order or any of their combinations Classes: Emitter.java: the visitor class for generating code JVM.java: The class defining the simple JVM used Instruction.java: The class defining Jasmin instructions Frame.java: The class for info about labels, local variable indices, etc. for a function COMP3131/9102 Page 526 May 8, 2017
15 Code Template [[X]]: the code generated for construct X Code template: a specification of [[X]] in terms of the codes for its syntactic components A code template specifies the translation of a construct independently of the context in which it is used Compiled code always executes in some context Optimisation is the art of captalising on context! Lack of context fully general (i.e., slow) code Thus, inefficient code may be generated; it can be optimised later by the compiler backend COMP3131/9102 Page 527 May 8, 2017
16 Expressions 1. Literals 2. Variables (lvalues and rvalues) 3. Arithmetic expressions 4. Boolean expressions 5. Relational expressions 6. Assignment expressions 7. Call expressions (assignment spec) COMP3131/9102 Page 528 May 8, 2017
17 Integer Literals CodeTemplate: [[IntLiteral]]: emiticonst(intliteral.value) private void emiticonst(int value) { if (value == -1) emit(jvm.iconst_m1); else if (value >= 0 && value <= 5) emit(jvm.iconst + "_" + value); else if (value >= -128 && value <= 127) emit(jvm.bipush, value); else if (value >= && value <= 32767) emit(jvm.sipush, value); else emit(jvm.ldc, value); } Visitor method: public Object visitintliteral(intliteral ast, Object o) { Frame frame = (Frame) o; emiticonst(integer.parseint(ast.spelling));... return null; } COMP3131/9102 Page 529 May 8, 2017
18 Floating-Point Literals CodeTemplate: [[F loatliteral]]: emitfconst(floatliteral.value) private void emitfconst(float value) { if(value == 0.0) emit(jvm.fconst_0); else if(value == 1.0) emit(jvm.fconst_1); else if(value == 2.0) emit(jvm.fconst_2); else emit(jvm.ldc, value); } Visitor method: public Object visitfloatliteral(floatliteral ast, Object o) { Frame frame = (Frame) o; emitfconst(float.parsefloat(ast.spelling));... return null; } COMP3131/9102 Page 530 May 8, 2017
19 Boolean Literals CodeTemplate: [[BooleanLiteral]]: emitbconst(booleanliteral.value) private void emitfconst(boolean value) { if (value) emit(jvm.iconst_1); else emit(jvm.iconst_0); } Visitor method: public Object visitbooleanliteral(booleanliteral ast, Object o) { Frame frame = (Frame) o; emitbconst(ast.spelling.equals("true"));... return null; } COMP3131/9102 Page 531 May 8, 2017
20 Code template: Visitor Method: Arithmetic Expression E 1 i+ E 2 [[E 1 i+ E 2 ]]: [[E 1 ]] [[E 2 ]] emit( iadd ) public Object visitbinaryexpr(binaryexpr ast, Object o) { Frame frame = (Frame) o; String op = ast.o.spelling; ast.e1.visit(this, o); ast.e2.visit(this, o);... else if (op.equals("i+")) { emit(jvm.iadd);... }... Other arithmetic operators (integral or real) handled similarly COMP3131/9102 Page 532 May 8, 2017
21 AST: Example 1: ( ) The nodes visited in post-order per code template Code: iconst_1 bipush 100 iadd sipush 200 ldc iadd iadd COMP3131/9102 Page 533 May 8, 2017
22 visitfuncdecl: Frame Objects A new frame object created each time visitfuncdecl is called public Object visitfuncdecl(funcdecl ast, Object o) {... frame = new Frame(true) for main or new Frame(false) otherwise... The frame object passed as the 2nd arg and available at all child nodes The constructor of the class Frame: public Frame(boolean _main) { this._main = _main; label = 0; localvarindex = 0; currentstacksize = 0; maximumstacksize = 0; constack = new Stack<String>(); brkstack = new Stack<String>(); scopestart = new Stack<String>(); scopeend = new Stack<String>(); } Code will be provided COMP3131/9102 Page 534 May 8, 2017
23 L1: L2: Boolean (or Logical) Expressions: E 1 &&E 2 [[E 1 ]] ifeq L1 [[E 2 ]] ifeq L1 iconst 1 goto L2 iconst 0 public Object visitbinaryexpr(binaryexpr ast, Object o){ Frame frame = (Frame) o;... L1 = frame.getnewlabel(); L2 = frame.getnewlabel(); ast.e1.visit(this, o); emit(jvm.ifeq, L1); ast.e2.visit(this, o); emit(jvm.ifeq, L1); emit(jvm.iconst 1); emit(jvm.goto, L2); emit(l1 + : ); emit(jvm.iconst 0); emit(l2 + : );... Code must respect the short circuit evaluation rule and!dealt with similarly Better codes can be generated (Week 11 Tutorial) COMP3131/9102 Page 535 May 8, 2017
24 Example 2: Boolean Expressions: true && false iconst 1 ifeq L2 iconst 0 ifeq L2 iconst 1 goto L3 label=0 frame.getnewlabel called twice L2: iconst 0 L3: label=2 The Frame object created for main Passed to all the children of the main s FuncDecl node COMP3131/9102 Page 536 May 8, 2017
25 Example: Testing and Marking Short-Circuit Evaluation boolean f() { putbool(false); return false; } void main() { false && f(); } Wrong if false is printed! COMP3131/9102 Page 537 May 8, 2017
26 Code Template: Relational Expressions: E 1 i> E 2 L1: L2: [[E 1 ]] [[E 2 ]] if icmpgt L1 iconst 0 goto L2 iconst 1 Other relational operations on integer operands handled similarly COMP3131/9102 Page 538 May 8, 2017
27 AST: Example 3: Relational Expressions Code L0 and L1 generated in visitcompstmt L2: L3: iconst_1 iconst_2 iadd iconst_3 if_icmpgt L2 iconst_0 goto L3 iconst_1 COMP3131/9102 Page 539 May 8, 2017
28 Code Template: Relational Expressions: E 1 f> E 2 L1: L2: [[E 1 ]] [[E 2 ]] fcmpg ifgt L1 iconst 0 goto L2 iconst 1 if fcmpgt is non-existent and is simulated by fcmpg and ifgt Other floating-point relational operators handled similarly COMP3131/9102 Page 540 May 8, 2017
29 Assignment Expression: a = E Assumptions: (1) a is int (2) Its local variable index is 1 Code Template: [[E]] istore 1 The above code template breaks down for a = b = 1; iconst 1 dup istore 2 // the local var index for b is 2 istore 1 Need to know the context in which b = 1 is used when the node for b=1 is visited How? a parent link is added to every AST node ast.parent is not dup COMP3131/9102 Page 541 May 8, 2017
30 Code Template: Example: Assignment Expression: LHS = RHS [[LHS]] [[RHS]] appropriate store instruction VC: int[] a = new int[10]; // index 1 int i = 1; // index 2 int j = 2; // index 3 a[i + 1] = j + 10; Bytecode for a[i + 1] = j + 10: aload_1 iload_2 iconst_1 iadd iload_3 bipush 10 iadd iastore COMP3131/9102 Page 542 May 8, 2017
31 Statements 1. if 2. while for left for you to work it out 3. break and continue 4. return 5. expression statement 6. compound statement COMP3131/9102 Page 543 May 8, 2017
32 Code Template: if (E) S1 else S2 L1: L2: [[E]] ifeq L1 [[S1]] goto L2 [[S2]] Works even when either S1 or S2 or both are empty In the AST, if (E) S1 without the else is represented as IfStmt / \ E S1 EmptyStmt Those instructions in blue need not be generated. COMP3131/9102 Page 544 May 8, 2017
33 Code Template: L1: L2: while (E) S Push the continue label L1 to constack Push the break label L2 to brkstack [[E]] ifeq L2 [[S]] goto L1 Also works when S is empty Pop the continue label L1 from constack Pop the break label L2 from brkstack COMP3131/9102 Page 545 May 8, 2017
34 break and continue Code template for break: goto the label marking the inst following the while Code template for continue: goto the label marking the first inst of the while COMP3131/9102 Page 546 May 8, 2017
35 return E Assumption: type coercion has been done. Code Template: return E:int and return E:Boolean Code Template: return E:float [[E]] ireturn [[E]] freturn COMP3131/9102 Page 547 May 8, 2017
36 Code Template: Examples: Expression Statement: E; [[E]] pop if it has a value left on the stack 1; ---> pop 1 + 2; ---> pop f(1,2) ---> pop if the return type is not void a = 1; ---> no pop ; ---> no pop COMP3131/9102 Page 548 May 8, 2017
37 Code template: Compound Statememts Push the label marking the beginning of scope to scopestart Push the label marking the end of scope to scopeend... [[DL]] // no code; [[SL]] Pop the scopestart label Pop the scopeend label Code will be provided COMP3131/9102 Page 549 May 8, 2017
38 Global Variable Declarations Provided for you (but only for scalar variables) Generate.field declarations Geneate the class initialiser<clinit> You need to add the initialisations for arrays All initialisers for global variables are assumed to be constant expressions as in C, although this was not checked in Assignment 4. COMP3131/9102 Page 550 May 8, 2017
39 Local Variable Declarations Instance field index available in VC.ASTs.Decl.java Call frame.getnewindex() to allocate indices consecutively for formal parameters and local variables: For a function (treated as an instance method), 0 is allocated to this For main (a static method), 0 is allocated argv and 1 to the implicitly declared variable vc$ COMP3131/9102 Page 551 May 8, 2017
40 lvalues (store) v.s rvalues (load) Let visitsimplevar do nothing (because we do not know by looking at this node whether the variable is a lvalue or rvalue) Generate an appropriate load or store in visitassignexpr Consider l = r (store for l and load for r): COMP3131/9102 Page 552 May 8, 2017
41 Generating Jasmin Directives.limit locals.limit stack.var.line COMP3131/9102 Page 553 May 8, 2017
42 .limit locals XXX Generated at the end of processing a function XXX is the current value of frame.getnewindex() COMP3131/9102 Page 554 May 8, 2017
43 Syntax:.var.var var-index is name type-desc scopestart-label scopeend-label Generated when a var or formal para decl is processed var-index, name and type are extracted from the Decl node The scopestart and scopeend labels from scopestart and scopeend stacks (Slide 549) COMP3131/9102 Page 555 May 8, 2017
44 .line XXX Source line where the instructions between this.line and the next are translated from Optional (you should leave it at the very end) Maintain a current line Generate a.line if the next construct is from a different line COMP3131/9102 Page 556 May 8, 2017
45 .limit stack XXX XXX is the maximum depth of the operand stack Calculating the value by simulating the execution of the byte code generated incrementally Example: iconst_1 iconst_2 iadd iconst_1 iconst_2 iconst_3 iadd iadd astore_1... frame.push() frame.push() frame.pop() frame.push() frame.push() frame.push() frame.pop() frame.pop() frame.pop() COMP3131/9102 Page 557 May 8, 2017
46 Some Language Issues Java byte code requires that all variables be initialised all method be terminated by a return Both are not enforced in the VC language All test cases used for marking Assignment 5 will satisfy the 1st restriction, You can satisfy the 2nd restriction by either having approprite returns in your test programs or optionally forcing your VC compiler to always generate an appropriate return for each function COMP3131/9102 Page 558 May 8, 2017
47 Reading Chapter 7 of the on-line JVM Spec (compiling Java) 8.4 (Red Dragon) or of Purple Dragon (for short-circuit evaluations) Assignment 5 spec Next/Last class: Chris s lecture COMP3131/9102 Page 559 May 8, 2017
COMP3131/9102: Programming Languages and Compilers
COMP3131/9102: Programming Languages and Compilers Jingling Xue School of Computer Science and Engineering The University of New South Wales Sydney, NSW 2052, Australia http://www.cse.unsw.edu.au/~cs3131
More informationCSC 4181 Handout : JVM
CSC 4181 Handout : JVM Note: This handout provides you with the basic information about JVM. Although we tried to be accurate about the description, there may be errors. Feel free to check your compiler
More informationCompiler construction 2009
Compiler construction 2009 Lecture 2 Code generation 1: Generating Jasmin code JVM and Java bytecode Jasmin Naive code generation The Java Virtual Machine Data types Primitive types, including integer
More informationJVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format
Course Overview What This Topic is About PART I: overview material 1 Introduction 2 Language processors (tombstone diagrams, bootstrapping) 3 Architecture of a compiler PART II: inside a compiler 4 Syntax
More informationTutorial 3: Code Generation
S C I E N C E P A S S I O N T E C H N O L O G Y Tutorial 3: Code Generation Univ.-Prof. Dr. Franz Wotawa, DI Roxane Koitz, Stephan Frühwirt, Christopher Liebmann, Martin Zimmermann Institute for Software
More informationOver-view. CSc Java programs. Java programs. Logging on, and logging o. Slides by Michael Weeks Copyright Unix basics. javac.
Over-view CSc 3210 Slides by Michael Weeks Copyright 2015 Unix basics javac java.j files javap 1 2 jasmin converting from javap to jasmin classfile structure calling methods adding line numbers Java programs
More informationCOMP 520 Fall 2013 Code generation (1) Code generation
COMP 520 Fall 2013 Code generation (1) Code generation COMP 520 Fall 2013 Code generation (2) The code generation phase has several sub-phases: computing resources such as stack layouts, offsets, labels,
More informationCompilation 2012 Code Generation
Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University Phases Computing resources, such as: layout of data structures offsets register allocation Generating an internal representation
More information02 B The Java Virtual Machine
02 B The Java Virtual Machine CS1102S: Data Structures and Algorithms Martin Henz January 22, 2010 Generated on Friday 22 nd January, 2010, 09:46 CS1102S: Data Structures and Algorithms 02 B The Java Virtual
More informationCode Generation Introduction
Code Generation Introduction i = 0 LF w h i l e i=0 while (i < 10) { a[i] = 7*i+3 i = i + 1 lexer i = 0 while ( i < 10 ) source code (e.g. Scala, Java,C) easy to write Compiler (scalac, gcc) parser type
More informationCourse Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion
Course Overview PART I: overview material 1 Introduction (today) 2 Language Processors (basic terminology, tombstone diagrams, bootstrapping) 3 The architecture of a Compiler PART II: inside a compiler
More informationCSE 431S Final Review. Washington University Spring 2013
CSE 431S Final Review Washington University Spring 2013 What You Should Know The six stages of a compiler and what each stage does. The input to and output of each compilation stage (especially the back-end).
More informationRecap: Printing Trees into Bytecodes
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 emits: code for e 1 that leaves result on the stack,
More informationPart VII : Code Generation
Part VII : Code Generation Code Generation Stack vs Register Machines JVM Instructions Code for arithmetic Expressions Code for variable access Indexed variables Code for assignments Items How to use items
More informationJVML Instruction Set. How to get more than 256 local variables! Method Calls. Example. Method Calls
CS6: Program and Data Representation University of Virginia Computer Science Spring 006 David Evans Lecture 8: Code Safety and Virtual Machines (Duke suicide picture by Gary McGraw) pushing constants JVML
More informationSOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE
1 SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ Java Programming Language Java Introduced in 1995 Object-oriented programming
More informationLet s make some Marc R. Hoffmann Eclipse Summit Europe
Let s make some Marc R. Hoffmann Eclipse Summit Europe 2012 24.10.2012 public class WhatIsFaster { int i; void inc1() { i = i + 1; } void inc2() { i += 1; } void inc3() { i++; } } Why? Compilers Scrip;ng
More informationCSE 431S Code Generation. Washington University Spring 2013
CSE 431S Code Generation Washington University Spring 2013 Code Generation Visitor The code generator does not execute the program represented by the AST It outputs code to execute the program Source to
More informationCompiling Techniques
Lecture 10: Introduction to 10 November 2015 Coursework: Block and Procedure Table of contents Introduction 1 Introduction Overview Java Virtual Machine Frames and Function Call 2 JVM Types and Mnemonics
More informationExercise 7 Bytecode Verification self-study exercise sheet
Concepts of ObjectOriented Programming AS 2018 Exercise 7 Bytecode Verification selfstudy exercise sheet NOTE: There will not be a regular exercise session on 9th of November, because you will take the
More informationThe Java Virtual Machine
Virtual Machines in Compilation Abstract Syntax Tree Compilation 2007 The compile Virtual Machine Code interpret compile Native Binary Code Michael I. Schwartzbach BRICS, University of Aarhus 2 Virtual
More informationCompiler 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 informationUnder the Hood: The Java Virtual Machine. Problem: Too Many Platforms! Compiling for Different Platforms. Compiling for Different Platforms
Compiling for Different Platforms Under the Hood: The Java Virtual Machine Program written in some high-level language (C, Fortran, ML, ) Compiled to intermediate form Optimized Code generated for various
More informationThe Structure of a Syntax-Directed Compiler
Source Program (Character Stream) Scanner Tokens Parser Abstract Syntax Tree Type Checker (AST) Decorated AST Translator Intermediate Representation Symbol Tables Optimizer (IR) IR Code Generator Target
More informationThe Java Virtual Machine. CSc 553. Principles of Compilation. 3 : The Java VM. Department of Computer Science University of Arizona
The Java Virtual Machine CSc 553 Principles of Compilation 3 : The Java VM Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg The Java VM has gone
More informationUnder the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008
Under the Hood: The Java Virtual Machine Lecture 23 CS2110 Fall 2008 Compiling for Different Platforms Program written in some high-level language (C, Fortran, ML,...) Compiled to intermediate form Optimized
More informationCOMP3131/9102: Programming Languages and Compilers
COMP3131/9102: Programming Languages and Compilers Jingling Xue School of Computer Science and Engineering The University of New South Wales Sydney, NSW 2052, Australia http://www.cse.unsw.edu.au/~cs3131
More informationJAM 16: The Instruction Set & Sample Programs
JAM 16: The Instruction Set & Sample Programs Copyright Peter M. Kogge CSE Dept. Univ. of Notre Dame Jan. 8, 1999, modified 4/4/01 Revised to 16 bits: Dec. 5, 2007 JAM 16: 1 Java Terms Java: A simple,
More informationTopics. Structured Computer Organization. Assembly language. IJVM instruction set. Mic-1 simulator programming
Topics Assembly language IJVM instruction set Mic-1 simulator programming http://www.ontko.com/mic1/ Available in 2 nd floor PC lab S/W found in directory C:\mic1 1 Structured Computer Organization 2 Block
More informationImproving Java Performance
Improving Java Performance #perfmatters Raimon Ràfols ...or the mumbo-jumbo behind the java compiler Agenda - Disclaimer - Who am I? - Our friend the java compiler - Language additions & things to consider
More informationThe Structure of a Syntax-Directed Compiler
Source Program (Character Stream) Scanner Tokens Parser Abstract Syntax Tree Type Checker (AST) Decorated AST Translator Intermediate Representation Symbol Tables Optimizer (IR) IR Code Generator Target
More informationCourse Overview. Levels of Programming Languages. Compilers and other translators. Tombstone Diagrams. Syntax Specification
Course Overview Levels of Programming Languages PART I: overview material 1 Introduction 2 Language processors (tombstone diagrams, bootstrapping) 3 Architecture of a compiler PART II: inse a compiler
More informationJava byte code verification
Java byte code verification SOS Master Science Informatique U. Rennes 1 Thomas Jensen SOS Java byte code verification 1 / 26 Java security architecture Java: programming applications with code from different
More informationSemantic actions for declarations and expressions
Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate
More informationSemantic actions for declarations and expressions. Monday, September 28, 15
Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate
More informationCMSC430 Spring 2014 Midterm 2 Solutions
CMSC430 Spring 2014 Midterm 2 Solutions 1. (12 pts) Syntax directed translation & type checking Consider the following grammar fragment for an expression for C--: exp CONST IDENT 1 IDENT 2 [ exp 1 ] Assume
More informationStatic Program Analysis
Static Program Analysis Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ws-1617/spa/ Recap: Taking Conditional Branches into Account Extending
More informationJoeq Analysis Framework. CS 243, Winter
Joeq Analysis Framework CS 243, Winter 2009-2010 Joeq Background Compiler backend for analyzing and optimizing Java bytecode Developed by John Whaley and others Implemented in Java Research project infrastructure:
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationBuilding 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 informationPlan for Today. Safe Programming Languages. What is a secure programming language?
cs2220: Engineering Software Class 19: Java Security Java Security Plan for Today Java Byte s () and Verification Fall 2010 UVa David Evans Reminder: Project Team Requests are due before midnight tomorrow
More informationCSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1
CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Winter 2008 3/11/2008 2002-08 Hal Perkins & UW CSE V-1 Agenda Java virtual machine architecture.class files Class loading Execution engines
More informationWhen do We Run a Compiler?
When do We Run a Compiler? Prior to execution This is standard. We compile a program once, then use it repeatedly. At the start of each execution We can incorporate values known at the start of the run
More informationSemantic actions for expressions
Semantic actions for expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate representations
More informationThe Structure of a Compiler
The Structure of a Compiler A compiler performs two major tasks: Analysis of the source program being compiled Synthesis of a target program Almost all modern compilers are syntax-directed: The compilation
More informationTranslating JVM Code to MIPS Code 1 / 43
Translating JVM Code to MIPS Code 1 / 43 Outline 1 Introduction 2 SPIM and the MIPS Architecture 3 Our Translator 2 / 43 Introduction Compilation is not necessarily done after the class file is constructed
More informationEXAMINATIONS 2008 MID-YEAR COMP431 COMPILERS. Instructions: Read each question carefully before attempting it.
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2008 MID-YEAR COMP431 COMPILERS Time Allowed: 3 Hours Instructions: Read each
More informationThe Java Virtual Machine
The Java Virtual Machine Norman Matloff and Thomas Fifield University of California at Davis c 2001-2007, N. Matloff December 11, 2006 Contents 1 Background Needed 3 2 Goal 3 3 Why Is It a Virtual Machine?
More informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationThe Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.
The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees
More informationjavac 29: pop 30: iconst_0 31: istore_3 32: jsr [label_51]
Analyzing Control Flow in Java Bytecode Jianjun Zhao Department of Computer Science and Engineering Fukuoka Institute of Technology 3-10-1 Wajiro-Higashi, Higashi-ku, Fukuoka 811-02, Japan zhao@cs.t.ac.jp
More informationCOMP 520 Fall 2009 Virtual machines (1) Virtual machines
COMP 520 Fall 2009 Virtual machines (1) Virtual machines COMP 520 Fall 2009 Virtual machines (2) Compilation and execution modes of Virtual machines: Abstract syntax trees Interpreter AOT-compile Virtual
More informationJoeQ Framework CS243, Winter 20156
Overview Java Intermediate representation JoeQ Framework CS243, Winter 20156 Bytecode JoeQ Framework Quads: Instruction set used in JoeQ JoeQ constructs Writing analysis in JoeQ HW 2 Typical Compiler Infrastructure
More informationCOMP3131/9102: Programming Languages and Compilers
COMP3131/9102: Programming Languages and Compilers Jingling Xue School of Computer Science and Engineering The University of New South Wales Sydney, NSW 2052, Australia http://www.cse.unsw.edu.au/~cs3131
More informationCode Generation COMP 520: Compiler Design (4 credits) Professor Laurie Hendren
COMP 520 Winter 2015 Code Generation (1) Code Generation COMP 520: Compiler Design (4 credits) Professor Laurie Hendren hendren@cs.mcgill.ca Maggie the Devourer (of Code) COMP 520 Winter 2015 Code Generation
More informationCOMP3131/9102: Programming Languages and Compilers
COMP3131/9102: Programming Languages and Compilers Jingling Xue School of Computer Science and Engineering The University of New South Wales Sydney, NSW 2052, Australia http://www.cse.unsw.edu.au/~cs3131
More informationProgramming Language Systems
Programming Language Systems Instructors: Taiichi Yuasa and Masahiro Yasugi Course Description (overview, purpose): The course provides an introduction to run-time mechanisms such as memory allocation,
More informationChapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats
Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Chapter 5 A Closer Look at Instruction Set Architectures Gain familiarity with memory addressing modes. Understand
More informationSpace Exploration EECS /25
1/25 Space Exploration EECS 4315 www.eecs.yorku.ca/course/4315/ Nondeterminism 2/25 Nondeterministic code is code that, even for the same input, can exhibit different behaviours on different runs, as opposed
More informationCSc 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 informationSemantic actions for declarations and expressions
Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate
More informationChapter 5. A Closer Look at Instruction Set Architectures
Chapter 5 A Closer Look at Instruction Set Architectures Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand
More informationCopyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16
1 Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16 Towards JVM Dynamic Languages Toolchain Insert Picture Here Attila
More informationCS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II
CS2110 Fall 2011 Lecture 25 Under the Hood: The Java Virtual Machine, Part II 1 Java program last time Java compiler Java bytecode (.class files) Compile for platform with JIT Interpret with JVM run native
More informationEXAMINATIONS 2014 TRIMESTER 1 SWEN 430. Compiler Engineering. This examination will be marked out of 180 marks.
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2014 TRIMESTER 1 SWEN 430 Compiler Engineering Time Allowed: THREE HOURS Instructions:
More informationCSc 620 Debugging, Profiling, Tracing, and Visualizing Programs. Compiling Java. The Java Class File Format 1 : JVM
Attributes Execute The Java Virtual Machine CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs 1 : JVM Christian Collberg collberg+620@gmail.com The Java VM has gone the many complex instructions/large
More informationWhat is software testing? Software testing is designing, executing and evaluating test cases in order to detect faults.
ϖοιδ τεσταδδανδχουντ() { ασσερ τεθυαλσ(1, ο.αδδανδχουντ(νεω ΑρραψΛιστ()); ϖοιδ τεσταδδανδχουντ() { ασσερ τεθυαλσ(1, ο.αδδανδχουντ(νεω ΑρραψΛιστ()); ιντ αδδανδχουντ(λιστ λιστ) { ρετυρν λιστ.σιζε(); ιντ
More informationCompiling expressions
E H U N I V E R S I T Y T O H F R G Compiling expressions E D I N B U Javier Esparza Computer Science School of Informatics The University of Edinburgh The goal 1 Construct a compiler for arithmetic expressions
More informationSemantic 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 informationCompilers. History of Compilers. A compiler allows programmers to ignore the machine-dependent details of programming.
Compilers Compilers are fundamental to modern computing. They act as translators, transforming human-oriented programming languages into computer-oriented machine languages. To most users, a compiler can
More informationAgenda. 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 information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationJava Class Loading and Bytecode Verification
Java Class Loading and Bytecode Verification Every object is a member of some class. The Class class: its members are the (definitions of) various classes that the JVM knows about. The classes can be dynamically
More informationThe 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 informationRun-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 informationSemantic Processing. Semantic Errors. Semantics - Part 1. Semantics - Part 1
Semantic Processing The Lexer and Parser Found lexical and syntax errors Built Abstract Syntax Tree Now!Find semantic errors.!build information about the program. Later!Generate IR Code!Optimize IR Code!Generate
More informationProgram Dynamic Analysis. Overview
Program Dynamic Analysis Overview Dynamic Analysis JVM & Java Bytecode [2] A Java bytecode engineering library: ASM [1] 2 1 What is dynamic analysis? [3] The investigation of the properties of a running
More information3/15/18. Overview. Program Dynamic Analysis. What is dynamic analysis? [3] Why dynamic analysis? Why dynamic analysis? [3]
Overview Program Dynamic Analysis Dynamic Analysis JVM & Java Bytecode [2] A Java bytecode engineering library: ASM [1] 2 What is dynamic analysis? [3] The investigation of the properties of a running
More informationMnemonics Type-Safe Bytecode Generation in Scala
Mnemonics Type-Safe Bytecode Generation in Scala Johannes Rudolph CleverSoft GmbH, Munich Peter Thiemann Albert-Ludwigs-Universität Freiburg, Germany Scala Days 2010, Lausanne, 15.04.2010 Existing bytecode
More informationA Tour of Language Implementation
1 CSCE 314: Programming Languages Dr. Flemming Andersen A Tour of Language Implementation Programming is no minor feat. Prometheus Brings Fire by Heinrich Friedrich Füger. Image source: https://en.wikipedia.org/wiki/prometheus
More informationChapter 6: Code Generation
Chapter 6: Code Generation Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Bridging the semantic gap between
More informationJava TM Introduction. Renaud Florquin Isabelle Leclercq. FloConsult SPRL.
Java TM Introduction Renaud Florquin Isabelle Leclercq FloConsult SPRL http://www.floconsult.be mailto:info@floconsult.be Java Technical Virtues Write once, run anywhere Get started quickly Write less
More informationImproving Java Code Performance. Make your Java/Dalvik VM happier
Improving Java Code Performance Make your Java/Dalvik VM happier Agenda - Who am I - Java vs optimizing compilers - Java & Dalvik - Examples - Do & dont's - Tooling Who am I? (Mobile) Software Engineering
More informationAn Introduction to Multicodes. Ben Stephenson Department of Computer Science University of Western Ontario
An Introduction to Multicodes Ben Stephenson Department of Computer Science University of Western Ontario ben@csd csd.uwo.ca Outline Java Virtual Machine Background The Current State of the Multicode Art
More informationVirtual Machines. COMP 520: Compiler Design (4 credits) Alexander Krolik MWF 9:30-10:30, TR
COMP 520 Winter 2018 Virtual Machines (1) Virtual Machines COMP 520: Compiler Design (4 credits) Alexander Krolik alexander.krolik@mail.mcgill.ca MWF 9:30-10:30, TR 1080 http://www.cs.mcgill.ca/~cs520/2018/
More informationCompilation 2012 The What and Why of Compilers
Compilation 2012 The What and Why of Compilers Jan Midtgaard Michael I. Schwartzbach Aarhus University What is a Compiler? A program that: tralates from one programming language to another preserves the
More informationCode Generation: Introduction
Code Generation: Introduction i = 0 LF w h i l e i=0 while (i < 10) { a[i] = 7*i+3 i = i + 1 } lexer i = 0 while ( i < 10 ) source code (e.g. Scala, Java,C) easy to write Compiler (scalac, gcc) parser
More informationLECTURE 18. Control Flow
LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a
More informationChapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats
Chapter 5 Objectives Chapter 5 A Closer Look at Instruction Set Architectures Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand
More informationChapter 5. A Closer Look at Instruction Set Architectures
Chapter 5 A Closer Look at Instruction Set Architectures Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand
More informationProgramming Language Concepts: Lecture 2
Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2011 PLC 2011, Lecture 2, 6 January 2011 Classes and
More informationAnatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?
Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages! JVM Dr. Hyunyoung Lee 1 Java Virtual Machine and Java The Java Virtual Machine (JVM) is a stack-based abstract computing machine. JVM was designed to support Java -- Some
More informationWhat 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
What is a compiler? What is a compiler? Traditionally: Program that analyzes and translates from a high level language (e.g., C++) to low-level assembly language that can be executed by hardware int a,
More informationJava: framework overview and in-the-small features
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer
More informationSEMANTIC ANALYSIS TYPES AND DECLARATIONS
SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether
More informationCS263: Runtime Systems Lecture: High-level language virtual machines. Part 1 of 2. Chandra Krintz UCSB Computer Science Department
CS263: Runtime Systems Lecture: High-level language virtual machines Part 1 of 2 Chandra Krintz UCSB Computer Science Department Portable, Mobile, OO Execution Model Execution model embodied by recent
More informationExploiting FPGA Concurrency to Enhance JVM Performance
Exploiting FPGA Concurrency to Enhance JVM Performance James Parnis Gareth Lee School of Computer Science & Software Engineering The University of Western Australia, 35 Stirling Highway, Crawley, W.A.
More informationCompiling for Different Platforms. Problem: Too Many Platforms! Dream: Platform Independence. Java Platform 5/3/2011
CS/ENGD 2110 Object-Oriented Programming and Data Structures Spring 2011 Thorsten Joachims Lecture 24: Java Virtual Machine Compiling for Different Platforms Program written in some high-level language
More informationLecture 7: Type Systems and Symbol Tables. CS 540 George Mason University
Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing
More information