CS263: Runtime Systems Lecture: High-level language virtual machines. Part 1 of 2. Chandra Krintz UCSB Computer Science Department

Similar documents
CS263: Runtime Systems Lecture: High-level language virtual machines

CS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II

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

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-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

Compiling Techniques

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

02 B The Java Virtual Machine

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

Run-time Program Management. Hwansoo Han

Problem: Too Many Platforms!

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

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

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

Compiler construction 2009

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

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

The Java Virtual Machine. CSc 553. Principles of Compilation. 3 : The Java VM. Department of Computer Science University of Arizona

High-Level Language VMs

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

CSC 4181 Handout : JVM

Java byte code verification

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

Java Class Loading and Bytecode Verification

Delft-Java Link Translation Buffer

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

CSE 431S Final Review. Washington University Spring 2013

Program Dynamic Analysis. Overview

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

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

Chapter 5. A Closer Look at Instruction Set Architectures

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

Java: framework overview and in-the-small features

CS 231 Data Structures and Algorithms, Fall 2016

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

Introduction to Programming Using Java (98-388)

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

An Introduction to Multicodes. Ben Stephenson Department of Computer Science University of Western Ontario

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

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

Improving Java Performance

The Java Virtual Machine

JAM 16: The Instruction Set & Sample Programs

1 Shyam sir JAVA Notes

Static Analysis of Dynamic Languages. Jennifer Strater

Translating JVM Code to MIPS Code 1 / 43

The Java Virtual Machine

Compilation 2012 Code Generation

The Java Language Implementation

CS260 Intro to Java & Android 03.Java Language Basics

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

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

Introduction Basic elements of Java

Inheritance, Polymorphism and the Object Memory Model

Tutorial 3: Code Generation

Short Notes of CS201

CSCE 314 Programming Languages

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Let s make some Marc R. Hoffmann Eclipse Summit Europe

CS201 - Introduction to Programming Glossary By

CS11 Java. Fall Lecture 1

COMP3131/9102: Programming Languages and Compilers

Exercise 7 Bytecode Verification self-study exercise sheet

Data Structures (list, dictionary, tuples, sets, strings)

Java Fundamentals (II)

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Chapter 5. A Closer Look at Instruction Set Architectures

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

Procedure and Object- Oriented Abstraction

Java Object Oriented Design. CSC207 Fall 2014

COP 3330 Final Exam Review

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Java Internals. Frank Yellin Tim Lindholm JavaSoft

Delft-Java Dynamic Translation

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2

Java and C CSE 351 Spring

Java Overview An introduction to the Java Programming Language

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

Code Generation Introduction

CMPSC 497: Java Security

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

C++ Programming: Polymorphism

CS 11 java track: lecture 1

Practical VM exploiting based on CACAO

Compiler construction 2009

CSc 453 Interpreters & Interpretation

Mnemonics Type-Safe Bytecode Generation in Scala

Instantiation of Template class

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Administrivia. Java Review. Objects and Variables. Demo. Example. Example: Assignments

Joeq Analysis Framework. CS 243, Winter

Java Instrumentation for Dynamic Analysis

Advances in Programming Languages: Generics, interoperability and implementation

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

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

Introduction to Java

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

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

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

Chapter 1 Getting Started

Transcription:

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 PL Implementations Java, all.net languages, scripting languages Object-oriented Encapsulation and data hiding, inheritance, polymorphism Static methods static dispatch; virtual methods dynamic dispatch When same name is used (polymorphism): hidden vs overridden Static fields and instance fields When same name is used (polymorphism): hidden

Portable, Mobile, OO Execution Model Execution model embodied by recent PL Implementations Java, all.net languages, scripting languages Object-oriented Encapsulation and data hiding, inheritance, polymorphism Static methods static dispatch; virtual methods dynamic dispatch When same name is used (polymorphism): hidden vs overridden Static fields and instance fields When same name is used (polymorphism): hidden Program is portable and assumed to be mobile Architecture-independent representation of code and data Incrementally loaded (transfer unit = class, assembly, archive (jar)) Data translated from file/class to VM s internal representation» Class model and object model Code is translated to native code interleaved with execution Instruction level (interpretation), method level (JIT compilation), or path level (trace compilation)

Java Classfiles Architecture-independent Format called bytecode Dynamically loaded / executed by a Java Virtual Machine File.java class cls1 { class cls2 { source compiler (javac File.java) cls1.class... Java bytecode... architecture-independent architecture-dependent Java Virtual Machine Translation from bytecode to native machine code executable code... Java bytecode... cls2.class Runtime environment program loading/verif. memory management thread/synchronization optimization

A Java Program (Compiled Java Source) Class files (generated from source using a source compiler) Each class file is in a binary bytecode format Each class file contains in a fixed, well-defined format Symbolic information (Metadata in MSIL/.Net binary files) All of the necessary data to execute the class file Instructions (code) in the JVM ISA format Java Class File Symbolic info method code... method code

A Java Program (Compiled Java Source) Class files (generated from source using a source compiler) Each class file is in a binary bytecode format Each class file contains in a fixed, well-defined format Symbolic information (Metadata in MSIL/.Net binary files) All of the necessary data to execute the class file Instructions (code) in the JVM ISA format Java Class File Constant Pool method code... method code Instead of repeating all of the symbol names throughout, we store all of the symbols in a table (the constant pool) and then have everything that uses the symbol (code, other data structures) use a reference into the table instead Types (packages, classes, primitives), names, and also method and field data structures

The Java Class File Format (Symbolic Info) Java Class File Magic number Version Constant pool Access flags This class Super class Interfaces Fields Methods Attributes

The Java Class File Format (Symbolic Info) Java Class File Magic number Version Constant pool Constant pool - an array String: Hello Method: C.M(int)V Field: int F... Access flags This class Super class Interfaces Fields Methods Attributes Fields Flags Name Sig Attributes [pub] x int [priv] y C Methods Flags Name Sig Attributes [pub] q ( )int code exceptions Code maxstack=5, maxlocals= Code[] = {push,add,store,ldc ExceptionTable[]={ Attributes

The Java Class File Format (Symbolic Info) Java Class File Magic number Version Constant pool Constant pool - an array String: Hello Method: C.M(int)V Field: int F... Access flags This class Super class Interfaces Fields Methods Attributes References the constant pool Fields Flags Name Sig Attributes [pub] x int [priv] y C Methods Flags Name Sig Attributes [pub] q ( )int code exceptions Code maxstack=5, maxlocals= Code[] = {push,add,store,ldc ExceptionTable[]={ Attributes

A Java Program (Compiled Java Source) Class files (generated from source using a source compiler) Each class file is in a binary bytecode format Each class file contains in a fixed, well-defined format Symbolic information (Metadata in MSIL/.Net binary files) All of the necessary data to execute the class file Instructions (code) in the JVM ISA format Java Class File Constant Pool method code... method code When a class file is read into memory by the runtime, it is stored in a representation internal to the runtime. The runtime keeps a global table which Refers to all these structures, and a map that records which indexes hold which structure. E.g. all internal class representations, static fields, and static methods, are stored in this global table (sometimes called the statics table).

Java Classfiles Architecture-independent Format called bytecode Dynamically loaded / executed by a Java Virtual Machine File.java class cls1 { class cls2 { source compiler (javac File.java) cls1.class... Java bytecode... architecture-independent architecture-dependent Java Virtual Machine Translation from bytecode to native machine code executable code... Java bytecode... cls2.class Runtime environment program loading/verif. memory management thread/synchronization optimization

Load/store Arithmetic Java Bytecode Instructions Type conversions (int to long, etc) Object creation (objects/arrays/multi-dim arrays) Object manipulation (get/put fields, check properties) Operand stack manipulation Control transfer (conditionals/unconditionals) Method invocation and return Exception and finally implementation Synchronization Code maxstack=5, maxlocals= Code[] = {push,add,store,ldc ExceptionTable[]={ Attributes http://docs.oracle.com/javase/specs/jvms/se7/html/index.html /html/jvms-.html#jvms-.1.1.

Load/store Arithmetic Java Bytecode Instructions Type conversions (int to long, etc) Object creation (objects/arrays/multi-dim arrays) Object manipulation (get/put fields, check properties) Operand stack manipulation Control transfer (conditionals/unconditionals) Method invocation and return Exception and finally implementation Synchronization Code maxstack=5, maxlocals= Code[] = {push,add,store,ldc ExceptionTable[]={ Attributes http://docs.oracle.com/javase/specs/jvms/se7/html/index.html /html/jvms-.html#jvms-.1.1.

Operand Stack Do not confuse this with the user/runtime/system stack! User stack: manages local variable scope for functions/methods at runtime Operand stack: holds operands so that instructions can be executed Both are last-in-first-out (LIFO) queue data structures Most modern VM languages execute a stream of instructions using an operand stack Requires that the virtual instruction set architecture (ISA) implements a stack machine

Stack-based ISA Operands are implicit - on the top of stack (tos) Compiler simplification (no register allocation) Compact instruction encoding push A push B add pop C Operand Stack tos C = A + B //push A on tos //push B on tos //add the to elements at the tos //pop the tos and put the value in C A B (A+B) A Used in hardware in old HP calculators Use in most modern language runtimes to enable program portability JavaCard implements Java bytecode ISA in hardware; as does Azul Vega processor

The Alternative: Register-based ISA Operands are explicit (ie specified in the instruction) Register-register (aka load-store) Memory accesses via load & store instructions only load R1, A load R2, B add R3,R1,R2 store C, R3 C = A + B (RISC) //load memory at &A into reg1 //load memory at &B into reg2 //add reg1+reg2 and store result in reg3 //store value in reg1 into memory at &C Register-memory Operands can be taken from registers or memory directly add C, A, B C = A + B (CISC) // load memory from each address // perform operation // store result in memory

Java Bytecode Instructions Can manipulate data (operands) in following formats: typed instrs instr. starts with Integers (32-bits) i Longs (6-bits) l Floats (32-bits) f Doubles (6-bits) d Shorts (16-bits) s Bytes (-bits) b Object references (32-bits) a Char (16-bits) c Arrays Opcode + data - variable length instructions Opcode: 1-byte wide (256 possible) Data: zero or more values to be operated on (operands) 1-byte opcode operand... operand Operands are 1-byte each so For a 2-byte index you need: (operand1 << ) operand2

Java Bytecode Instructions Refer to method parameters and local variables by number 256 is the maximum wide version of instruction extends this to 65536 EX: istore 2 pops tos and puts value in local variable number 2 Java stack (operand stack) Holds the operands during operations All (virtual) computation performed here 32-bits wide; longs/doubles take 2 stack entries maxstack=5, maxlocals= Code[] = {push,add,store,ldc ExceptionTable[]={ Attributes Two per method data structures: Local variable array (max index is 6K-1): Index: 1 2 3 5 Holds params followed by local vars Operand stack Each method gets its own Grows/shrinks with instructions executed

Java Bytecode Instructions Refer to method parameters and local variables by number 256 is the maximum wide version of instruction extends this to 65536 EX: istore 2 pops tos and puts value in local variable number 2 Java stack (operand stack) Holds the operands during operations All (virtual) computation performed here 32-bits wide; longs/doubles take 2 stack entries Two per method data structures: Local variable array (max index is 6K-1): Index: 1 2 3 5 Holds params followed by local vars Operand stack Each method gets its own Grows/shrinks with instructions executed Constant Pool rep in VM Reference within an instruction to the constant pool instruction

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; Simple.field1 = i+j; Simple.field2 = null; Simple.foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo(int k) { public static void main(string args[]) { int i = args.length; int j = 7; Simple.field1 = i+j; Simple.field2 = null; Simple.foo(7); When a method call is made (using line-by-line interpretation): Runtime moves arguments to correct location in caller s register (locals) array public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: bipush 7 1: invokestatic #5; //Method foo:(i)v 21: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo(int k) { public static void main(string args[]) { int i = args.length; int j = 7; Simple.field1 = i+j; Simple.field2 = null; Simple.foo(i); When a method call is made (using line-by-line interpretation): Runtime moves arguments to correct location in caller s register (locals) array public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16:??? 17: invokestatic #5; //Method foo:(i)v 2: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo(int k) { public static void main(string args[]) { int i = args.length; int j = 7; Simple.field1 = i+j; Simple.field2 = null; Simple.foo(i); When a method call is made (using line-by-line interpretation): Runtime moves arguments to correct location in caller s register (locals) array public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: iload_1 17: invokestatic #5; //Method foo:(i)v 2: return

Constructors public class Hello { int field1; int getfield() { return field1; public static void main(string args[]) { System.err.println("Hello World!"); Hello obj = new Hello(); obj.field1 = 7; int i = obj.getfield(); Allocation (new) + instantiation (<init>(...)v) Constructors are statically dispatched Constructors must return void So aliasing (dup) must be used) All constructors run parent constructor first! default parent: super() //added for you you can change this via super(...) public static void main(java.lang.string[]); Code: : getstatic #2 // Field java/lang/ // System.err:Ljava/io/ // PrintStream; 3: ldc #3 // String Hello World! 5: invokevirtual # // Method java/io/ // PrintStream.println: //(Ljava/lang/String;)V : new #5 // class Hello 11: dup : invokespecial #6 // Method "<init>":()v 15: astore_1 16: aload_1 17: bipush 7 19: putfield #7 // Field field1:i 22: aload_1 23: invokevirtual # // Method getfield:()i 26: istore_2 27: return

Instance fields and methods public class Hello { int field1; int getfield() { return field1; public static void main(string args[]) { System.err.println("Hello World!"); Hello obj = new Hello(); obj.field1 = 7; int i = obj.getfield(); When a method call is made (using line-by-line interpretation): Runtime moves arguments to correct location in caller s registers (locals) array public static void main(java.lang.string[]); Code: : getstatic #2 // Field java/lang/ // System.err:Ljava/io/ // PrintStream; 3: ldc #3 // String Hello World! 5: invokevirtual # // Method java/io/ // PrintStream.println: //(Ljava/lang/String;)V : new #5 // class Hello 11: dup : invokespecial #6 // Method "<init>":()v 15: astore_1 16: aload_1 17: bipush 7 19: putfield #7 // Field field1:i 22: aload_1 23: invokevirtual # // Method getfield:()i 26: istore_2 27: return

Practice, Practice, Practice! (by Monday) http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf //dump the bytecode (shows constant pool entries resolved) javap -c Simple //Simple must be in your classpath //http://www.cs.ucsb.edu/~cs263/showme.tar.gz //cs263 dir must be in your class path //dump constant pool (so you can resolve the entries yourself) java cs263.showmethestructure Simple.class JVM instructions: http://cs.au.dk/~mis/dovs/vmspec/vmspecix.fm.html

CS263: Runtime Systems Lecture: High-level language virtual machines Today: Part 2 of 2 Chandra Krintz UCSB Computer Science Department

The Java Class File Format (Symbolic Info) Java Class File Magic number Version Constant pool Access flags This class Super class Interfaces Fields Methods Attributes

The Java Class File Format (Symbolic Info) Java Class File Magic number Version Constant pool Constant pool - an array String: Hello Method: C.M(int)V Field: int F... Access flags This class Super class Interfaces Fields Methods Attributes References the constant pool Fields Flags Name Sig Attributes [pub] x int [priv] y C Methods Flags Name Sig Attributes [pub] q ( )int code exceptions Code maxstack=5, maxlocals= Code[] = {push,add,store,ldc ExceptionTable[]={ Attributes

Load/store Arithmetic Java Bytecode Instructions Type conversions (int to long, etc) Object creation (objects/arrays/multi-dim arrays) Object manipulation (get/put fields, check properties) Operand stack manipulation Control transfer (conditionals/unconditionals) Method invocation and return Exception and finally implementation Synchronization Code maxstack=5, maxlocals= Code[] = {push,add,store,ldc ExceptionTable[]={ Attributes http://docs.oracle.com/javase/specs/jvms/se7/html/index.html /html/jvms-.html#jvms-.1.1.

Stack-based ISA Operands are implicit - on the top of stack (tos) Compiler simplification (no register allocation) Compact instruction encoding push A push B add pop C Operand Stack tos C = A + B //push A on tos //push B on tos //add the to elements at the tos //pop the tos and put the value in C A B (A+B) A Used in hardware in old HP calculators Use in most modern language runtimes to enable program portability JavaCard implements Java bytecode ISA in hardware; as does Azul Vega processor

Java Bytecode Instructions Can manipulate data (operands) in following formats: typed instrs instr. starts with Integers (32-bits) i Longs (6-bits) l Floats (32-bits) f Doubles (6-bits) d Shorts (16-bits) s Bytes (-bits) b Object references (32-bits) a //address Char (16-bits) c Arrays Opcode + data - variable length instructions Opcode: 1-byte wide (256 possible) Data: zero or more values to be operated on (operands) 1-byte opcode operand... operand Operands are 1-byte each so For a 2-byte index you need: (operand1 << ) operand2

Java Bytecode Instructions Refer to method parameters and local variables by number 256 is the maximum wide version of instruction extends this to 65536 EX: istore 2 pops tos and puts value in local variable number 2 Java stack (operand stack) Holds the operands during operations All (virtual) computation performed here 32-bits wide; longs/doubles take 2 stack entries Two per method data structures: Local variable array (max index is 6K-1): Index: 1 2 3 5 Holds params followed by local vars Operand stack Each method gets its own Grows/shrinks with instructions executed Constant Pool rep in VM Reference within an instruction to the constant pool instruction

JVM Bytecode ISA Typed instructions Opcode: 1-byte wide (253 are used) Data: zero or more values to be operated on (operands) MSIL Typed instructions Opcode is 2-bytes (6K possible) Python 113 opcodes (2 with arguments and 71 without) All use an operand stack for one or more of their operands Translator must translate this ISA to native code Interpreter (line-by-line translation): calls functions for each instr Compiler: translates methods or code blocks to native all at once

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf class Simple { static int field1; static Simple field2; static int field3; public static void foo() { public static void main(string args[]) { int i = args.length; int j = 7; field1 = i+j; field2 = null; foo(); Virtual Local variable array (max index is 6K-1): Index: 1 2 3 5 Holds params followed by local vars public static void main(java.lang.string[]); Code: : aload_ 1: arraylength 2: istore_1 3: ldc #2; //int 7 5: istore_2 6: iload_1 7: iload_2 : iadd 9: putstatic #3; //Field //field1:i : aconst_null 13: putstatic #; //Field //field2:lsimple; 16: invokestatic #5; //Method foo:()v 19: return

http://www.cs.ucsb.edu/~cs263/lectures/constantpoolexample.pdf Caller Op stack (before call) arg_n arg_1 Ref(C)... Caller Op stack (after call) int... Method call pops args (and instance if not static) upon entry pushes the return type on operand stack when finished (ie it returns) //object is pushed if instance method //argsfor method are pushed invokevirtual #17; //Method T1.m1(arg1,...argN)I Args popped as part of call and placed in callee's local variable array Upon return, return value is pushed on caller's operand stack

Other Things to know/remember Different source compilers implement the same semantics for the same thing aload_1 dup aload_1 aload_1 Constructor methods are instance methods that are statically dispatched! You need not add super() to your constructors (it happens for you) Par(){ //super() only works in constructors; must be first else Error super(); // only add this if you want a different super, e.g. super(int); field3 = 7; The "this" object for instance methods becomes the first argument Simple obj = new Simple(); int i = obj.instmethod(72, "cat"); //arg types: Simple, int, String //when invoked in hardware becomes: call instmethod(obj,72,"cat") //you know its an instance method bc of invokevirtual 16: invokevirtual #2; //method Simple.instMethod(I,LString;)I

Instance fields and Method consume the this object from tos public static void main(java.lang.string[]); Code: : new #6 3: dup : invokespecial #7 7: astore_1 : aload_1 9: getfield #2 : istore_2 13: aload_1 1: bipush 7 16: putfield #2 19: return tos Note that instance field accesses (getfield, putfield) and instant method invocations (invokevirtual, invokespecial) consume the this reference from tos. Operand stack for each instruction on left: class test { int field1 = 2; void testme() { public static void main (String a[]){ test tobj = new test(); int i = tobj.field1; tobj.field1 = 7; : 3: : 7: : Ltest; Ltest; Ltest; Ltest; 9: : 13: 1: 16: int (=2) Ltest; 7 Ltest; Ltest;

Interesting bytecodes and method dispatch specializations class A { static int field1= ; int field2 = 3; int field3 = 7; static int field; static void m1() { void m2() { void m3() { A() { static void main(string args[]) { B.foo(); class B extends A { static int fielda= ; int field2; int fieldc = 2; void m2() { static void m() { final void m5() { B() { static void foo() { A tmpa1 = new A(); A tmpa2 = new B(); tmpa2.m2();

Constructors static void foo(); //javap c B Code: : new #9 // class A 3: dup : invokespecial #6 // Method A."<init>":()V 7: astore_ : new #1 // class B 11: dup : invokespecial #11 // Method "<init>":()v 15: astore_1 16: aload_1 17: invokevirtual # // Method A.m2:()V 2: return class B extends A { static int fielda= ; int field2; int fieldc = 2; void m2() { static void m() { final void m5() { B() { static void foo() { A tmpa1 = new A(); A tmpa2 = new B(); tmpa2.m2();

Java Object Allocation and Construction Object initialization - 2 step process new C - creates a new object instance of class C Instance fields in the object are set to default values invokespecial C:<init> invokes one of C s constructors Can initialize fields to non-default values or perform any arbitrary computation JVM specification requires that this protocol be respected The object returned by new is uninitialized and cannot be used until the initialization method is invoked on it & returns normally Premature use is type-safe since default values are used However, inconsistencies can arise if an object is accessible before the init method has completed Added difficulty, <init> methods don t return an object However, instructor signature (type) shows a void: <init>()v

Object Initialization and Verification x = new C(); new C dup *compute arguments (if any) & put them on the stack* invokespecial C.<init>(arg_1,...,arg_n)V stack arg_n arg_1 Ref(C) Ref(C) invokespecial doesn t return an object Operates by side effect, updates object pointed to by reference Two references (hence the dup instruction) are needed The topmost is consumed by invokespecial The second reference Holds the reference to the initialized object (after invokespecial) This object goes from uninitialized (before the invokespecial) to initialized (after it) Initializer needs not return an object

Interesting bytecodes and method dispatch specializations static void foo(); Code: : new #9 // class A 3: dup : invokespecial #6 // Method A."<init>":()V 7: astore_ : new #1 // class B 11: dup : invokespecial #11 // Method "<init>":()v 15: astore_1 16: aload_1 17: invokevirtual # // Method A.m2:()V 2: return java A output: class A default constructor class A default constructor class B default constructor class B instance method m2() class B extends A { static int fielda= ; int field2; int fieldc = 2; void m2() { static void m() { final void m5() { B() { static void foo() { A tmpa1 = new A(); A tmpa2 = new B(); tmpa2.m2();

Group Formation and Project Vision Statement Groups of size 2 See this link for project ideas Anything related to language runtimes and/or performance is OK http://www.cs.ucsb.edu/~cs263/projects.html Vision statement due in 1 week Names, perms, photos Github repo (that I can access (ckrintz) if private) 1 paragraph on what you will work on Starting next week: by every Friday 5pm Commit something equivalent to 1 lines of code to your repo

Assignment 1 (completed in class) Solutions posted on the web http://www.cs.ucsb.edu/~cs263/sched.html Under today's date set

CS263: Runtime Systems Lecture: High-level language virtual machines Today: Part 2 of 2 Chandra Krintz UCSB Computer Science Department

Mobile, OO Execution Model Execution model embodied by recent PL Implementations Java, all.net languages, scripting languages Object-oriented Program is portable and assumed to be mobile Architecture-independent representation of code and data Incrementally loaded (transfer unit: class, assembly, jar) Data translated from file/class to VM s internal representation» Class model and object model Code is translated to native code interleaved with execution Instruction level (interpretation), method level (JIT compilation), or path level (trace compilation)

Dynamic Class File Loading Lazy: load incrementally as classes are used by the program Convert data to internal representation in memory Upon access, read in the class file or assembly Check that its structure is valid Check whether code is type-safe if language requires it Convert symbols (Java = constant pool) to internal data structures Linking: give target symbols memory locations

Dynamic Class File Loading Lazy: load incrementally as classes are used by the program Convert data to internal representation in memory Upon access, read in the class file or assembly Check that its structure is valid Check whether code is type-safe if language requires it Convert symbols (Java = constant pool) to internal data structures Linking: give target symbols memory locations Table of all static fields and methods of all classes (statics table) Including internal class representations and their maps Keep a map of where you put everything Statics table map Symbol table for names/constants

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { VM STATICS TABLE (Address stored in R7) x72 x72 VM STATICS MAP (stored in known location too, say x3): Name Loc Parent.field1 SF Parent.field2 SF Parent.test1 SM Parent.test2 SM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { VM STATICS TABLE (Address stored in R7) x72 x72 VM STATICS MAP (stored in known location too, say x3): Name Loc Parent.field1 SF Parent.field2 SF Parent.test1 SM Parent.test2 SM Temporary place-holder address for all method bodies before they are compiled -- called a stub For interpreter-only this will ahe address of the bytecode array of the method in memory

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { VM STATICS TABLE (Address stored in R7) x72 x72 VM STATICS MAP (at x3): Name Loc Parent.field1 SF Parent.field2 SF Parent.test1 SM Parent.test2 SM Internal Representation Of Class Parent x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { VM STATICS TABLE (Address stored in R7) VM STATICS MAP (at x3): Name Loc Parent.field1 SF Parent.field2 SF x72 Parent.test1 SM Parent.test2 SM x72 Parent.Type 16 16 x92 Parent.Rep 2 2 x9a Internal Representation Of Class Parent x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { int i = 999999; static void test2() { VM STATICS TABLE (Address stored in R7) VM STATICS MAP (at x3): Name Loc Parent.field1 SF Parent.field2 SF x72 Parent.test1 SM Parent.test2 SM x72 Parent.Type Type 16 16 x92 Parent.Rep Rep 2 2 2 x9a 999999 All other constants from the constant pool of a class go here too! Parent.const1 O 2 Internal Representation Of Class Parent x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF

Review: Static (Class) Methods & Fields Most simple solution: One big table (statics/symbol table) in the runtime Typically, a runtime/class loader populates this as classes are loaded incrementally Keeps a map of symbols à offsets As the translator translates instructions, it uses the statics table map (symbol table) of an accessed class to obtain the offset of the field or method that the code accesses The addresses of which are stored in the statics table For statically or dynamically typed languages

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { Parent.test2(); //invokestatic static void test2() { 16 Parent.field2=7; //putstatic 2 2 VM STATICS TABLE (Address stored in R7) VM STATICS MAP (at x3): Name Loc Parent.field1 SF Parent.field2 SF x72 Parent.test1 SM Parent.test2 SM x72 x92 x9a 999999 Parent.Type Type 16 Parent.Rep Rep 2 Parent.const1 O 2 Internal Representation Of Class Parent x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF

If the language is statically typed Use the static type or cast to figure out which field it is If there is a Parent-Child relationship (OO hierarchy) And there is a field of the same name in both Both are available in the child object Use different variable/types (or use casts) to get to the one you want If the language is dynamically typed Do a hashtable lookup by name at runtime Hashtable per object Review: Instance Fields Lookup gives an index into the object All instance fields stored in the object

Object Layout (Java/C#) The first 2 words of an object is the header Header word 1 Header word 2 Instance Field 1 Instance Field 2... 16 6

Object model VM Support of Static OO PLs Specifies the layout of the object in memory Header: holds information for the runtime For lookup of class (type) For access to lookup tables (dispatch tables, hash tables (python/ruby)) For garbage collection (if any) For locking Store info about whether there is a lock on the object, whether it is contended for, etc. For hashcodes Unique identifier per object in the system The object s identity

Object model VM Support of Static OO PLs Specifies the layout of the object in memory = Internal Class Representation Header: holds information for the runtime For lookup of class (type) For access to lookup tables (dispatch tables, hash tables (python/ruby)) For garbage collection (if any) For locking Store info about whether there is a lock on the object, whether it is contended for, etc. For hashcodes Unique identifier per object in the system The object s identity

Object Layout (Java/C#) The first 2 words of an object is the header Type Ref - type information block (1word ptr to class) Entry in static array that holds a reference to class object Reference to the internal representation of the class Type Ref Other Internal Representation Of Class Parent x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF Field 1 Field 2... 16 9

Object Layout (Java/C#) The first 2 words of an object is the header Type Ref - type information block (1word ptr to class) Entry in static array that holds a reference to class object Reference to the internal representation of the class Other Internal Representation Of Class Parent x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field1 IF field2 IF field1 value field2 value... 16 9

Object Layout (Java/C#) The first 2 words of an object is the header Type Ref - type information block (1word ptr to class) Entry in static array that holds a reference to class object Reference to the internal representation of the class Other field1 value field2 value... 16 Internal Representation Of Class Parent x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field1 IF field2 IF Parent obj = new Parent(); //obj ref on TOS obj.field1 = 7; //putfield consumes TOS 91

Review: Instance Methods If the language is statically typed If the language uses static dispatch (C++, C# when the keyword virtual is NOT used) Use the static type or cast to figure out which field it is If there is a Parent-Child relationship (OO hierarchy) And there is a field of the same name in both» Both are available in the child object (static lookup)» Use different variable/types (or use casts) to get to the one you want Put them in the statics table (and statics table map) Look them up just like we do static fields and static methods Constructors in Java are statically dispatched instance methods! Simple:<init>()V

Review: Instance Methods If the language is statically typed If the language uses static dispatch (C++, C# when the keyword virtual is NOT used) Use the static type or cast to figure out which field it is If there is a Parent-Child relationship (OO hierarchy) And there is a field of the same name in both» Both are available in the child object (static lookup)» Use different variable/types (or use casts) to get to the one you want If the language uses dynamic dispatch (Java, C++/C# with the virtual keyword) Do the lookup at runtime (typically some sort of table/map lookup) Look at object to which the variable refers, check its type (TypeRef) Use its type to figure out which method to invoke (offset of method in object )

Dispatch Tables Every class (in a statically typed language) has a fixed set of virtual instance methods (which includes inherited methods) DTs (aka VMTs) hold addresses to methods Block of native code if compiled Block of bytecode if interpreted A dispatch table indexes these methods AKA virtual method table (VMT) dispatch table = an array of method addresses: entry points A method f lives at a fixed offset in the dispatch table for a class and all of its subclasses The internal class representation holds the offset map 9

Object Layout (Java/C#) Instance fields and instance methods Other Internal Representation Of Class x9a x92 Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field1 IF field2 IF field1 value field2 value... 16 95

Virtual Method Table in JVMs Virtual Method Table (VMT) = Dispatch Table (DT) Store it in the Internal class representation instead of individual objects Because method code doesn t change (inst. field values do) VMT/DT entries are references to code bodies Either bytecode that will be interpreted Or arch-dependent binary if compiled Type Ref Other Field 1 Field 2... Object instances of same class 96 VMT Internal Representation Of Class Class Type Info VM1 VM2 VM3...

Instance Fields and Methods + Inheritance In a statically typed language (Java, C++, C#) Fields and methods cannot be added on the fly Thus we know the layout of all objects For fast lookups, assign fields/methods from top of class hierarchy first: e.g. Great Grandparent, Grand Parent, Parent, then Child A method f lives at a fixed offset in the dispatch table for a class and all of its subclasses Type Ref Other Field 1 Field 2... Object instances of same class 97 VMT Class Type VMClass VM1 VM2 VM3...

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { 16 static void test2() { 2 void test3() { 2 void test() { class Child extends Parent { static int field2 = 1; int field; int field5 = 3; static void test2() { void test() { void test5() { static void main(string args[]) { VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc Parent.field1 SF Parent.field2 SF x72 Parent.test1 SM Parent.test2 SM x72 Child.field2 SF 16 Child.test2 SM 2 1 Child.main SM 2 x72 x72 Method stubs in a compiled runtime Loaded first b/c it has main( ) in it Causes Parent to be loaded right away because Child inherits from Parent And we cannot create the Child s internal rep without its parent s layout

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { class Child extends Parent { static int field2 = 1; int field; int field5 = 3; static void test2() { void test() { void test5() { static void main(string args[]) { Internal Representation Of Class Parent x9a x92 x72 x72 VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM Type Info Map contains offsets in all objects where the instance fields are stored. It ALSO contains offsets into the VMT in the class representation where the virtual instance method addresses are stored.

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { class Child extends Parent { static int field2 = 1; int field; int field5 = 3; static void test2() { void test() { void test5() { static void main(string args[]) { Internal Representation Of Class Parent x9a x92 Internal Representation Of Class Child x91c x72 x72 x975 x72 x72 x72 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 With inheritance, map of child is first loaded with all of the parent parts (fields first) -- fields are hidden not overridden!

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { class Child extends Parent { static int field2 = 1; int field; int field5 = 3; static void test2() { void test() { void test5() { static void main(string args[]) { Internal Representation Of Class Parent x9a x92 Internal Representation Of Class Child x91c x72 x72 x975 x72 x72 x72 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM P.test IM then instance methods - Non-virtual (static dispatch) go in global statics table -Virtual (dynamic dispatch) go in VMT and Type Map (all instance methods in Java are virtual)

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { class Child extends Parent { static int field2 = 1; int field; int field5 = 3; static void test2() { void test() { void test5() { static void main(string args[]) { Internal Representation Of Class Parent x9a x92 Internal Representation Of Class Child x91c x72 x72 x975 x72 x72 x72 VMT VMT then virtual instance methods -- which child can override Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { x72 16 1 static void test2() { 2 x72 void test3() { 2 x72 void test() { class Child extends Parent { static int field2 = 1; int field; int field5 = 3; static void test2() { void test() { void test5() { static void main(string args[]) { VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc Parent.field1 SF Parent.field2 SF x72 Parent.test1 SM Parent.test2 SM Child.field2 SF 16 Child.test2 SM 2 Child.main SM 2 Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { x72 16 1 static void test2() { 2 x72 2 void test3() { x72 2 x92 void test() { 32 x9a 36 x975 class Child extends Parent { x91c static int field2 = 1; int field; int field5 = 3; static void test2() { void test() { void test5() { static void main(string args[]) { VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 Parent.field1 SF Parent.test1 SM Parent.field2 SF Parent.test2 SM Child.field2 SF 16 Child.test2 SM 2 Child.main SM 2 Parent.Type Type 2 Parent.Rep Rep 32 Child.Type Type 36 Child.Rep Rep Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 36 class Child extends Parent { static int field2 = 1; int field; int field5 = 999999; static void test2() { void test() { void test5() { static void main(string args[]) { VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x72 Child.Type Type 36 2 32 x92 x9a Child.Rep Rep Child.const1 O x975 x91c 999999 Constant pool constants are here too!

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 36 class Child extends Parent { static int field2 = 1; int field; int field5 = 999999; static void test2() { 52 void test() { void test5() { static void main(string args[]) { VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x72 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O 32 x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x72 x72 Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 36 class Child extends Parent { static int field2 = 1; int field; int field5 = 999999; static void test2() { 52 void test() { void test5() { static void main(string args[]) { VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O 32 x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x72 x72 x523 Compiled Child.main code Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 36 class Child extends Parent { static int field2 = 1; int field; int field5 = 999999; static void test2() { 52 void test() { void test5() { static void main(string args[]) { Parent l1 = new Parent(); Parent l2 = new Child(); Child l3 = new Child(); VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O 32 x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x79 x72 x523 Compiled Child.main code x79 Compiled Parent.<init>()V code Program execution point (PC, control) Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 36 class Child extends Parent { static int field2 = 1; int field; int field5 = 999999; static void test2() { 52 void test() { void test5() { static void main(string args[]) { Parent l1 = new Parent(); Parent l2 = new Child(); Child l3 = new Child(); VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O 32 x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x79 x72 x523 Compiled Child.main code x79 Compiled Parent.<init>()V code Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 x11 x9a rest of header 7 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 36 class Child extends Parent { static int field2 = 1; int field; int field5 = 999999; static void test2() { 52 void test() { void test5() { static void main(string args[]) { Parent l1 = new Parent(); Parent l2 = new Child(); Child l3 = new Child(); VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O 32 x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x79 x2 x523 Compiled Child.main code Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 x79 Compiled Parent.<init>()V x11 code x9a x2 Compiled Child.<init>()V code rest of header 7 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 36 class Child extends Parent { static int field2 = 1; int field; int field5 = 999999; static void test2() { 52 void test() { void test5() { static void main(string args[]) { Parent l1 = new Parent(); Parent l2 = new Child(); Child l3 = new Child(); VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O 32 x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x79 x2 x523 Compiled Child.main code Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c x975 x72 x72 x72 x79 Compiled Parent.<init>()V x11 code x9a x2 Compiled Child.<init>()V code rest of header 7 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM 16 2 xf x91c rest of header 7 999999

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 32 class Child extends Parent { 36 static int field2 = 1; int field; int field5 = 999999; static void test2() { void test() { 52 void test5() { static void main(string args[]) { Parent l1 = new Parent(); Parent l2 = new Child(); Child l3 = new Child(); VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x79 x2 x11 x9a rest of header Program execution point (PC, control) 7 16 2 Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c xf x91c x975 x72 x72 x72 rest of header 7 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM 16 x1a x91c rest of header 999999 999999 7

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 32 class Child extends Parent { 36 static int field2 = 1; int field; int field5 = 999999; static void test2() { void test() { 52 void test5() { static void main(string args[]) { Parent l1 = new Parent(); Parent l2 = new Child(); Child l3 = new Child(); l3.test3(); VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x79 x2 x11 x9a rest of header Program execution point (PC, control) 7 16 2 Internal Representation Of Class Parent x9a x92 x72 x72 Internal Representation Of Class Child x91c xf x91c x975 x72 x72 x72 rest of header 7 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM 16 x1a x91c rest of header 999999 999999 7

class Parent { static int field1= ; static int field2; int field3 = 7; int field; static void test1() { static void test2() { void test3() { void test() { 32 class Child extends Parent { 36 static int field2 = 1; int field; int field5 = 999999; static void test2() { void test() { 52 void test5() { static void main(string args[]) { Parent l1 = new Parent(); Parent l2 = new Child(); Child l3 = new Child(); l3.test3(); VM STATICS TABLE (Address stored in R7) VM STATICS MAP at x3: Name Loc x72 x72 Parent.field1 SF Parent.test1 SM Child.field2 SF 16 Parent.field2 SF Parent.test2 SM Child.test2 SM 2 16 1 Child.main SM 2 Parent.Type Type 2 2 x72 Parent.Rep Rep 32 2 x523 Child.Type Type 36 2 x92 Child.Rep Rep Child.const1 O x9a Parent.<init>()V SIM Child.<init>()V SIM 52 x975 x91c 999999 x79 x2 x11 x9a rest of header Program execution point (PC, control) 7 x61 Compiled Parent.test3 code 16 2 Internal Representation Of Class Parent x9a x92 x61 x72 Internal Representation Of Class Child x91c xf x91c x975 x61 x72 x72 rest of header 7 VMT VMT Class Type Info Object x92 Parent Type Info PARENT MAP: Name Loc field3 IF field IF test3 IM test IM x975 Child Type Info CHILD MAP: Name Loc P.field3 IF P.field IF C.field IF 16 C.field5 IF 2 P.test3 IM C.test IM C.test5 IM 16 x1a x91c rest of header 999999 999999 7