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

Size: px
Start display at page:

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

Transcription

1 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 Instruction Set loads, stores (0-3 for each iload, lload, fload, dload, aload) pop, dup, swap, etc. arithmetic conversion (e.g., il) comparisons (lcmp) goto, jsr, goto_w, jsr_w, ret tableswitch, lookupswitch 0 getstatic, putstatic newarray, anewarray, 66 multianewarray,arraylength 9 invoke methods, throw 37 new getfield, putfield checkcast instanceof monitorenter, monitorexit returns (e.g., ireturn) conditional jumps (ifeq, ifnull, ifnonnull) 6 wide nop, breakpoint, unused, implementation 6 dependent (0 out of 6 possible opcodes used) How to get more than 6 local variables! wide <opcode> <byte> <byte> Opcode is one of iload, fload, aload, lload, dload, istore, fstore, astore, lstore, dstore, or ret Modifies instruction to take byte operand (byte << 8 byte) Method Calls invokevirtual <method> Invokes the method <method> on the parameters and object on the top of the stack. Finds the appropriate method at run-time based on the actual type of the this object. invokevirtual <Method void println(java.lang.string)> 3 Method Calls Example invokestatic <method> Invokes a static (class) method <method> on the parameters on the top of the stack. Finds the appropriate method at runtime based on the actual type of the this object. public class Sample { System.err.println ("Hello!"); System.exit (); 6

2 > javap -c Sample Compiled from Sample.java public class Sample extends java.lang.object { public Sample(); public static void main(java.lang.string[]); public class Sample { System.err.println ("Hello!"); System.exit (); Method Sample() 0 aload_0 invokespecial # <Method java.lang.object()> return 0 getstatic # <Field java.io.printstream err> 3 ldc #3 <String "Hello!"> invokevirtual # <Method void println(java.lang.string)> 8 iconst_ 9 invokestatic # <Method void exit(int)> return Cast Instruction public class Cast { Object x; x = (Object) args[0]; System.out.println ("result: " + (String) x); aload_0 iconst_0 public class Cast { aaload 3 astore_ Object x; getstatic # <Field java.io.printstream x = (Object) out> args[0]; 7 new #3 <Class java.lang.stringbuffer> System.out.println ("result: " + (String) x); 0 dup invokespecial # <Method java.lang.stringbuffer()> ldc # <String "result: "> 6 invokevirtual #6 <Method java.lang.stringbuffer append(java.lang.string)> 9 aload_ 0 checkcast #7 <Class java.lang.string> 3 invokevirtual #6 <Method java.lang.stringbuffer append(java.lang.string)> 6 invokevirtual #8 <Method java.lang.string tostring()> 9 invokevirtual #9 <Method void println(java.lang.string)> 3 return pushing constants JVML Instruction Set loads, stores (0-3 for each iload, lload, fload, dload, aload) pop, dup, swap, etc. arithmetic conversion (e.g., il) comparisons (lcmp) goto, jsr, goto_w, jsr_w, ret tableswitch, lookupswitch returns (e.g., ireturn) conditional jumps (ifeq, ifnull, ifnonnull) 0 getstatic, putstatic newarray, anewarray, 66 multianewarray,arraylength 9 invoke methods, throw 37 new getfield, putfield checkcast instanceof monitorenter, monitorexit 6 wide nop, breakpoint, unused, implementation 6 dependent (0 out of 6 possible opcodes used) 9 0 The Worst Instruction jsr [branchbyte] [branchbyte] Forms jsr = 68 (0xa8) Operand Stack......, address Description The address of the opcode of the instruction immediately following this jsr instruction is pushed onto the operand stack as a value of type returnaddress. The unsignedbranchbyte and branchbyte are used to construct a signed 6-bit offset, where the offset is (branchbyte << 8) branchbyte. Execution proceeds at that offset from the address of this jsr instruction. The target address must be that of an opcode of an instruction within the method that contains this jsr instruction. Notes The jsr instruction is used with the ret instruction in the implementation of the finally clauses of the Java programming language. Note that jsr pushes the address onto the operand stack and ret gets it out of a local variable. This asymmetry is intentional. public class JSR { try { System.out.println("hello"); catch (Exception e) { System.out.println ("There was an exception!"); finally { System.out.println ("I am finally here!"); Try-Catch-Finally

3 public class JSR { 0 getstatic # <Field java.io.printstream out> 3 ldc #3 <String "hello"> try { System.out.println("hello"); invokevirtual # <Method void println(java.lang.string)> catch (Exception e) { 8 jsr 3 System.out.println (... exception!"); finally { goto 6 System.out.println ("I am finally"); astore_ getstatic # <Field java.io.printstream out> 8 ldc #6 <String "There was an exception!"> 0 invokevirtual # <Method void println(java.lang.string)> 3 jsr 3 6 goto 6 9 astore_ 30 jsr 3 33 aload_ 3 athrow Exception table: from to target type 3 astore_3 0 8 <Class java.lang.exception> 36 getstatic # <Field java.io.printstream 0 out> 9 any 39 ldc #7 <String "I am finally here!"> 6 9 any invokevirtual # <Method void 9 println(java.lang.string)> 33 9 any ret 3 6 return Java : Programming Language compared to C++, not to C ^ sort of A simple, object-oriented, ^ distributed, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, and dynamic language. [Sun9] Java: int is 3 bits C: int is >= 6 bits 3 What is a secure programming language?. Language is designed so it cannot express certain computations considered insecure. A few attempt to do this: PLAN, packet filters. Language is designed so that (accidental) program bugs are likely to be caught by the compiler or run-time environment instead of leading to security vulnerabilities. Safe Programming Languages Type Safety Compiler and run-time environment ensure that bits are treated as the type they represent Memory Safety Compiler and run-time environment ensure that program cannot access memory outside defined storage Control Flow Safety Can t jump to arbitrary addresses Which of these does C/C++ have? Is Java the first language to have them? No way! LISP had them all in Java Safety Type Safety Most types checked statically Coercions, array assignments type checked at run time Memory Safety No direct memory access (e.g., pointers) Primitive array type with mandatory runtime bounds checking Control Flow Safety Structured control flow, no arbitrary jumps Malicious Code Can a safe programming language protect you from malcode?. Code your servers in it to protect from buffer overflow bugs. Only allow programs from untrustworthy origins to run if the are programmed in the safe language 7 8 3

4 Safe Languages? But how can you tell program was written in the safe language? Get the source code and compile it (most vendors, and all malicious attackers refuse to provide source code) Special compilation service cryptographically signs object files generated from the safe language (SPIN, [Bershad96]) Verify object files preserve safety properties of source language (Java) code.java Java Source Code User JVML javac Compiler JavaVM code.class JVML Object Code Wants to know JVML code satisfies Java s safety properties. 9 0 Does JVML satisfy Java s safety properties? Java Security Architecture JAR iconst_ push integer constant on stack istore_0 store top of stack in variable 0 as int aload_0 load object reference from variable 0 No! This code violates Java s type rules. Verify Exception Security exception ClassLoader Class Verifier Java VM Operating System Protected Resource Mistyped Code.method public static main([ljava/lang/string;)v JAR iconst_ > java Simple ClassLoader istore_0 Exception in thread aload_0 Class "main" iconst_ Verify Verifier java.lang.verifyerror: iconst_3 Exception (class: Simple, method: iadd Security main signature: Java VM exception Operating System ([Ljava/lang/String;)V).end method Protected Resource Register 0 contains wrong type Verifier error before any code runs 3 Runtime Error public class Cast { Object o = new Object (); String s; s = (String) o; System.out.println(s); return; 0 new # <Class java.lang.object> 3 dup invokespecial # <Method java.lang.object()> 7 astore_ 8 aload_ 9 checkcast #3 <Class java.lang.string> astore_ 3 getstatic # <Field java.io.printstream out> 6 aload_ 7 invokevirtual # <Method void println(java.lang.string)> 0 return

5 Bytecode Verifier Checks class file is formatted correctly Magic number: class file starts with 0xCAFEBABE String table, code, methods, etc. Checks JVML code satisfies safety properties Simulates program execution to know types are correct, but doesn t need to examine any instruction more than once Verifying Safety Properties Type safe Stack and variable slots must store and load as same type Only use operations valid for the data type Memory safe Must not attempt to pop more values from stack than are on it Doesn t access private fields and methods outside class implementation Control flow safe Jumps must be to valid addresses within function, or call/return 6 Charge PS6 will be out (electronically) on Friday If you would like to be assigned a partner for PS6, send me as soon as possible 7

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

Plan for Today. Class 21: Hair-Dryer Attacks. Recap: Java Platform. Project Design Documents. Running Mistyped Code. Running Mistyped Code

Plan for Today. Class 21: Hair-Dryer Attacks. Recap: Java Platform. Project Design Documents. Running Mistyped Code. Running Mistyped Code cs2220: Engineering Software Class 21: Hair-Dryer Attacks Plan for Today Recap: Java Platform Security Trusted Computing Base: should we trust Java s? Hair-Dryer Attacks Image from www.clean-funny.com,

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

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

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

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

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

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

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

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

Running Mistyped Code. Lecture 19: Java Security. Running Mistyped Code. Java Security Architecture. JavaVM. Reference Monitors

Running Mistyped Code. Lecture 19: Java Security. Running Mistyped Code. Java Security Architecture. JavaVM. Reference Monitors CS16: Program and Data Representation University of Virginia Computer Science Spring 006 David Evans Lecture 19: Java Security PS6 Submission: Only to be eligible for the Byte Code Wizard awards. If the

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 Language Implementation

The Java Language Implementation CS 242 2012 The Java Language Implementation Reading Chapter 13, sections 13.4 and 13.5 Optimizing Dynamically-Typed Object-Oriented Languages With Polymorphic Inline Caches, pages 1 5. Outline Java virtual

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

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

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

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

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

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

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

Static Analysis of Dynamic Languages. Jennifer Strater

Static Analysis of Dynamic Languages. Jennifer Strater Static Analysis of Dynamic Languages Jennifer Strater 2017-06-01 Table of Contents Introduction............................................................................... 1 The Three Compiler Options...............................................................

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

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

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

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

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

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16

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

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

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time CS2110 Fall 2011 Lecture 25 Java program last time Java compiler Java bytecode (.class files) Compile for platform with JIT Interpret with JVM Under the Hood: The Java Virtual Machine, Part II 1 run native

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

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

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

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

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

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

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

Shared Mutable State SWEN-220

Shared Mutable State SWEN-220 Shared Mutable State SWEN-220 The Ultimate Culprit - Shared, Mutable State Most of your development has been in imperative languages. The fundamental operation is assignment to change state. Assignable

More information

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator CS 412/413 Introduction to Compilers and Translators Andrew Myers Cornell University Administration Design reports due Friday Current demo schedule on web page send mail with preferred times if you haven

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

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

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

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

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

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

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

Scala: Byte-code Fancypants. David Pollak JVM Language Summit 2009

Scala: Byte-code Fancypants. David Pollak JVM Language Summit 2009 Scala: Byte-code Fancypants David Pollak JVM Language Summit 2009 http://github.com/dpp/jvm_summit_2009 About DPP Author Beginning Scala BDFL Lift Wrote some spreadsheets What is Scala? A pile of short-cuts

More information

Advances in Programming Languages: Generics, interoperability and implementation

Advances in Programming Languages: Generics, interoperability and implementation Advances in Programming Languages: Generics, interoperability and implementation Stephen Gilmore The University of Edinburgh February 1, 2007 Understanding generic code Generic Java extends Java with generic

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

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

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

INTERMEDIATE REPRESENTATIONS RTL EXAMPLE

INTERMEDIATE REPRESENTATIONS RTL EXAMPLE INTERMEDIATE REPRESENTATIONS CS 403: Intermediate Representations and Code Generation Stefan D. Bruda Winter 2015 Code generation is typically not done directly The functioning of a compiler is typically

More information

Oak Intermediate Bytecodes

Oak Intermediate Bytecodes Oak Intermediate Bytecodes A summary of a paper for the ACM SIGPLAN Workshop on Intermediate Representations (IR 95) James Gosling 100 Hamilton Avenue 3rd floor Palo Alto CA 94301 Oak

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

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Roadmap. Java: Assembly language: OS: Machine code: Computer system: Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq movq... popq ret %rbp %rsp, %rbp

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

LaboratoriodiProgrammazione III

LaboratoriodiProgrammazione III LaboratoriodiProgrammazione III Lezione 15: Portabilità e Sicurezza, Java Massimo Tivoli Origins of the language James Gosling and others at Sun, 1990 95 Oak language for set top box small networked device

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

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

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

Introduction Basic elements of Java

Introduction Basic elements of Java Software and Programming I Introduction Basic elements of Java Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Module Information Time: Thursdays in the Spring term Lectures: MAL B04: 2

More information

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

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

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

Problems of Bytecode Verification

Problems of Bytecode Verification Eidgenossische Technische Hochschule Zurich Ecole polytechnique federale de Zurich Politecnico federale di Zurigo Swiss Federal Institute of Technology Zurich Problems of Bytecode Verification Robert F.

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

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-05: The

More information

Java Card Platform. Virtual Machine Specification, Classic Edition. Version 3.1. January 2019

Java Card Platform. Virtual Machine Specification, Classic Edition. Version 3.1. January 2019 Java Card Platform Virtual Machine Specification, Classic Edition Version 3.1 January 2019 Java Card Platform Virtual Machine Specification, Classic Edition Version 3.1 Copyright 1998, 2019, Oracle and/or

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

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

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 Instrumentation for Dynamic Analysis

Java Instrumentation for Dynamic Analysis Java Instrumentation for Dynamic Analysis and Michael Ernst MIT CSAIL Page 1 Java Instrumentation Approaches Instrument source files Java Debug Interface (JDI) Instrument class files Page 2 Advantages

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

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

Practical VM exploiting based on CACAO

Practical VM exploiting based on CACAO Just in Time compilers - breaking a VM Practical VM exploiting based on CACAO Roland Lezuo, Peter Molnar Just in Time compilers - breaking a VM p. Who are we? We are (were) CS students at Vienna University

More information

Java TM. Multi-Dispatch in the. Virtual Machine: Design and Implementation. Computing Science University of Saskatchewan

Java TM. Multi-Dispatch in the. Virtual Machine: Design and Implementation. Computing Science University of Saskatchewan Multi-Dispatch in the Java TM Virtual Machine: Design and Implementation Computing Science University of Saskatchewan Chris Dutchyn (dutchyn@cs.ualberta.ca) September 22, 08 Multi-Dispatch in the Java

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

Delft-Java Dynamic Translation

Delft-Java Dynamic Translation Delft-Java Dynamic Translation John Glossner 1 2 1 IBM Research Yorktown Heights, NY glossner@cardit.et.tudelft.nl Stamatis Vassiliadis 2 2 Delft University of Technology Electrical Engineering Department

More information

CS11 Java. Fall Lecture 1

CS11 Java. Fall Lecture 1 CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon

More information

Design and Implementation of Pep, a Java Just-In-Time Translator

Design and Implementation of Pep, a Java Just-In-Time Translator SML-E-96-49 Published in TAPOS, Theory and Practice of Object Systems 3(2), p. 127-155, 1997. Design and Implementation of Pep, a Java Just-In-Time Translator Ole Agesen Sun Microsystems Laboratories 2

More information

High-Level Language VMs

High-Level Language VMs High-Level Language VMs Outline Motivation What is the need for HLL VMs? How are these different from System or Process VMs? Approach to HLL VMs Evolutionary history Pascal P-code Object oriented HLL VMs

More information

Vulnerability analysis of a smart card Run Time

Vulnerability analysis of a smart card Run Time Vulnerability analysis of a smart card Run Time Séminaire méthodes formelles et sécurité Rennes, January the 6 th Jean-Louis Lanet Jean-louis.lanet@unilim.fr Agenda The context The Java Card security model

More information

Verifying a Compiler for Java Threads

Verifying a Compiler for Java Threads Verifying a Compiler for Java Threads Andreas Lochbihler IPD, PROGRAMMING PARADIGMS GROUP, COMPUTER SCIENCE DEPARTMENT KIT - University of the State of aden-wuerttemberg and National Research Center of

More information