COMP3131/9102: Programming Languages and Compilers

Size: px
Start display at page:

Download "COMP3131/9102: Programming Languages and Compilers"

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 464 May 6, 2018

2 Lecture 9: JVM 1. Our code generation 2. JVM: Data types Operand stack Local variable array (indices) Instructions ( Jasmin instructions) Parameter-passing ( Jasmin method invocations) COMP3131/9102 Page 465 May 6, 2018

3 void whileint() { int i = 0; while (i < 100) { i++; An Example is compiled to Method void whileint() 0 iconst_0 1 istore_1 // i s index is 1 2 goto 8 5 iinc 1 1 // i++ 8 iload_1 9 bipush if_icmplt 5 14 return COMP3131/9102 Page 466 May 6, 2018

4 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 467 May 6, 2018

5 /* * System.java */ Standard Environment: Built-in Functions package VC.lang; import java.io.*; import java.util.stringtokenizer; public class System { private static BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in)); public final static int getint() { try { java.lang.system.out.print("enter an integer: "); String s = reader.readline(); StringTokenizer st = new StringTokenizer(s); int i = Integer.parseInt(st.nextToken()); java.lang.system.out.println("you have entered " + i + "."); return i; catch (java.io.ioexception e) { java.lang.system.out.println("caught IOException: " + e.getmessage()); java.lang.system.exit(1); return -1; public final static void putbool(boolean b) { java.lang.system.out.print(b); COMP3131/9102 Page 468 May 6, 2018

6 public final static void putboolln(boolean b) { java.lang.system.out.println(b); public final static void putint(int i) { java.lang.system.out.print(i); public final static void putintln(int i) { java.lang.system.out.println(i); public final static float getfloat() { try { java.lang.system.out.print("enter a float: "); String s = reader.readline(); StringTokenizer st = new StringTokenizer(s); float f = Float.parseFloat(st.nextToken()); java.lang.system.out.println("you have entered " + f + "."); return f; catch (java.io.ioexception e) { java.lang.system.out.println("caught IOException: " + e.getmessage()); java.lang.system.exit(1); return -1.0F; public final static void putfloat(float f) { java.lang.system.out.print(f); public final static void putfloatln(float f) { java.lang.system.out.println(f); COMP3131/9102 Page 469 May 6, 2018

7 public final static void putstring(string s) { java.lang.system.out.print(s); public final static void putstringln(string s) { java.lang.system.out.println(s); public final static void putln() { java.lang.system.out.println(); COMP3131/9102 Page 470 May 6, 2018

8 References Jasmin home page: Tim Lindholm and Frank Yellin, The Java Virtual Machine Specification, 2nd Edition, Addison-Wesley, (The entire book is available on-line; see the subject Resource Page.) Vill Venners, Inside the Java 2 Virtual Machine, 2nd Edition, McGraw-Hill, (Some chapters available on-line; see the subject Resource Page.) COMP3131/9102 Page 471 May 6, 2018

9 Jasmin Assembly Language Sun has not defined an assembler format Jasmin is a Java assembler, which has been installed in the class account and can be invoked as follows: % 3131 % jasmin gcd.j --> the output is gcd.class % java gcd Install fromhttp://jasmin.sourceforge.net/ on your own computer Read also the Jasmin User Guide there: Jasmin page contains pointers to other assembly languages COMP3131/9102 Page 472 May 6, 2018

10 Jasmin Assembly Language v.s Java Byte Code 1-to-1 correspondence Operation codes (opcodes) represented by mnemonics Name indices written in symbolic form Local variables are encoded by indices (integers) Examples: Jasmin Instructions Java Byte Code iload 0x60 bipush 20 0x1614 getstatic Test.i 0xb2???? where???? is an index into the constant pool entry for Test.i Constant pool will be discussed in Lecture 11 but its understanding unnecessary for Assignment 5 COMP3131/9102 Page 473 May 6, 2018

11 gcd.java // find the greatest common divisor of two integers public class gcd { static int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a - (a/b) *b); public static void main(string argv[]) { int i = 2; int j = 4; System.out.println(gcd(i, j)); COMP3131/9102 Page 474 May 6, 2018

12 ;; Produced by JasminVisitor (BCEL) ;; gcd.java.class public gcd.super java/lang/object gcd.j.method public <init>()v.limit stack 1.limit locals 1.var 0 is this Lgcd; from Label0 to Label1 Label0:.line 3 Label1:.end method aload_0 invokespecial java/lang/object/<init>()v return.method static gcd(ii)i.limit stack 4.limit locals 2.var 0 is a I from Label1 to Label2.var 1 is b I from Label1 to Label2 Label1:.line 5.line 6 iload_1 ifne Label0 iload_0 COMP3131/9102 Page 475 May 6, 2018

13 Label0:.line 8 Label2:.end method ireturn iload_1 iload_0 iload_0 iload_1 idiv iload_1 imul isub invokestatic gcd/gcd(ii)i ireturn.method public static main([ljava/lang/string;)v.limit stack 3.limit locals 3.var 0 is argv [Ljava/lang/String; from Label0 to Label1.var 1 is i I from Label2 to Label1.var 2 is j I from Label4 to Label1 Label0:.line 12 iconst_2 istore_1 Label2:.line 13 iconst_4 istore_2 Label4:.line 14 getstatic java.lang.system.out Ljava/io/PrintStream; COMP3131/9102 Page 476 May 6, 2018

14 iload_1 iload_2 invokestatic gcd/gcd(ii)i invokevirtual java/io/printstream/println(i)v Label1:.line 15 return.end method COMP3131/9102 Page 477 May 6, 2018

15 Java Class File: gcd.class (Output of od -An -tx1 gcd.class) ca fe ba be d 00 1e 0a a a b c 69 6e e f f 4c 69 6e 65 4e 75 6d c d e b 4c 6a f 6c 61 6e 67 2f e 67 3b a 53 6f c e 6a c c 00 0b 00 0c c a b 0c 00 1c 00 1d a f 6c 61 6e 67 2f 4f 62 6a a f 6c 61 6e 67 2f d f c 6a f 69 6f 2f e d 3b a f 69 6f 2f e d e 74 6c 6e d a b b a b 00 0c b 9a a ac 1b 1a 1a 1b 6c 1b b ac a e d 00 0e c 07 3d b b 1c b b b a c d e 00 0f 00 0f f COMP3131/9102 Page 478 May 6, 2018

16 BCEL (Byte Code Engineering Library) Home page: Formerly known as JavaClass BCEL comes with a Jasmin disassembler, which has been installed in the class account and can be invoked as follows: % 3131 % jasmind gcd.class --> this produces gcd.j jasmind is a shell command: #!/bin/csh # # jasmind - runs the Jasmin disassembler # # Usage: # jasmind classname.class # setenv CLASSPATH ~cs3131/javatools/javaclass exec java JasminVisitor $* Install from the BCEL home page on your own computer. COMP3131/9102 Page 479 May 6, 2018

17 Multi-Level Machine Model VC Jasmin JVM Java C There is a virtual machine and a language at each level Each level builds on the functionality of the level below and provides the functionality to the level above COMP3131/9102 Page 480 May 6, 2018

18 Lecture 9: JVM 1. Our code generation 2. JVM: Data types Operand stack Local variable array (indices) Instructions ( Jasmin instructions) Parameter-passing ( Jasmin method invocations) COMP3131/9102 Page 481 May 6, 2018

19 JVM Data Types TYPE RANGE FIELD DESC boolean {0, 1 Z byte 8 bit signed 2 s complement ( 2 7 to 2 7 1) B short 16 bit signed 2 s complement ( 2 15 to2 15 1) S int 32 bit signed 2 s complement ( 2 31 to2 31 1) I long 64 bit signed 2 s complement ( 2 63 to2 63 1) L char 16 bit unsigned Unicode (0 to ) C float 32-bit IEEE 754 single-precision F double 64-bit IEEE 754 double-precision D reference 32 bit unsigned reference (0 to2 32 1) Slide 483 returnaddress 32 bit unsigned reference (0 to2 32 1) N/A All (except returnaddress) mapped 1-to-1 to Java s primitive types returnaddress used with jsr/jsr w/ret for handling exceptions boolean, byte, char and short are all implemented as int, but arrays of these types may be stored in arrays of less than 32 bits COMP3131/9102 Page 482 May 6, 2018

20 JVM Data Types (Cont d) TYPE FIELD DESCRIPTOR class reference Lclass-name; interface reference Linterface-name; array reference [[ [ component-type void V class and interface names are qualified names with. replaced by / The no. of[is equal to the no. of dimensions of the array Type Field Descriptor Object Ljava/lang/Object; String Ljava/lang/String; String[] [Ljava/lang/String; int [] [I float [][] [[F See $4.3.2, The JVM Spec for a formal definition COMP3131/9102 Page 483 May 6, 2018

21 Boolean, Byte, Short and Char Represented as Int public class IntTypes { public static void main(string argv[]) { boolean z = true; byte b = 1; short s = 2; char c = a ;.method public static main([ljava/lang/string;)v....line 3.line 4.line 5.line 6 Label0:.line 8 iconst_1 istore_1 iconst_1 istore_2 iconst_2 istore_3 bipush 97 istore 4 return.end method COMP3131/9102 Page 484 May 6, 2018

22 An Example for Printing Data Type Descriptors public class Desc { public static void main(string argv[]) { Object o = new Object(); int [] i = new int[10]; float [][] f = new float[10][10]; String s1 = "Hello World!"; String [] s2 = { "Hello", "World!"; System.out.println("Th class name of Object is: " + o.getclass()); System.out.println("Th class name of int[] is: " + i.getclass()); System.out.println("Th class name of float[][] is: " + f.getclass()); System.out.println("Th class name of String: " + s1.getclass()); System.out.println("Th class name of String[]: " + s2.getclass()); COMP3131/9102 Page 485 May 6, 2018

23 Method Descriptors (ParameterType ) ReturnType Examples: Method Declaration Method Descriptor int gcd(int i, int j) (II)I void main(string argv[]) ([Ljava/lang/String;)V char foo(float f, String) (FLjava/lang/String;)C See $4.3.3, The JVM Spec for a formal definition COMP3131/9102 Page 486 May 6, 2018

24 Operand Stack Accessed by pushing and popping values storing operands and receiving the operations results passing arguments and receiving method results This unified view is one of the main reasons why code generation for stack-based machines is easier than registers-based machines A new op stack is created every time a method is called Integral expression: * Jasmin code (without being optimised): iconst_1 iconst_2 iconst_3 imul iadd iconst_4 iadd COMP3131/9102 Page 487 May 6, 2018

25 Local Variable Array 1. A new local variable array is created each time a method is called 2. Local variables addressed by indexing, starting from 0 3. Instance methods: slot 0 given to this Parameters (if any) given consecutive indices, starting from 1 The indices allocated to the other variables in any order 4. Class methods: Parameters (if any) given consecutive indices, starting from 0 The indices allocated to the other variables in any order 5. One slot can hold a value of boolean, byte, char, short, int, float, reference and returnadrress 6. One pair of slots can hold a value of long and double COMP3131/9102 Page 488 May 6, 2018

26 Local Variable Indices: Class Methods 1. Class method: public static void foo() { int i1 = 1; // index 0 int i2 = 2; // index 1 int i3 = 3; // index 2 int i = i1 + i2 * i3; // index 3 2. Jasmin code: iconst_1 istore_0 iconst_2 istore_1 iconst_3 istore_2 iload_0 iload_1 iload_2 imul iadd istore_3 COMP3131/9102 Page 489 May 6, 2018

27 Local Variable Indices: Instance Methods 1. Instance method: public void foo() { // "this" given index 0 int i1 = 1; // index 1 int i2 = 2; // index 2 int i3 = 3; // index 3 int i = i1 + i2 * i3; // index 4 2. Jasmin code: iconst_1 istore_1 iconst_2 istore_2 iconst_3 istore_3 iload_1 iload_2 iload_3 imul iadd istore_4 COMP3131/9102 Page 490 May 6, 2018

28 Local Variable Indices: Double Word variables 1. The Long type: public static void foo() { int i1 = 1; // index 0 long i2 = 2; // indices 1 and 2 int i3 = 3; // index 3 long i = i1 + i2 * i3; // indices 4 and 5 2. Jasmin code: iconst_1 istore_0 ldc2_w 2 lstore_1 iconst_3 istore_3 iload_0 i2l lload_1 iload_3 i2l lmul ladd lstore 4 3. Accessing index 2 or 5 is disallowed COMP3131/9102 Page 491 May 6, 2018

29 Lecture 9: JVM 1. Our code generation 2. JVM: Data types Operand stack Local variable array (indices) Instructions ( Jasmin instructions) Parameter-passing ( Jasmin method invocations) COMP3131/9102 Page 492 May 6, 2018

30 Jasmin (or JVM) Instructions 1. Arithmetic Instructions 2. Load and store instructions 3. Control transfer instructions 4. Type conversion instructions 5. Operand stack management instructions 6. Object creation and manipulation 7. Method invocation instructions 8. Throwing instructions (not used) 9. Implementing finally (not used) 10. Synchronisation (not used) COMP3131/9102 Page 493 May 6, 2018

31 Arithmetic Instructions ($3.11.3, JVM Spec) add: iadd, fadd, subtract: isub, fsub multiply: imul, fmul divide: idiv, fdiv negative: ineg, fneg comparison: fcmpg, fcmpl... COMP3131/9102 Page 494 May 6, 2018

32 Load and Store Instructions Loading a local variable into the operand stack: iload iload_0,..., iload_3 fload fload_0,..., fload_3 aload aload_0,..., aload_3 // for array and object refs iaload // load from an int array faload // load from a float array Storing a value from the operand stack into a local variable: istore istore_0,..., istore_3 fstore fstore_0,..., fstore_3 astore astore_0,..., astore_3 // for array and object refs iastore // store into an int array fastore // store into a float array Load a constant into the operand stack: bipush, sipush, ldc, iconst_m1, iconst_0,..., iconst_5, fconst_0,..., fconst_2 COMP3131/9102 Page 495 May 6, 2018

33 Example: Load and Stored (Slide 487 Repeated) 1. Integral expression: * Jasmin code: iconst_1 iconst_2 iconst_3 imul iadd iconst_4 iadd COMP3131/9102 Page 496 May 6, 2018

34 Example: Load and Store (Cont d) 1. Integral expression: * Jasmin code: iconst_1 bipush 100 sipush 200 imul iadd ldc iadd 3. bipush: sipush: ldc val, where val is an int, float or string COMP3131/9102 Page 497 May 6, 2018

35 Example: Load and Store (Cont d) 1. Floating-point expression: 1.0F + 2.0F * 3.0F + 4.0F 2. Jasmin code: fconst_1 fconst_2 ldc 3.0 fmul fadd ldc 4.0 fadd COMP3131/9102 Page 498 May 6, 2018

36 1. Array operations: Example: Load and Store for Arrays a[0] = 100; i = a[0] 2. Jasmin code (assuming a and i have the indices 1 and 2, resp.) // a[0] = 100; aload_1 iconst_0 bipush 100 iastore // i = a[0]; aload_1 iconst_0 iaload istore_2 COMP3131/9102 Page 499 May 6, 2018

37 1. Unconditional: goto 2. Instructions on int: Control Transfer Instructions ifeq ifne ifle iflt ifne ifge if_icmpeq if_icmpne if_icmple if_icmplt if_icmpge if_icmpgt 3. For floating-point operands, use first fcmpg or fcmpl and then ifeq ifne ifle iflt ifne ifge COMP3131/9102 Page 500 May 6, 2018

38 op stack (before) value1 value op stack (after) if icmge label 1. Pop off the two ints off and compare them 2. If value1 >= value2, jump to label. Otherwise, execution continues at the next instruction Other if icmpxx instructions are similar. COMP3131/9102 Page 501 May 6, 2018

39 1. Ctrl1.java Example 1: Control Transfer Instructions public class Ctrl1 { public static void main(string argv[]) { int i = 1, int j = 2, int k; if (i < j) k = 0; else k = 1; 2. Ctrl1.j (irrelevant lines removed).method public static main([ljava/lang/string;)v iconst_1 istore_1 iconst_2 istore_2 iload_1 iload_2 if_icmpge Label0 iconst_0 istore_3 goto Label1 Label0: iconst_1 istore_3 Label1: return.end method COMP3131/9102 Page 502 May 6, 2018

40 1. Ctrl2.java Example 2: Control Transfer Instructions public class Ctrl1 { public static void main(string argv[]) { float i = 1, float j = 2, float k; if (i < j) k = 0.0F; else k = 1.0F; 2. Ctrl2.j (irrelevant lines removed).method public static main([ljava/lang/string;)v fconst_1 fstore_1 fconst_2 fstore_2 fload_1 fload_2 fcmpg ifge Label0 fconst_0 fstore_3 goto Label1 Label0: fconst_1 fstore_3 Label1: return.end method COMP3131/9102 Page 503 May 6, 2018

41 fcmpg and fcmpl op stack (before): value1 value op stack (after): value1 = value2 value1 < value2 value1 > value2 If either is NaN, fcmpg pushes 1 and fcmpl pushes -1. See JVM SPEC $7.5 for an explanation why the two instructions are provided ( javase/specs/jvms/se7/html/jvms-3.html# jvms-3.5) COMP3131/9102 Page 504 May 6, 2018

42 1. Source: 2. Jasmin code: Type Conversion Instructions int i = 1; // index 1 float f = i; // index 2 iconst_1 istore_1 iload_1 i2f fstore 2 3. Only i2f is used in the VC compiler 4. i2c, i2b, f2i, etc. not used COMP3131/9102 Page 505 May 6, 2018

43 Operand Stack Management Instructions Instructions: dup: duplicate the stack top operand pop: remove the stack top operand swap: swap the top two operands others: pop2, dup2, etc. Only the first two will be used in the VC compiler: dup: for translating a = b =... pop: for translating expression statements such as 1; COMP3131/9102 Page 506 May 6, 2018

44 Example: dup in Translating Compound Assignments 1. Assignment expressions: 2. Jasmin code: int i; \\ index 1 int j; \\ index 2 int k; \\ index 3 i = j = k = 1; iconst_1 dup istore_3 dup istore_2 istore_1 COMP3131/9102 Page 507 May 6, 2018

45 Example: pop in Translating VC Expression Statements 1. Assignment expressions: 2. Jasmin code: int i; // index (i = 2); iconst_1 iconst_2 dup istore_1 iadd pop COMP3131/9102 Page 508 May 6, 2018

46 Object Creation and Manipulation Create a new class instance: new Access fields of classes: getstatic, putstatic, getfield, putfield Create a new array: newarray, anewarray, multianewarray (only the first is used) Load an array component onto the operand stack: iaload, faload, baload, caload,... Store a value from the operand stack as an array component: iastore, fastore, bastore, castore, COMP3131/9102 Page 509 May 6, 2018

47 Example: Object Creation and Manipulation Static and field variables: public class StaticField { static int i = 1; int j = 1; public static void main(string argv[]) { StaticField o = new StaticField(); System.out.println(i); System.out.println(o.j); Jasmin code (irrelevant lines removed).field static i I.field j I.method public static main([ljava/lang/string;)v.line 5 new StaticField dup invokespecial StaticField/<init>()V COMP3131/9102 Page 510 May 6, 2018

48 .line 6.line 7 Label0:.line 8 astore_1 return.end method getstatic java.lang.system.out Ljava/io/PrintStream; getstatic StaticField.i I invokevirtual java/io/printstream/println(i)v getstatic java.lang.system.out Ljava/io/PrintStream; aload_1 getfield StaticField.j I invokevirtual java/io/printstream/println(i)v COMP3131/9102 Page 511 May 6, 2018

49 Syntax: The Syntax for Field Instructions getstatic field-spec type-descriptor where field-spec consists of a classname followed by a field name. Examples: getstatic java/lang/system/out Ljava/io/PrintStream; getstatic StaticField/i I getfield and putfield not used in the VC compiler COMP3131/9102 Page 512 May 6, 2018

50 Arrays Java Statements // assuming a is at slot 1 (by compiler) int a[] = new int[10]; a[1] = a[2] + 1; Bytecode: bipush 10 newarray int astore_1 aload_1 iconst_1 aload_1 iconst_2 iaload iconst_1 iadd iastore COMP3131/9102 Page 513 May 6, 2018

51 Method calls: Method Invocation Instructions invokestatic invokevirtual invokespecial // also known as invokenonvirtual -- the instance initialisation method <init> -- a private method of "this" -- a method in a super class of "this" invokeinterface (why invokeinterface? stackoverflow.com/questions/ /what-is-the-point-of-invokeinterface) Method returns: return ireturn freturn... COMP3131/9102 Page 514 May 6, 2018

52 The Syntax for Method Invocation Instructions The syntax for invokestatic/virtual/special invokexx method-spec where method-spec consists of a classname, a method name and a descriptor. invokeinterface not used in the VC compiler COMP3131/9102 Page 515 May 6, 2018

53 invokestatic Method Invocation Instructions (Cont d) op stack after arg1 arg2... argn... result (if any) before invokevirtual and invokespecial op stack after objref arg1... argn... result (if any) before invokevirtual: on the dynamic type of objref invokespecial: based on the static class of objref Note that programmer-defined operators (methods) are treated exactly the same as the built-in operators (e.g., + and ) COMP3131/9102 Page 516 May 6, 2018

54 1. Met1.java: Example: Static Method Invocation public class Met1 { static int add(int i1, int i2) { return i1 + i2; public static void main(string argv[]) { add(1, 2); 2. Met1.j (irrelevant lines removed):.method static add(ii)i.limit stack 2.limit locals 2 iload_0 iload_1 iadd ireturn.end method.method public static main([ljava/lang/string;)v.limit stack 2.limit locals 1 iconst_1 iconst_2 invokestatic Met1/add(II)I pop return.end method COMP3131/9102 Page 517 May 6, 2018

55 1. Met2.java: Example 9: Instance Method Invocation public class Met2 { int add(int i1, int i2) { return i1 + i2; public static void main(string argv[]) { Met2 m = new Met2(); m.add(1, 2); 2. Met2.j (irrelevant lines removed):.method add(ii)i.limit stack 2.limit locals 3 iload_1 iload_2 iadd ireturn.end method.method public static main([ljava/lang/string;)v.limit stack 3.limit locals 2 new Met2 dup invokespecial Met2/<init>()V astore_1 aload_1 iconst_1 iconst_2 invokevirtual Met2/add(II)I return.end method COMP3131/9102 Page 518 May 6, 2018

56 Polymorphism: invokevirtual and invokespecial public class Fruit { public static void main(string argv[]) { Apple apple = new Apple(); Fruit fruit = apple; fruit.whoami(); void whoami() { System.out.println("This is a fruit."); class Apple extends Fruit { void whoami() { System.out.println("This is an apple."); super.whoami(); COMP3131/9102 Page 519 May 6, 2018

57 ;; Produced by JasminVisitor (BCEL package) ;; ;; Mon Oct 09 16:09:47 GMT+10: source Fruit.java.class public Fruit.super java/lang/object Fruit.j.method public <init>()v.limit stack 1.limit locals 1.var 0 is this LFruit; from Label0 to Label1 Label0:.line 1 Label1: aload_0 invokespecial java/lang/object/<init>()v return.end method.method public static main([ljava/lang/string;)v.limit stack 2.limit locals 3.var 0 is arg0 [Ljava/lang/String; from Label0 to Label1 Label0:.line 4.line 6 new Apple dup invokespecial Apple/<init>()V astore_1 aload_1 COMP3131/9102 Page 520 May 6, 2018

58 .line 7 Label1:.line 3 astore_2 aload_2 invokevirtual Fruit/whoAmI()V <=== a virtual call return.end method.method whoami()v.limit stack 2.limit locals 1.var 0 is this LFruit; from Label0 to Label1 Label0:.line 11 getstatic java.lang.system.out Ljava/io/PrintStream; ldc "This is a fruit." invokevirtual java/io/printstream/println(ljava/lang/string;)v Label1:.line 10 return.end method COMP3131/9102 Page 521 May 6, 2018

59 .source Fruit.java.class Apple.super Fruit.method <init>()v.limit stack 1.limit locals 1.var 0 is this LApple; from Label0 to Label1 Label0:.line 16 aload_0 invokespecial Fruit/<init>()V Label1: return.end method Apple.j.method whoami()v.limit stack 2.limit locals 1.var 0 is this LApple; from Label0 to Label1 Label0:.line 18 getstatic java.lang.system.out Ljava/io/PrintStream; ldc "This is an apple." invokevirtual java/io/printstream/println(ljava/lang/string;)v.line 19 Label1:.line 17 return.end method aload_0 invokespecial Fruit/whoAmI()V <=== a static call COMP3131/9102 Page 522 May 6, 2018

60 Jasmin Directives Jasmin home page.source.class.super.limit.method.field static.end.var.line Example: gcd.j (Slide 475) COMP3131/9102 Page 523 May 6, 2018

61 Jasmin File Structure (syntax.bnf) Jasmin Syntax Jonathan Meyer, April 1996 This file contains a simplified BNF version of the Jasmin syntax. jasmin_file ::=.class [ <access> ] <name> <break>.super <name> <break> [ <fields> ] [ <methods> ] <fields> ::= <field> [ <field>... ] <field> ::=.field <access> <name> <signature> [ = <default> ] <break> <default> ::= <int> <quoted_string> <float> <methods> ::= <method> [ <method>... ] COMP3131/9102 Page 524 May 6, 2018

62 <method> ::=.method <access> <name> <break> [ <statements> ].end method <break> <statements> ::= <statement> [ <statement>... ] <statement> ::= <directive> <break> <instruction> <break> <label> : <break> <directive> ::=.limit stack <val>.limit locals <val>.throws <classname>.catch <classname> from <label1> to <label2> using <label3> COMP3131/9102 Page 525 May 6, 2018

63 <instruction> ::= <simple_instruction> <complex_instruction> <simple_instruction> ::= <insn> <insn> <int> <int> <insn> <int> <insn> <num> <insn> <word> <insn> <word> <int> <insn> <word> <word> <insn> <quoted_string> <complex_instruction> ::= <lookupswitch> <tableswitch> COMP3131/9102 Page 526 May 6, 2018

64 <lookupswitch> ::= lookupswitch <nl> <int> : <label> <nl> <int> : <label> <nl>... default : <label> <tableswitch> ::= tableswitch <low> <nl> <label> <nl> <label> <nl>... default : <label> <access> ::= <access_item> [ <access_item>... ] <access_item> ::= public private protected static final synchronized volatile transient native interface abstract COMP3131/9102 Page 527 May 6, 2018

65 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) Run javac -g Test.java (-g turns on all debugging info) (c) Run jasmind Test.class (jasmind runs java JasminVisitor Test.class) or javap -c Test (d) Read Jasmin code in Test.j COMP3131/9102 Page 528 May 6, 2018

66 Reading (in Order of Increasing Importance) on-line JVM instructions Play around the tools mentioned in this lecture: All available in the class account Install them on your PC if you have one The JVM Spec Book Chapter 3 (instructions) Chapter 7 (more examples on compiling Java) Inside the JVM book (Chapter 5) Next Class: Java Bytecode Generation (Assignment 5) COMP3131/9102 Page 529 May 6, 2018

COMP3131/9102: Programming Languages and Compilers

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 information

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format

JVM. 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 information

CSC 4181 Handout : JVM

CSC 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 information

Course Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion

Course 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 information

Tutorial 3: Code Generation

Tutorial 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 information

The 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 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 information

Programming Language Systems

Programming 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 information

Let s make some Marc R. Hoffmann Eclipse Summit Europe

Let 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 information

Over-view. CSc Java programs. Java programs. Logging on, and logging o. Slides by Michael Weeks Copyright Unix basics. javac.

Over-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 information

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs. Compiling Java. The Java Class File Format 1 : JVM

CSc 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 information

JVML Instruction Set. How to get more than 256 local variables! Method Calls. Example. Method Calls

JVML 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 information

Compiler construction 2009

Compiler 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 information

javac 29: pop 30: iconst_0 31: istore_3 32: jsr [label_51]

javac 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 information

Compiling Techniques

Compiling 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 information

02 B The Java Virtual Machine

02 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 information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-06: The

More information

The Java Virtual Machine

The 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 information

Improving Java Performance

Improving 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 information

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

SOFTWARE 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 information

Compilation 2012 Code Generation

Compilation 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 information

CSE 431S Final Review. Washington University Spring 2013

CSE 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 information

A Quantitative Analysis of Java Bytecode Sequences

A Quantitative Analysis of Java Bytecode Sequences A Quantitative Analysis of Java Bytecode Sequences Ben Stephenson Wade Holst Department of Computer Science, University of Western Ontario, London, Ontario, Canada 1 Introduction A variety of studies have

More information

Recap: Printing Trees into Bytecodes

Recap: 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 information

CSE 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 /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 information

CS2110 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 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 information

The Java Virtual Machine

The 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 information

Under the Hood: The Java Virtual Machine. Problem: Too Many Platforms! Compiling for Different Platforms. Compiling for Different Platforms

Under 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 information

Topics. Structured Computer Organization. Assembly language. IJVM instruction set. Mic-1 simulator programming

Topics. 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 information

Improving Java Code Performance. Make your Java/Dalvik VM happier

Improving 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 information

Code Generation Introduction

Code 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 information

JAM 16: The Instruction Set & Sample Programs

JAM 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 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

An 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 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 information

Java Class Loading and Bytecode Verification

Java 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 information

Part VII : Code Generation

Part 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 information

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Under 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 information

COMP 520 Fall 2013 Code generation (1) Code generation

COMP 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 information

Java byte code verification

Java 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 information

Program Dynamic Analysis. Overview

Program 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 information

3/15/18. Overview. Program Dynamic Analysis. What is dynamic analysis? [3] Why dynamic analysis? Why dynamic analysis? [3]

3/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 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

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

CMPSC 497: Java Security

CMPSC 497: Java Security CMPSC 497: Java Security Trent Jaeger Systems and Internet Infrastructure Security (SIIS) Lab Computer Science and Engineering Department Pennsylvania State University 1 Enforcement Mechanisms Static mechanisms

More information

Problem: Too Many Platforms!

Problem: Too Many Platforms! Compiling for Different Platforms 2 Program written in some high-level language (C, Fortran, ML,...) Compiled to intermediate form Optimized UNDE THE HOOD: THE JAVA VITUAL MACHINE Code generated for various

More information

Virtual Machines. COMP 520: Compiler Design (4 credits) Alexander Krolik MWF 9:30-10:30, TR

Virtual 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 information

Characterizing the SPEC JVM98 Benchmarks On The Java Virtual Machine

Characterizing the SPEC JVM98 Benchmarks On The Java Virtual Machine Characterizing the SPEC JVM98 Benchmarks On The Java Virtual Machine Kyle R. Bowers David Kaeli Northeastern University Computer Architecture Research Group Department of Electrical and Computer Engineering

More information

Java: framework overview and in-the-small features

Java: 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 information

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Chapter 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 information

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 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 information

COMP 520 Fall 2009 Virtual machines (1) Virtual machines

COMP 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 information

CSc 372 Comparative Programming Languages. Getting started... Getting started. B: Java Bytecode BCEL

CSc 372 Comparative Programming Languages. Getting started... Getting started. B: Java Bytecode BCEL BCEL CSc 372 Comparative Programming Languages B: Java Bytecode BCEL BCEL (formerly JavaClass) allows you to load a class, iterate through the methods and fields, change methods, add new methods and fields,

More information

An Analysis of Basic Blocks within SPECjvm98 Applications

An Analysis of Basic Blocks within SPECjvm98 Applications An Analysis of Basic Blocks within SPECjvm98 Applications Jonathan Lambert Computer Science Dept. National University of Ireland Maynooth, Co. Kildare, Ireland jonathan@cs.nuim.ie James F. Power Computer

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

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs. Getting started... Getting started. 2 : Java Bytecode BCEL

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs. Getting started... Getting started. 2 : Java Bytecode BCEL BCEL CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs 2 : Java Bytecode BCEL BCEL (formerly JavaClass) allows you to load a class, iterate through the methods and fields, change methods,

More information

Code Analysis and Optimization. Pat Morin COMP 3002

Code Analysis and Optimization. Pat Morin COMP 3002 Code Analysis and Optimization Pat Morin COMP 3002 Outline Basic blocks and flow graphs Local register allocation Global register allocation Selected optimization topics 2 The Big Picture By now, we know

More information

to perform dependence analysis on Java bytecode, we must extend existing dependence analysis techniques for adapting Java bytecode. In this paper we p

to perform dependence analysis on Java bytecode, we must extend existing dependence analysis techniques for adapting Java bytecode. In this paper we p Dependence Analysis of 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 Email:zhao@cs.t.ac.jp

More information

CSCE 314 Programming Languages

CSCE 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 information

Static Program Analysis

Static 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 information

Compiling for Different Platforms. Problem: Too Many Platforms! Dream: Platform Independence. Java Platform 5/3/2011

Compiling 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 information

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs

CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs CSc 620 Debugging, Profiling, Tracing, and Visualizing Programs 2 : Java Bytecode BCEL Christian Collberg Department of Computer Science University of Arizona collberg+620@gmail.com Copyright c 2005Christian

More information

Taming the Java Virtual Machine. Li Haoyi, Chicago Scala Meetup, 19 Apr 2017

Taming the Java Virtual Machine. Li Haoyi, Chicago Scala Meetup, 19 Apr 2017 Taming the Java Virtual Machine Li Haoyi, Chicago Scala Meetup, 19 Apr 2017 Who Am I? Previously: Dropbox Engineering Currently: Bright Technology Services - Data Science, Scala consultancy Fluent Code

More information

Delft-Java Dynamic Translation

Delft-Java Dynamic Translation Delft-Java Dynamic Translation John Glossner 1,2 and Stamatis Vassiliadis 2 1 IBM Research DSP and Embedded Computing Yorktown Heights, NY glossner@us.ibm.com (formerly with Lucent Technologies) 2 Delft

More information

Translating Java bytecode to Simple

Translating Java bytecode to Simple Translating Java bytecode to Simple Semester Thesis Report Scheidegger Roman June 2010 Chair of Programming Methodology http://www.pm.inf.ethz.ch/ Department of Computer Science ETH Zurich Contents 1 Introduction

More information

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code Java Security The virtual machine principle: Source Code Compiler Abstract Machine Code Abstract Machine Code Compiler Concrete Machine Code Input Hardware Input Interpreter Output 236 Java programs: definitions

More information

CS263: 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 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 information

Java and C II. CSE 351 Spring Instructor: Ruth Anderson

Java and C II. CSE 351 Spring Instructor: Ruth Anderson Java and C II CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Lab 5 Due TONIGHT! Fri 6/2

More information

This project is supported by DARPA under contract ARPA F C-0057 through a subcontract from Syracuse University. 2

This project is supported by DARPA under contract ARPA F C-0057 through a subcontract from Syracuse University. 2 Contents 1 Introduction 3 2 Bytecode Analysis 4 2.1 The Java Virtual Machine................................. 4 2.2 Flow Graphs........................................ 5 2.3 Dominators and Natural Loops..............................

More information

Plan for Today. Safe Programming Languages. What is a secure programming language?

Plan 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 information

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Chapter 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 information

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 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 information

Exercise 7 Bytecode Verification self-study exercise sheet

Exercise 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 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

Java TM Introduction. Renaud Florquin Isabelle Leclercq. FloConsult SPRL.

Java 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 information

Joeq Analysis Framework. CS 243, Winter

Joeq 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 information

Mnemonics Type-Safe Bytecode Generation in Scala

Mnemonics 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 information

Jaos - Java on Aos. Oberon Event 03 Patrik Reali

Jaos - Java on Aos. Oberon Event 03 Patrik Reali Jaos - Java on Aos Oberon Event 03 Patrik Reali 1 Agenda! Oberon vs. Java! Java for Aos! Type Mapping! Compiling! Linking! Exceptions! Native Methods! Concurrency! Special Topics! Strings! Overloading!

More information

Bytecode-based Analysis for Increasing Class-Component Testability

Bytecode-based Analysis for Increasing Class-Component Testability Bytecode-based Analysis for Increasing Class-Component Testability Supaporn Kansomkeat Faculty of Engineering, Chulalongkorn University Bangkok, 10330, THAILAND supaporn.k@student.chula.ac.th Jeff Offutt

More information

A Force-Directed Program Graph Visualizer for Teaching White-Box Testing Techniques

A Force-Directed Program Graph Visualizer for Teaching White-Box Testing Techniques Paper ID #11203 A Force-Directed Program Graph Visualizer for Teaching White-Box Testing Techniques Dr. Weifeng Xu, Gannon University Dr. Weifeng Xu is an associate professor in department of computer

More information

Course Overview. Levels of Programming Languages. Compilers and other translators. Tombstone Diagrams. Syntax Specification

Course 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 information

Translating JVM Code to MIPS Code 1 / 43

Translating 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 information

How do you create a programming language for the JVM?

How do you create a programming language for the JVM? How do you create a programming language for the JVM? Federico Tomassetti.com Hi, I am Federico!Got a PhD in Language Engineering!Lived here and there Ora sono un Language En Progetto e co! Parser! Interpr!

More information

Michael Rasmussen ZeroTurnaround

Michael Rasmussen ZeroTurnaround Michael Rasmussen ZeroTurnaround Terminology ASM basics Generating bytecode Simple examples Your examples? Lately I ve been, I ve been losing sleep, dreaming about the things that we could be Binary names

More information

Introduction to Programming Using Java (98-388)

Introduction 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 information

Code Generation COMP 520: Compiler Design (4 credits) Professor Laurie Hendren

Code 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 information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

CSE 431S Code Generation. Washington University Spring 2013

CSE 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 information

EXAMINATIONS 2008 MID-YEAR COMP431 COMPILERS. Instructions: Read each question carefully before attempting it.

EXAMINATIONS 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 information

JoeQ Framework CS243, Winter 20156

JoeQ 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 information

A Type System for Object Initialization In the Java TM Bytecode Language

A Type System for Object Initialization In the Java TM Bytecode Language Electronic Notes in Theoretical Computer Science 10 (1998) URL: http://www.elsevier.nl/locate/entcs/volume10.html 7 pages A Type System for Object Initialization In the Java TM Bytecode Language Stephen

More information

Space Exploration EECS /25

Space 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 information

Compiling Faster, Compiling Better with Falcon. Iván

Compiling Faster, Compiling Better with Falcon. Iván Compiling Faster, Compiling Better with Falcon Iván Krȳlov @JohnWings Compiling Faster, Compiling Better with Falcon Overview of 3 technologies Falcon compiler ReadyNow & Compile Stashing Challenges (largely

More information

Code Generation: Introduction

Code 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 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

Living in the Matrix with Bytecode Manipulation

Living in the Matrix with Bytecode Manipulation Living in the Matrix with Bytecode Manipulation QCon NY 2014 Ashley Puls Senior Software Engineer New Relic, Inc. Follow Along http://slidesha.re/1kzwcxr Outline What is bytecode? Why manipulate bytecode?

More information

EXAMINATIONS 2014 TRIMESTER 1 SWEN 430. Compiler Engineering. This examination will be marked out of 180 marks.

EXAMINATIONS 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 information

Code Profiling. CSE260, Computer Science B: Honors Stony Brook University

Code Profiling. CSE260, Computer Science B: Honors Stony Brook University Code Profiling CSE260, Computer Science B: Honors Stony Brook University http://www.cs.stonybrook.edu/~cse260 Performance Programs should: solve a problem correctly be readable be flexible (for future

More information

invokedynamic IN 45 MINUTES!!! Wednesday, February 6, 13

invokedynamic IN 45 MINUTES!!! Wednesday, February 6, 13 invokedynamic IN 45 MINUTES!!! Me Charles Oliver Nutter headius@headius.com, @headius blog.headius.com JRuby Guy at Sun, Engine Yard, Red Hat JVM enthusiast, educator, contributor Earliest adopter of invokedynamic

More information

Exploiting FPGA Concurrency to Enhance JVM Performance

Exploiting 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 information

EMBEDDING THE HIDDEN INFORMATION INTO JAVA BYTE CODE BASED ON OPERANDS INTERCHANGING

EMBEDDING THE HIDDEN INFORMATION INTO JAVA BYTE CODE BASED ON OPERANDS INTERCHANGING EMBEDDING THE HIDDEN INFORMATION INTO JAVA BYTE CODE BASED ON OPERANDS INTERCHANGING Andrey Vladimirovich Krasov, Aleksander Sergeevich Arshinov and Igor Aleksandrovich Ushakov Federal State Budget-Financed

More information

Advice Weaving in ÉNFASIS

Advice Weaving in ÉNFASIS 2010 Electronics, Robotics and Automotive Mechanics Conference Advice Weaving in ÉNFASIS Ulises Juárez-Martínez Division of Research and Postgraduate Studies Instituto Tecnológico de Orizaba 94320, Veracruz,

More information