Building a Java Interpreter CS 142 (b) 01/14. Lab Sessions Monday, Wednesday – 10am – noon – ICS 189 Send an email or make an appointment with the TA.

Slides:



Advertisements
Similar presentations
Methods and Formatted Output Chapter 4. Overview Breaking down a big program into small methods. Formatting output – using printf – using DecimalFormat.
Advertisements

Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Mohamed. M. Saad.  Java Virtual Machine Prototype based on Jikes RVM  Targets  Code profiling/visualization using execution flow  Utilize large number.
Mohamed M. Saad & Mohamed A. Mohamedin.  Static Execution Graph  Nodes; can be either ▪ Basic Blocks; a sequence of non-branching instructions ▪ Variables.
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.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.
CSCI 160 Midterm Review Rasanjalee DM.
CS 338 Project: Phase 4. Grammar Start  stmt eof Stmt  id = expr | if (expr) then stmt | while (expr) do stmt | begin CS end CS  stmt ; CS |   ote:
Computer Programming Lab 8.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
CS 153: Concepts of Compiler Design November 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Lab 9 Java Bytecode & The Jasmin Assembler
IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006.
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.
Compilation 2007 Optimization Michael I. Schwartzbach BRICS, University of Aarhus.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Milan Jovic University of Lugano November 30, 2006.
Code Generation Introduction. Compiler (scalac, gcc) Compiler (scalac, gcc) machine code (e.g. x86, arm, JVM) efficient to execute i=0 while (i < 10)
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
1 Intro to Computer Science I Chapter 1 Introduction to Computation Algorithms, Processors, and Programs.
CSCI 273: Processing An Introduction. Programming Languages –An abstract "human understandable" language for telling the computer what to do –The abstract.
Recursion Examples Fundamentals of CS Case 1: Code /* Recursion: Case 1 */ #include void count (int index); main () { count (0); getchar(); } void count.
The Java Virtual Machine 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Krakatoa: Decompilation in Java “Does Bytecode Reveal Source?” Todd A. Proebsting Scott A. Watterson The University of Arizona Presented by Karl von Randow.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
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.
Code Compiled with javac static int k = 0; static boolean action(int si, boolean ob, int sm, int pr) { if (sm + 2*pr > 10 && !(si
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
CSCI Processing CSCI Introduction to Algorithm Design An Introduction.
Code Optimization 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a.
Programming Languages
A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?
Code generation exercises. Function body Transform the following code into java bytecode: def middle(small: Int, big: Int): Int = { val mid = small +
#include "dump.h" int main ( int argc, char* argv[] ) { __asm { mov eax, 1// init eax to 1 mov ebx, esp; keep a copy of esp mov ecx, 3/* init ecx to 3.
Chap. 10, Intermediate Representations J. H. Wang Dec. 14, 2015.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 18: Code Safety and Virtual Machines
Chap. 10, Intermediate Representations J. H. Wang Dec. 27, 2011.
Code generation exercises. Function body Transform the following code into java bytecode: def middle(small: Int, big: Int): Int = { val mid = small +
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.
RealTimeSystems Lab Jong-Koo, Lim
CS 536 © CS 536 Spring Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 15.
CS 153: Concepts of Compiler Design November 9 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS216: Program and Data Representation
Java Virtual Machine (JVM)
Java Byte Codes (0xCAFEBABE) cs205: engineering software
March 29th Odds & Ends CS 239.
CSC 113: Computer programming II
Introduction to Algorithm Design
Lecture 19: 0xCAFEBABE (Java Byte Codes) CS201j: Engineering Software
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
Byte Code Verification
Course Overview PART I: overview material PART II: inside a compiler
Java Lesson 36 Mr. Kalmes.
Java Decompiler.
CS 153: Concepts of Compiler Design November 6 Class Meeting
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
CS 432: Compiler Construction Lecture 16
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Building a Java Interpreter
CMPE 152: Compiler Design April 16 Class Meeting
CMPE 152: Compiler Design April 18 Class Meeting
Presentation transcript:

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

Java Interpreter Input: a bytecode instruction stream Output: a native-code instruction stream In our project: – Translate each bytecode instruction to C++ code

Instructions We Are Interested in iconst, iload and istore iadd if_icmpne, if_icmpeq, if_icmpgt, if_icmplt, ifeq, ifne, ifgt, iflt goto invokestatic return

Building an Interpreter void interpret(InstructionSeq is){ for (Instruction i = is.first(); i != null; i = next) { int opCode = i.getOpCode(); next = is.nextInstruction(i); switch(opCode){ case iload: int index = i.getOperand(); int value = values.get(index); push(value); break; case istore: int index = i.getOperand(); int value = pop(); values.set(index, value); break; }

Building an Interpreter (Cond.) for(Instruction i = is.first(); i != null; i = next){ int opCode = i.getOpCode(); next = is.nextInstruction(i); switch(opCode){ case iadd: int value1 = pop(); int value2 = pop(); push(value1 + value2); break; case if_icmpeq: int value1 = pop(); int value2 = pop(); int target = i.getOperand(); if(value1 == value2) next = is.getInstruction(target); break; case goto: int target = i.getOperand(); next = is.getInstruction(target); break; }

Building an Interpreter (Cond.) void interpret(InstructionSeq is){ for(Instruction i = is.first(); i != null; i = next){ … case invokestatic: String mName = ((CallInsruction) i). getTarget(); InstructionSet newSet = findInstructionSetforMethod(mName); invoke(newSet); break; }

Handling of println If the target of a static method is System.out.println, just call C++ function printf on the parameter string