Eelco Visser
CS4200 Compiler Construction
TU Delft
November 2018
Lecture 12: Programming (Virtual) Machines
- (Virtual) machine architecture 

‣ In particular: Java Virtual Machine

- Machine instructions

- Encoding linguistic abstractions

- Optimizing generated code

Linguistic Abstraction
- High-level programming languages abstract from low-level machine
mechanics

- Abstractions in imperative and object-oriented languages

- Calling Conventions

- Register machines vs stack machines
!2
Virtual Machines
Stack frames in the Java Virtual Machine
- parameter passing, returning results

- implementation strategies

Stack frames in register-based machines
- registers x86 family

- manipulating stack registers

- calling conventions

Optimizations
!3
Summary
Reading Material
4
!5
Programmable Computing
Machines
6
Hard-Wired Programs
!7
https://commons.wikimedia.org/wiki/File:Wiring_diagram_of_battery-powered_doorbell.JPG
Fixed to perform one computation
from input to output
Programmable Machines
!8
ENIAC (Electronic Numerical Integrator And Computer) in
Philadelphia, Pennsylvania. Glen Beck (background) and Betty
Snyder (foreground) program the ENIAC in building 328 at the
Ballistic Research Laboratory (BRL).
https://en.wikipedia.org/wiki/ENIAC#/media/File:Eniac.jpg
Machine is programmed by creating data
path using wires
Central Processing Unit
- Processor registers

- Arithmetic logic unit

Main Memory
- Stores data and instructions

External Storage
- Persistent storage of data

Input/Output
!9
Stored-Program Computer (Von Neumann Architecture)
https://en.wikipedia.org/wiki/Von_Neumann_architecture#/media/File:Von_Neumann_Architecture.svg
State & Control
10
Machine state
- data stored in memory

- memory hierarchy: registers, RAM, disk, network, … 

Imperative program
- computation is series of changes to memory

- basic operations on memory (increment register)

- controlling such operations (jump, return address, …)

- control represented by state (program counter, stack, …)
!11
State
General purpose registers
- accumulator AX - arithmetic operations

- counter CX - shift/rotate instructions, loops

- data DX - arithmetic operations, I/O

- base BX - pointer to data

- stack pointer SP, base pointer BP - top and base of stack

- source SI, destination DI - stream operations

Special purpose registers
- segments SS, CS, DS, ES, FS, GS

- flags EFLAGS
!12
Registers: x86 Family
Example: x86 Assembler
!13
mov AX [1]
mov CX AX
L: dec CX
mul CX
cmp CX 1
ja L
mov [2] AX
read memory
write memory
calculation
jump
Example: Java Bytecode
!14
.method static public m(I)I
iload 1
ifne else
iconst_1
ireturn
else: iload 1
dup
iconst_1
isub
invokestatic Math/m(I)I
imul
ireturn
read memory
calculation
jump
Memory abstractions
- variables: abstract over data storage

- expressions: combine data into new data

- assignment: abstract over storage operations

Control-flow abstractions
- structured control-flow: abstract over unstructured jumps

- ‘go to statement considered harmful’ Edgser Dijkstra, 1968
!15
Memory & Control Abstractions
Example: C
!16
int f = 1
int x = 5
int s = f + x
while (x > 1) {
f = x * f ;
x = x - 1
}
variable
expression
assignment
control flow
Example: Tiger
!17
/* factorial function */
let
var f := 1
var x := 5
var s := f + x
in
while x > 1 do (
f := x * f ;
x := x - 1
)
end
variable
expression
assignment
control flow
Procedures
18
Control-flow abstraction
- Procedure: named unit of computation

- Procedure call: jump to unit of computation and return

Memory abstraction
- Formal parameter: the name of the parameter

- Actual parameter: value that is passed to procedure

- Local variable: temporary memory

Recursion
- Procedure may (indirectly) call itself

- Consequence?
!19
Procedural Abstraction
Example: Procedures in C
!20
#include <stio.h>
/* factorial function */
int fac( int num ) {
if (num < 1)
return 1;
else
return num * fac(num - 1) ;
}
int main() {
int x = 10 ;
int f = fac( x ) ;
int x printf(“%d! = %dn”, x, f);
return 0;
}
formal parameter
actual parameter
local variable
recursive call
Procedures in Tiger
!21
/* factorial function */
let
function fac( n: int ) : int =
let
var f := 1
in
if n < 1 then
f := 1
else
f := (n * fac(n - 1) );
f
end
var f := 0
var x := 5
in
f := fac( x )
end
formal parameter
actual parameter
local variable
recursive call
Stack
- temporary storage

- grows from high to low memory addresses

- starts at SS

Stack frames
- return address

- local variables

- parameters

- stack base: BP

- stack top: SP
!22
Implementing Procedures with Stack and Stack Frames
General purpose registers
- accumulator AX - arithmetic operations

- counter CX - shift/rotate instructions, loops

- data DX - arithmetic operations, I/O

- base BX - pointer to data

- stack pointer SP, base pointer BP - top and base of stack

- source SI, destination DI - stream operations

Special purpose registers
- segments SS, CS, DS, ES, FS, GS

- flags EFLAGS
!23
Registers in x86 Family
Example: Procedures in x86 Assembler
!24
push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
pass parameter
access parameter
new stack frame
old stack frame
free parameters
Caller
- push parameters right-to-left on the stack

- clean-up stack after call 

Callee
- save old BP

- initialise new BP

- save registers

- return result in AX

- restore registers

- restore BP
!25
Calling Conventions: CDECL
push 21
push 42
call _f
add ESP 8
push EBP
mov EBP ESP
mov EAX [EBP + 8]
mov EDX [EBP + 12]
add EAX EDX
pop EBP
ret
caller
- push parameters right-to-left on the stack

callee
- save old BP

- initialise new BP

- save registers

- return result in AX

- restore registers

- restore BP
!26
Calling Conventions: STDECL
push 21
push 42
call _f@8
push EBP
mov EBP ESP
mov EAX [EBP + 8]
mov EDX [EBP + 12]
add EAX EDX
pop EBP
ret 8
Caller
- passes parameters in registers

- pushes additional parameters right-to-left 

on the stack

Callee
- save old BP, initialise new BP

- save registers

- return result in AX

- restore registers

- restore BP

- cleans up the stack
!27
Calling Conventions: FASTCALL
mov ECX 21
mov EDX 42
call @f@8
push EBP
mov EBP ESP
mov EAX ECX
add EAX EDX
pop EBP
ret
Procedure declarations
- in principle: full freedom

- project constraints

- target platform constraints

Procedure calls
- need to match procedure declarations

Precompiled libraries
- avoid recompilation

- source code not always available

Standardization
- compilers / high-level languages standardize use of calling conventions

- portable code: does not depend on particular calling convention
!28
Calling Conventions
Object-Oriented Languages
29
Objects
- Generalization of records

- Identity

- State

- Behaviour

Messages
- Objects send and receive messages

- Trigger behaviour

- Imperative realisation: method calls
!30
Modularity: Objects & Messages
Classes
- Generalization of record types

- Characteristics of objects: attributes, fields, properties

- Behaviour of objects: methods, operations, features

Encapsulation
- Interface exposure

- Hide attributes & methods

- Hide implementation
!31
Modularity: Classes
public class C {
public int f1;
private int f2;
public void m1() { return; }
private C m2(C c) { return c; }
}
Inheritance
- Inherit attributes & methods

- Additional attributes & methods

- Override behaviour

- Nominal subtyping

Interfaces
- Avoid multiple inheritance 

- Interface: contract for attributes & methods

- Class: provide attributes & methods

- Nominal subtyping
!32
Inheritance vs Interfaces
public class C {
public int f1;
public void m1() {…}
public void m2() {…}
}
public class D extends C {
public int f2;
public void m2() {…}
public void m3() {…}
}
public interface I {
public int f;
public void m();
}
public class E implements I
{
public int f;
public void m() {…}
public void m’() {…}
}
Ad-hoc polymorphism
- Overloading

‣ same method name, independent classes

‣ same method name, same class, different parameter types

- Overriding

‣ same method name, subclass, compatible types 

Universal polymorphism
- Subtype polymorphism

‣ inheritance, interfaces

- Parametric polymorphism
!33
Polymorphism
Dispatch
- link method call to method

Static dispatch
- type information at compile-time

Dynamic dispatch
- type information at run-time

- single dispatch: one parameter

- multiple dispatch: more parameters
!34
Static vs. Dynamic Dispatch
Single Dispatch in Java
!35
public class A {}
public class B extends A {}
public class C extends B {}
public class D {
public A m(A a) { System.out.println("D.m(A a)"); return a; }
public A m(B b) { System.out.println("D.m(B b)"); return b; }
}
public class E extends D {
public A m(A a) { System.out.println("E.m(A a)"); return a; }
public B m(B b) { System.out.println("E.m(B b)"); return b; }
}
A a = new A(); B b = new B(); C c = new C(); D d = new D(); E e = new E();
A ab = b; A ac = c; D de = e;
d. m(a); d. m(b); d. m(ab); d. m(c); d. m(ac);
e. m(a); e. m(b); e. m(ab); e. m(c); e. m(ac);
de.m(a); de.m(b); de.m(ab); de.m(c); de.m(ac);
Methods
- parameter types

- return type

Covariance
- method in subclass

- return type: subtype of original return type

Contravariance
- method in subclass

- parameter types: supertypes of original parameter types
!36
Overriding
Overloading vs Overriding
!37
public class F {
public A m(B b) { System.out.println("F.m(B b)"); return b; }
}
public class G extends F {
public A m(A a) { System.out.println("G.m(A a)"); return a; }
}
public class H extends F {
public B m(B b) { System.out.println("H.m(B b)"); return b; }
}
A a = new A(); B b = new B(); F f = new F(); G g = new G(); H h = new H();
A ab = b;
f.m(b);
g.m(a); g.m(b); g.m(ab);
h.m(a); h.m(b); h.m(ab);
Invariance
!38
public class X {
public A a;
public A getA() { return a ; }
public void setA(A a) { this.a = a ; }
}
public class Y extends X {
public B a;
public B getA() { return a ; }
public void setA(B a) { this.a = a ; }
}
A a = new A(); B b = new B(); X y = new Y();
y.getA(); y.setA(b); y.setA(a); y.getA();
String[] s = new String[3] ; Object[] o = s ; o[1] = new A();
Summary: Abstractions
39
Imperative languages
- subroutines, routines, procedures, functions, methods

- scoping: local variables

- declarations with parameters (formal parameters)

- calls with arguments (actual parameters)

- pass by value, pass by reference 

Machine code
- jumps: call and return

- call stack: return address, parameters, private data

- procedure prologue and epilogue
!40
Abstractions for Memory and Control
Imperative languages
- state & statements

- abstraction over machine code

- control flow & procedures

- types

Object-oriented languages
- objects & messages

- classes

- inheritance

- types
!41
Imperative vs Object-Oriented
Java Virtual Machine:
Architecture
42
JVM Architecture
!43
JVM Architecture: Threads
!44
Each thread has its own program counter (PC)
JVM Architecture: Thread
!45
JVM Architecture: Stack
!46
JVM Architecture: Heap
!47
JVM Architecture: Method Area
!48
JVM Architecture: JVM Stack
!49
JVM: Control Flow
50
Bytecode Instructions: Goto
!51
pc: 00
method area
00
01
02
03
04
05
06
A7
00
04
00
A7
FF
FF
goto
04
nop
goto
03
Bytecode Instructions: Goto
!52
pc: 04
method area
00
01
02
03
04
05
06
A7
00
04
00
A7
FF
FF
goto
04
nop
goto
03
Bytecode Instructions: Goto
!53
pc: 03
method area
00
01
02
03
04
05
06
A7
00
04
00
A7
FF
FF
goto
04
nop
goto
03
Bytecode Instructions: Goto
!54
pc: 04
method area
00
01
02
03
04
05
06
A7
00
04
00
A7
FF
FF
goto
04
nop
goto
03
JVM: Operand Stack
55
Operand Stack
!56
pc: 00
00
01
02
03
04
05
06
pc: 00 optop: 00
00
01
02
03
04
05
06
04
05
10
2A
11
43
03
iconst_1
iconst_2
bipush
sipush
method area stack
Operand Stack
!57
optop: 01pc: 01
00
01
02
03
04
05
06
0000 000100
01
02
03
04
05
06
04
05
10
2A
11
43
03
iconst_1
iconst_2
bipush
sipush
method area stack
Operand Stack
!58
optop: 02pc: 02
00
01
02
03
04
05
06
0000 0001
0000 0002
00
01
02
03
04
05
06
04
05
10
2A
11
43
03
iconst_1
iconst_2
bipush
sipush
method area stack
Operand Stack
!59
optop: 03pc: 04
00
01
02
03
04
05
06
0000 0001
0000 0002
0000 002A
00
01
02
03
04
05
06
04
05
10
2A
11
43
03
iconst_1
iconst_2
bipush
sipush
method area stack
Operand Stack
!60
optop: 04pc: 07
00
01
02
03
04
05
06
0000 0001
0000 0002
0000 002A
0000 4303
00
01
02
03
04
05
06
04
05
10
2A
11
43
03
iconst_1
iconst_2
bipush
sipush
method area stack
Operand Stack
!61
optop: 04
00
01
02
03
04
05
06
0000 0001
0000 0002
0000 002A
0000 4303
pc: 07
07
08
09
0A
0B
0C
0D
60
68
5F
64
9A
FF
F5
iadd
imul
swap
isub
ifne
00
method area stack
Operand Stack
!62
optop: 03
00
01
02
03
04
05
06
0000 0001
0000 0002
0000 432D
pc: 08
07
08
09
0A
0B
0C
0D
60
68
5F
64
9A
FF
F5
iadd
imul
swap
isub
ifne
00
method area stack
Operand Stack
!63
optop: 02
00
01
02
03
04
05
06
0000 0001
0000 865A
pc: 09
07
08
09
0A
0B
0C
0D
60
68
5F
64
9A
FF
F5
iadd
imul
swap
isub
ifne
00
method area stack
Operand Stack
!64
optop: 02
00
01
02
03
04
05
06
0000 865A
0000 0001
pc: 0A
07
08
09
0A
0B
0C
0D
60
68
5F
64
9A
FF
F5
iadd
imul
swap
isub
ifne
00
method area stack
Operand Stack
!65
optop: 01
00
01
02
03
04
05
06
0000 8659
pc: 0B
07
08
09
0A
0B
0C
0D
60
68
5F
64
9A
FF
F5
iadd
imul
swap
isub
ifne
00
method area stack
Operand Stack
!66
00
01
02
03
04
05
06
pc: 00 optop: 00
00
01
02
03
04
05
06
04
05
10
2A
11
43
03
iconst_1
iconst_2
bipush
sipush
method area stack
JVM: Constant Pool
67
Constant Pool
!68
pc: 00
method area stack
00
01
02
03
04
05
06
12
00
12
01
14
00
02
ldc
00
ldc
01
ldc2_w
02
00
01
02
03
04
05
06
constant pool
00
01
02
03
04
05
06
0000 002A
0000 4303
0000 0000
0000 002A
optop: 00
Constant Pool
!69
pc: 02
method area stack
00
01
02
03
04
05
06
12
00
12
01
14
00
02
ldc
00
ldc
01
ldc2_w
02
00
01
02
03
04
05
06
0000 002A
constant pool
00
01
02
03
04
05
06
0000 002A
0000 4303
0000 0000
0000 002A
optop: 01
Constant Pool
!70
pc: 04
method area stack
00
01
02
03
04
05
06
12
00
12
01
14
00
02
ldc
00
ldc
01
ldc2_w
02
00
01
02
03
04
05
06
0000 002A
0000 4303
constant pool
00
01
02
03
04
05
06
0000 002A
0000 4303
0000 0000
0000 002A
optop: 02
Constant Pool
!71
pc: 07
method area stack
00
01
02
03
04
05
06
12
00
12
01
14
00
02
ldc
00
ldc
01
ldc2_w
02
00
01
02
03
04
05
06
0000 002A
0000 4303
0000 0000
0000 002A
constant pool
00
01
02
03
04
05
06
0000 002A
0000 4303
0000 0000
0000 002A
optop: 04
JVM: Local Variables
72
Local Variables
!73
pc: 00
method area stack
00
01
02
03
04
05
06
04
3B
1A
3C
84
01
01
iconst_1
istore_0
iload_0
istore_1
iinc
01
01
00
01
02
03
04
05
06
local variables
00
01
02
03
04
05
06
optop: 00
Local Variables
!74
pc: 01
00
01
02
03
04
05
06
0000 0001
method area stack
00
01
02
03
04
05
06
04
3B
1A
3C
84
01
01
iconst_1
istore_0
iload_0
istore_1
iinc
01
01
local variables
00
01
02
03
04
05
06
optop: 01
Local Variables
!75
pc: 02
00
01
02
03
04
05
06
method area stack
00
01
02
03
04
05
06
04
3B
1A
3C
84
01
01
iconst_1
istore_0
iload_0
istore_1
iinc
01
01
local variables
00
01
02
03
04
05
06
0000 0001
optop: 00
Local Variables
!76
pc: 03
00
01
02
03
04
05
06
0000 0001
method area stack
00
01
02
03
04
05
06
04
3B
1A
3C
84
01
01
iconst_1
istore_0
iload_0
istore_1
iinc
01
01
local variables
00
01
02
03
04
05
06
0000 0001
optop: 01
Local Variables
!77
pc: 04
00
01
02
03
04
05
06
method area stack
00
01
02
03
04
05
06
04
3B
1A
3C
84
01
01
iconst_1
istore_0
iload_0
istore_1
iinc
01
01
local variables
00
01
02
03
04
05
06
0000 0001
0000 0001
optop: 00
Local Variables
!78
pc: 07
00
01
02
03
04
05
06
method area stack
00
01
02
03
04
05
06
04
3B
1A
3C
84
01
01
iconst_1
istore_0
iload_0
istore_1
iinc
01
01
local variables
00
01
02
03
04
05
06
0000 0001
0000 0002
optop: 00
JVM: Heap
79
Heap
!80
pc: 00
method area stack
heap
4303 4303 "Compilers" 002A 002A [20,01,40,02,42]
00
01
02
03
04
05
06
12
00
19
00
12
01
2E
ldc
00
aload
00
ldc
01
iaload
00
01
02
03
04
05
06
constant pool
00
01
02
03
04
05
06
4303 4303
0000 0004
local variables
00
01
02
03
04
05
06
002A 002A
optop: 00
Heap
!81
pc: 02
method area stack
heap
4303 4303 "Compilers" 002A 002A [20,01,40,02,42]
00
01
02
03
04
05
06
12
00
19
00
12
01
2E
ldc
00
aload
00
ldc
01
iaload
00
01
02
03
04
05
06
4303 4303
constant pool
00
01
02
03
04
05
06
4303 4303
0000 0004
local variables
00
01
02
03
04
05
06
002A 002A
optop: 01
Heap
!82
pc: 04
method area stack
heap
4303 4303 "Compilers" 002A 002A [20,01,40,02,42]
00
01
02
03
04
05
06
12
00
19
00
12
01
2E
ldc
00
aload
00
ldc
01
iaload
00
01
02
03
04
05
06
4303 4303
002A 002A
constant pool
00
01
02
03
04
05
06
4303 4303
0000 0004
local variables
00
01
02
03
04
05
06
002A 002A
optop: 02
Heap
!83
pc: 06
method area stack
heap
4303 4303 "Compilers" 002A 002A [20,01,40,02,42]
00
01
02
03
04
05
06
12
00
19
00
12
01
2E
ldc
00
aload
00
ldc
01
iaload
00
01
02
03
04
05
06
4303 4303
002A 002A
0000 0004
constant pool
00
01
02
03
04
05
06
4303 4303
0000 0004
local variables
00
01
02
03
04
05
06
002A 002A
optop: 03
Heap
!84
pc: 07
method area stack
heap
4303 4303 "Compilers" 002A 002A [20,01,40,02,42]
00
01
02
03
04
05
06
12
00
19
00
12
01
2E
ldc
00
aload
00
ldc
01
iaload
00
01
02
03
04
05
06
4303 4303
0000 0042
constant pool
00
01
02
03
04
05
06
4303 4303
0000 0004
local variables
00
01
02
03
04
05
06
002A 002A
optop: 02
JVM: Stack Frames
85
Dispatch
- link method call to method

Static dispatch
- based on type information at compile-time

Dynamic dispatch
- based on type information at run-time

- single dispatch: one parameter

- multiple dispatch: more parameters
!86
Static vs. Dynamic Dispatch
Example: Static Call
!87
.class public Exp
.method public static fac(I)I
iload 1
ifne else
iconst_1
ireturn
else: iload 1
dup
iconst_1
isub
invokestatic Exp/fac(I)I
imul
ireturn
.end method
function fac(n: int): int =
if
n = 0
then
1
else
n * fac(n - 1)
Example: Dynamic Call
!88
.class public Exp
.method public fac(I)I
iload 1
ifne else
iconst_1
ireturn
else: iload 0
iload 1
dup
iconst_1
isub
invokevirtual Exp/fac(I)I
imul
ireturn
.end method
function fac(n: int): int =
if
n = 0
then
1
else
n * fac(n - 1)
Caller
- push reference to receiver object 

- push parameters left-to-right

- call method 

Virtual machine on call
- allocate space (frame data, operand stack, local variables)

- store frame data (data pointer, return address, exception table) 

- store parameters as local variables

- dynamic dispatch

- point pc to method code
!89
Code Pattern: Dynamic Method Call
Callee
- parameters in local variables

- leave result on operand stack

- return to caller

Virtual machine on return
- push result on caller’s operand stack

- point pc to return address

- destroy frame
!90
Code Pattern: Return from Method Call
Implementation: Heap-Based
!91
3
frame
data
3
2
fac(3)
2
frame
data
fac(2)
1
frame
data
fac(1)
22
21
11
1
function fac(n: int): int =
if
n = 0
then
1
else
n * fac(n - 1)
Implementation: Stack-Based
!92
3
frame
data
3
2
fac(3)
2
frame
data
fac(2)
22
2
1
111
frame
data
fac(1)
11
function fac(n: int): int =
if
n = 0
then
1
else
n * fac(n - 1)
Stack Frames
!93
00
01
02
03
04
05
06
2A
10
40
B6
00
01
AC
aload_0
bipush
invokevirtual
01
ireturn
optop: 02
method area stack
heap
00
01
02
03
04
05
06
4303 4303
0000 0040
local variables
00
01
02
03
04
05
06
4303 4303
pc: 03
Stack Frames
!94
pc: 80
80
81
82
83
84
85
86
2B
59
68
AC
00
00
00
iload_1
dup
imul
ireturn
optop: 01
method area stack
heap
00
01
02
03
04
05
06
4303 4303
0000 0040
local variables
00
01
02
03
04
05
06
4303 4303
local variables
00
01
02
03
04
05
06
4303 4303
0000 0040
optop: 00
stack
00
01
02
03
04
05
06
Stack Frames
!95
pc: 81
80
81
82
83
84
85
86
2B
59
68
AC
00
00
00
iload_1
dup
imul
ireturn
optop: 01
method area stack
heap
00
01
02
03
04
05
06
4303 4303
0000 0040
local variables
00
01
02
03
04
05
06
4303 4303
local variables
00
01
02
03
04
05
06
4303 4303
0000 0040
optop: 01
stack
00
01
02
03
04
05
06
0000 0040
Stack Frames
!96
pc: 81
80
81
82
83
84
85
86
2B
59
68
AC
00
00
00
iload_1
dup
imul
ireturn
optop: 01
method area stack
heap
00
01
02
03
04
05
06
4303 4303
0000 0040
local variables
00
01
02
03
04
05
06
4303 4303
local variables
00
01
02
03
04
05
06
4303 4303
0000 0040
optop: 02
stack
00
01
02
03
04
05
06
0000 0040
0000 0040
Stack Frames
!97
pc: 82
80
81
82
83
84
85
86
2B
59
68
AC
00
00
00
iload_1
dup
imul
ireturn
optop: 01
method area stack
heap
00
01
02
03
04
05
06
4303 4303
0000 0040
local variables
00
01
02
03
04
05
06
4303 4303
local variables
00
01
02
03
04
05
06
4303 4303
0000 0040
optop: 01
stack
00
01
02
03
04
05
06
0000 1000
Stack Frames
!98
00
01
02
03
04
05
06
2A
10
40
B6
00
01
AC
aload_0
bipush
invokevirtual
01
ireturn
optop: 01
method area stack
heap
00
01
02
03
04
05
06
0000 1000
local variables
00
01
02
03
04
05
06
4303 4303
pc: 06
JVM: Class Files
99
Java Compiler
!100
> ls
Course.java
> javac -verbose Course.java
[parsing started Course.java]
[parsing completed 8ms]
[loading java/lang/Object.class(java/lang:Object.class)]
[checking university.Course]
[wrote Course.class]
[total 411ms]
> ls
Course.class Course.java
Class Files: Format
!101
magic number CAFEBABE
class file version (minor, major)
constant pool count + constant pool
access flags
this class
super class
interfaces count + interfaces
fields count + fields
methods count + methods
attribute count + attributes
Jasmin Intermediate Language
!102
.class public Exp
.method public static fac(I)I
iload 1
ifne else
iconst_1
ireturn
else: iload 1
dup
iconst_1
isub
invokestatic Exp/fac(I)I
imul
ireturn
.end method
Next: Code Generation
103
!104
Except where otherwise noted, this work is licensed under

Compiler Construction | Lecture 12 | Virtual Machines

  • 1.
    Eelco Visser CS4200 CompilerConstruction TU Delft November 2018 Lecture 12: Programming (Virtual) Machines
  • 2.
    - (Virtual) machinearchitecture ‣ In particular: Java Virtual Machine - Machine instructions - Encoding linguistic abstractions - Optimizing generated code Linguistic Abstraction - High-level programming languages abstract from low-level machine mechanics - Abstractions in imperative and object-oriented languages - Calling Conventions - Register machines vs stack machines !2 Virtual Machines
  • 3.
    Stack frames inthe Java Virtual Machine - parameter passing, returning results - implementation strategies Stack frames in register-based machines - registers x86 family - manipulating stack registers - calling conventions Optimizations !3 Summary
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
    Programmable Machines !8 ENIAC (ElectronicNumerical Integrator And Computer) in Philadelphia, Pennsylvania. Glen Beck (background) and Betty Snyder (foreground) program the ENIAC in building 328 at the Ballistic Research Laboratory (BRL). https://en.wikipedia.org/wiki/ENIAC#/media/File:Eniac.jpg Machine is programmed by creating data path using wires
  • 9.
    Central Processing Unit -Processor registers - Arithmetic logic unit Main Memory - Stores data and instructions External Storage - Persistent storage of data Input/Output !9 Stored-Program Computer (Von Neumann Architecture) https://en.wikipedia.org/wiki/Von_Neumann_architecture#/media/File:Von_Neumann_Architecture.svg
  • 10.
  • 11.
    Machine state - datastored in memory - memory hierarchy: registers, RAM, disk, network, … Imperative program - computation is series of changes to memory - basic operations on memory (increment register) - controlling such operations (jump, return address, …) - control represented by state (program counter, stack, …) !11 State
  • 12.
    General purpose registers -accumulator AX - arithmetic operations - counter CX - shift/rotate instructions, loops - data DX - arithmetic operations, I/O - base BX - pointer to data - stack pointer SP, base pointer BP - top and base of stack - source SI, destination DI - stream operations Special purpose registers - segments SS, CS, DS, ES, FS, GS - flags EFLAGS !12 Registers: x86 Family
  • 13.
    Example: x86 Assembler !13 movAX [1] mov CX AX L: dec CX mul CX cmp CX 1 ja L mov [2] AX read memory write memory calculation jump
  • 14.
    Example: Java Bytecode !14 .methodstatic public m(I)I iload 1 ifne else iconst_1 ireturn else: iload 1 dup iconst_1 isub invokestatic Math/m(I)I imul ireturn read memory calculation jump
  • 15.
    Memory abstractions - variables:abstract over data storage - expressions: combine data into new data - assignment: abstract over storage operations Control-flow abstractions - structured control-flow: abstract over unstructured jumps - ‘go to statement considered harmful’ Edgser Dijkstra, 1968 !15 Memory & Control Abstractions
  • 16.
    Example: C !16 int f= 1 int x = 5 int s = f + x while (x > 1) { f = x * f ; x = x - 1 } variable expression assignment control flow
  • 17.
    Example: Tiger !17 /* factorialfunction */ let var f := 1 var x := 5 var s := f + x in while x > 1 do ( f := x * f ; x := x - 1 ) end variable expression assignment control flow
  • 18.
  • 19.
    Control-flow abstraction - Procedure:named unit of computation - Procedure call: jump to unit of computation and return Memory abstraction - Formal parameter: the name of the parameter - Actual parameter: value that is passed to procedure - Local variable: temporary memory Recursion - Procedure may (indirectly) call itself - Consequence? !19 Procedural Abstraction
  • 20.
    Example: Procedures inC !20 #include <stio.h> /* factorial function */ int fac( int num ) { if (num < 1) return 1; else return num * fac(num - 1) ; } int main() { int x = 10 ; int f = fac( x ) ; int x printf(“%d! = %dn”, x, f); return 0; } formal parameter actual parameter local variable recursive call
  • 21.
    Procedures in Tiger !21 /*factorial function */ let function fac( n: int ) : int = let var f := 1 in if n < 1 then f := 1 else f := (n * fac(n - 1) ); f end var f := 0 var x := 5 in f := fac( x ) end formal parameter actual parameter local variable recursive call
  • 22.
    Stack - temporary storage -grows from high to low memory addresses - starts at SS Stack frames - return address - local variables - parameters - stack base: BP - stack top: SP !22 Implementing Procedures with Stack and Stack Frames
  • 23.
    General purpose registers -accumulator AX - arithmetic operations - counter CX - shift/rotate instructions, loops - data DX - arithmetic operations, I/O - base BX - pointer to data - stack pointer SP, base pointer BP - top and base of stack - source SI, destination DI - stream operations Special purpose registers - segments SS, CS, DS, ES, FS, GS - flags EFLAGS !23 Registers in x86 Family
  • 24.
    Example: Procedures inx86 Assembler !24 push 21 push 42 call _f add SP 8 push BP mov BP SP mov AX [BP + 8] mov DX [BP + 12] add AX DX pop BP ret pass parameter access parameter new stack frame old stack frame free parameters
  • 25.
    Caller - push parametersright-to-left on the stack - clean-up stack after call Callee - save old BP - initialise new BP - save registers - return result in AX - restore registers - restore BP !25 Calling Conventions: CDECL push 21 push 42 call _f add ESP 8 push EBP mov EBP ESP mov EAX [EBP + 8] mov EDX [EBP + 12] add EAX EDX pop EBP ret
  • 26.
    caller - push parametersright-to-left on the stack callee - save old BP - initialise new BP - save registers - return result in AX - restore registers - restore BP !26 Calling Conventions: STDECL push 21 push 42 call _f@8 push EBP mov EBP ESP mov EAX [EBP + 8] mov EDX [EBP + 12] add EAX EDX pop EBP ret 8
  • 27.
    Caller - passes parametersin registers - pushes additional parameters right-to-left 
 on the stack Callee - save old BP, initialise new BP - save registers - return result in AX - restore registers - restore BP - cleans up the stack !27 Calling Conventions: FASTCALL mov ECX 21 mov EDX 42 call @f@8 push EBP mov EBP ESP mov EAX ECX add EAX EDX pop EBP ret
  • 28.
    Procedure declarations - inprinciple: full freedom - project constraints - target platform constraints Procedure calls - need to match procedure declarations Precompiled libraries - avoid recompilation - source code not always available Standardization - compilers / high-level languages standardize use of calling conventions - portable code: does not depend on particular calling convention !28 Calling Conventions
  • 29.
  • 30.
    Objects - Generalization ofrecords - Identity - State - Behaviour Messages - Objects send and receive messages - Trigger behaviour - Imperative realisation: method calls !30 Modularity: Objects & Messages
  • 31.
    Classes - Generalization ofrecord types - Characteristics of objects: attributes, fields, properties - Behaviour of objects: methods, operations, features Encapsulation - Interface exposure - Hide attributes & methods - Hide implementation !31 Modularity: Classes public class C { public int f1; private int f2; public void m1() { return; } private C m2(C c) { return c; } }
  • 32.
    Inheritance - Inherit attributes& methods - Additional attributes & methods - Override behaviour - Nominal subtyping Interfaces - Avoid multiple inheritance - Interface: contract for attributes & methods - Class: provide attributes & methods - Nominal subtyping !32 Inheritance vs Interfaces public class C { public int f1; public void m1() {…} public void m2() {…} } public class D extends C { public int f2; public void m2() {…} public void m3() {…} } public interface I { public int f; public void m(); } public class E implements I { public int f; public void m() {…} public void m’() {…} }
  • 33.
    Ad-hoc polymorphism - Overloading ‣same method name, independent classes ‣ same method name, same class, different parameter types - Overriding ‣ same method name, subclass, compatible types Universal polymorphism - Subtype polymorphism ‣ inheritance, interfaces - Parametric polymorphism !33 Polymorphism
  • 34.
    Dispatch - link methodcall to method Static dispatch - type information at compile-time Dynamic dispatch - type information at run-time - single dispatch: one parameter - multiple dispatch: more parameters !34 Static vs. Dynamic Dispatch
  • 35.
    Single Dispatch inJava !35 public class A {} public class B extends A {} public class C extends B {} public class D { public A m(A a) { System.out.println("D.m(A a)"); return a; } public A m(B b) { System.out.println("D.m(B b)"); return b; } } public class E extends D { public A m(A a) { System.out.println("E.m(A a)"); return a; } public B m(B b) { System.out.println("E.m(B b)"); return b; } } A a = new A(); B b = new B(); C c = new C(); D d = new D(); E e = new E(); A ab = b; A ac = c; D de = e; d. m(a); d. m(b); d. m(ab); d. m(c); d. m(ac); e. m(a); e. m(b); e. m(ab); e. m(c); e. m(ac); de.m(a); de.m(b); de.m(ab); de.m(c); de.m(ac);
  • 36.
    Methods - parameter types -return type Covariance - method in subclass - return type: subtype of original return type Contravariance - method in subclass - parameter types: supertypes of original parameter types !36 Overriding
  • 37.
    Overloading vs Overriding !37 publicclass F { public A m(B b) { System.out.println("F.m(B b)"); return b; } } public class G extends F { public A m(A a) { System.out.println("G.m(A a)"); return a; } } public class H extends F { public B m(B b) { System.out.println("H.m(B b)"); return b; } } A a = new A(); B b = new B(); F f = new F(); G g = new G(); H h = new H(); A ab = b; f.m(b); g.m(a); g.m(b); g.m(ab); h.m(a); h.m(b); h.m(ab);
  • 38.
    Invariance !38 public class X{ public A a; public A getA() { return a ; } public void setA(A a) { this.a = a ; } } public class Y extends X { public B a; public B getA() { return a ; } public void setA(B a) { this.a = a ; } } A a = new A(); B b = new B(); X y = new Y(); y.getA(); y.setA(b); y.setA(a); y.getA(); String[] s = new String[3] ; Object[] o = s ; o[1] = new A();
  • 39.
  • 40.
    Imperative languages - subroutines,routines, procedures, functions, methods - scoping: local variables - declarations with parameters (formal parameters) - calls with arguments (actual parameters) - pass by value, pass by reference Machine code - jumps: call and return - call stack: return address, parameters, private data - procedure prologue and epilogue !40 Abstractions for Memory and Control
  • 41.
    Imperative languages - state& statements - abstraction over machine code - control flow & procedures - types Object-oriented languages - objects & messages - classes - inheritance - types !41 Imperative vs Object-Oriented
  • 42.
  • 43.
  • 44.
    JVM Architecture: Threads !44 Eachthread has its own program counter (PC)
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
    Bytecode Instructions: Goto !51 pc:00 method area 00 01 02 03 04 05 06 A7 00 04 00 A7 FF FF goto 04 nop goto 03
  • 52.
    Bytecode Instructions: Goto !52 pc:04 method area 00 01 02 03 04 05 06 A7 00 04 00 A7 FF FF goto 04 nop goto 03
  • 53.
    Bytecode Instructions: Goto !53 pc:03 method area 00 01 02 03 04 05 06 A7 00 04 00 A7 FF FF goto 04 nop goto 03
  • 54.
    Bytecode Instructions: Goto !54 pc:04 method area 00 01 02 03 04 05 06 A7 00 04 00 A7 FF FF goto 04 nop goto 03
  • 55.
  • 56.
    Operand Stack !56 pc: 00 00 01 02 03 04 05 06 pc:00 optop: 00 00 01 02 03 04 05 06 04 05 10 2A 11 43 03 iconst_1 iconst_2 bipush sipush method area stack
  • 57.
    Operand Stack !57 optop: 01pc:01 00 01 02 03 04 05 06 0000 000100 01 02 03 04 05 06 04 05 10 2A 11 43 03 iconst_1 iconst_2 bipush sipush method area stack
  • 58.
    Operand Stack !58 optop: 02pc:02 00 01 02 03 04 05 06 0000 0001 0000 0002 00 01 02 03 04 05 06 04 05 10 2A 11 43 03 iconst_1 iconst_2 bipush sipush method area stack
  • 59.
    Operand Stack !59 optop: 03pc:04 00 01 02 03 04 05 06 0000 0001 0000 0002 0000 002A 00 01 02 03 04 05 06 04 05 10 2A 11 43 03 iconst_1 iconst_2 bipush sipush method area stack
  • 60.
    Operand Stack !60 optop: 04pc:07 00 01 02 03 04 05 06 0000 0001 0000 0002 0000 002A 0000 4303 00 01 02 03 04 05 06 04 05 10 2A 11 43 03 iconst_1 iconst_2 bipush sipush method area stack
  • 61.
    Operand Stack !61 optop: 04 00 01 02 03 04 05 06 00000001 0000 0002 0000 002A 0000 4303 pc: 07 07 08 09 0A 0B 0C 0D 60 68 5F 64 9A FF F5 iadd imul swap isub ifne 00 method area stack
  • 62.
    Operand Stack !62 optop: 03 00 01 02 03 04 05 06 00000001 0000 0002 0000 432D pc: 08 07 08 09 0A 0B 0C 0D 60 68 5F 64 9A FF F5 iadd imul swap isub ifne 00 method area stack
  • 63.
    Operand Stack !63 optop: 02 00 01 02 03 04 05 06 00000001 0000 865A pc: 09 07 08 09 0A 0B 0C 0D 60 68 5F 64 9A FF F5 iadd imul swap isub ifne 00 method area stack
  • 64.
    Operand Stack !64 optop: 02 00 01 02 03 04 05 06 0000865A 0000 0001 pc: 0A 07 08 09 0A 0B 0C 0D 60 68 5F 64 9A FF F5 iadd imul swap isub ifne 00 method area stack
  • 65.
    Operand Stack !65 optop: 01 00 01 02 03 04 05 06 00008659 pc: 0B 07 08 09 0A 0B 0C 0D 60 68 5F 64 9A FF F5 iadd imul swap isub ifne 00 method area stack
  • 66.
    Operand Stack !66 00 01 02 03 04 05 06 pc: 00optop: 00 00 01 02 03 04 05 06 04 05 10 2A 11 43 03 iconst_1 iconst_2 bipush sipush method area stack
  • 67.
  • 68.
    Constant Pool !68 pc: 00 methodarea stack 00 01 02 03 04 05 06 12 00 12 01 14 00 02 ldc 00 ldc 01 ldc2_w 02 00 01 02 03 04 05 06 constant pool 00 01 02 03 04 05 06 0000 002A 0000 4303 0000 0000 0000 002A optop: 00
  • 69.
    Constant Pool !69 pc: 02 methodarea stack 00 01 02 03 04 05 06 12 00 12 01 14 00 02 ldc 00 ldc 01 ldc2_w 02 00 01 02 03 04 05 06 0000 002A constant pool 00 01 02 03 04 05 06 0000 002A 0000 4303 0000 0000 0000 002A optop: 01
  • 70.
    Constant Pool !70 pc: 04 methodarea stack 00 01 02 03 04 05 06 12 00 12 01 14 00 02 ldc 00 ldc 01 ldc2_w 02 00 01 02 03 04 05 06 0000 002A 0000 4303 constant pool 00 01 02 03 04 05 06 0000 002A 0000 4303 0000 0000 0000 002A optop: 02
  • 71.
    Constant Pool !71 pc: 07 methodarea stack 00 01 02 03 04 05 06 12 00 12 01 14 00 02 ldc 00 ldc 01 ldc2_w 02 00 01 02 03 04 05 06 0000 002A 0000 4303 0000 0000 0000 002A constant pool 00 01 02 03 04 05 06 0000 002A 0000 4303 0000 0000 0000 002A optop: 04
  • 72.
  • 73.
    Local Variables !73 pc: 00 methodarea stack 00 01 02 03 04 05 06 04 3B 1A 3C 84 01 01 iconst_1 istore_0 iload_0 istore_1 iinc 01 01 00 01 02 03 04 05 06 local variables 00 01 02 03 04 05 06 optop: 00
  • 74.
    Local Variables !74 pc: 01 00 01 02 03 04 05 06 00000001 method area stack 00 01 02 03 04 05 06 04 3B 1A 3C 84 01 01 iconst_1 istore_0 iload_0 istore_1 iinc 01 01 local variables 00 01 02 03 04 05 06 optop: 01
  • 75.
    Local Variables !75 pc: 02 00 01 02 03 04 05 06 methodarea stack 00 01 02 03 04 05 06 04 3B 1A 3C 84 01 01 iconst_1 istore_0 iload_0 istore_1 iinc 01 01 local variables 00 01 02 03 04 05 06 0000 0001 optop: 00
  • 76.
    Local Variables !76 pc: 03 00 01 02 03 04 05 06 00000001 method area stack 00 01 02 03 04 05 06 04 3B 1A 3C 84 01 01 iconst_1 istore_0 iload_0 istore_1 iinc 01 01 local variables 00 01 02 03 04 05 06 0000 0001 optop: 01
  • 77.
    Local Variables !77 pc: 04 00 01 02 03 04 05 06 methodarea stack 00 01 02 03 04 05 06 04 3B 1A 3C 84 01 01 iconst_1 istore_0 iload_0 istore_1 iinc 01 01 local variables 00 01 02 03 04 05 06 0000 0001 0000 0001 optop: 00
  • 78.
    Local Variables !78 pc: 07 00 01 02 03 04 05 06 methodarea stack 00 01 02 03 04 05 06 04 3B 1A 3C 84 01 01 iconst_1 istore_0 iload_0 istore_1 iinc 01 01 local variables 00 01 02 03 04 05 06 0000 0001 0000 0002 optop: 00
  • 79.
  • 80.
    Heap !80 pc: 00 method areastack heap 4303 4303 "Compilers" 002A 002A [20,01,40,02,42] 00 01 02 03 04 05 06 12 00 19 00 12 01 2E ldc 00 aload 00 ldc 01 iaload 00 01 02 03 04 05 06 constant pool 00 01 02 03 04 05 06 4303 4303 0000 0004 local variables 00 01 02 03 04 05 06 002A 002A optop: 00
  • 81.
    Heap !81 pc: 02 method areastack heap 4303 4303 "Compilers" 002A 002A [20,01,40,02,42] 00 01 02 03 04 05 06 12 00 19 00 12 01 2E ldc 00 aload 00 ldc 01 iaload 00 01 02 03 04 05 06 4303 4303 constant pool 00 01 02 03 04 05 06 4303 4303 0000 0004 local variables 00 01 02 03 04 05 06 002A 002A optop: 01
  • 82.
    Heap !82 pc: 04 method areastack heap 4303 4303 "Compilers" 002A 002A [20,01,40,02,42] 00 01 02 03 04 05 06 12 00 19 00 12 01 2E ldc 00 aload 00 ldc 01 iaload 00 01 02 03 04 05 06 4303 4303 002A 002A constant pool 00 01 02 03 04 05 06 4303 4303 0000 0004 local variables 00 01 02 03 04 05 06 002A 002A optop: 02
  • 83.
    Heap !83 pc: 06 method areastack heap 4303 4303 "Compilers" 002A 002A [20,01,40,02,42] 00 01 02 03 04 05 06 12 00 19 00 12 01 2E ldc 00 aload 00 ldc 01 iaload 00 01 02 03 04 05 06 4303 4303 002A 002A 0000 0004 constant pool 00 01 02 03 04 05 06 4303 4303 0000 0004 local variables 00 01 02 03 04 05 06 002A 002A optop: 03
  • 84.
    Heap !84 pc: 07 method areastack heap 4303 4303 "Compilers" 002A 002A [20,01,40,02,42] 00 01 02 03 04 05 06 12 00 19 00 12 01 2E ldc 00 aload 00 ldc 01 iaload 00 01 02 03 04 05 06 4303 4303 0000 0042 constant pool 00 01 02 03 04 05 06 4303 4303 0000 0004 local variables 00 01 02 03 04 05 06 002A 002A optop: 02
  • 85.
  • 86.
    Dispatch - link methodcall to method Static dispatch - based on type information at compile-time Dynamic dispatch - based on type information at run-time - single dispatch: one parameter - multiple dispatch: more parameters !86 Static vs. Dynamic Dispatch
  • 87.
    Example: Static Call !87 .classpublic Exp .method public static fac(I)I iload 1 ifne else iconst_1 ireturn else: iload 1 dup iconst_1 isub invokestatic Exp/fac(I)I imul ireturn .end method function fac(n: int): int = if n = 0 then 1 else n * fac(n - 1)
  • 88.
    Example: Dynamic Call !88 .classpublic Exp .method public fac(I)I iload 1 ifne else iconst_1 ireturn else: iload 0 iload 1 dup iconst_1 isub invokevirtual Exp/fac(I)I imul ireturn .end method function fac(n: int): int = if n = 0 then 1 else n * fac(n - 1)
  • 89.
    Caller - push referenceto receiver object - push parameters left-to-right - call method Virtual machine on call - allocate space (frame data, operand stack, local variables) - store frame data (data pointer, return address, exception table) - store parameters as local variables - dynamic dispatch - point pc to method code !89 Code Pattern: Dynamic Method Call
  • 90.
    Callee - parameters inlocal variables - leave result on operand stack - return to caller Virtual machine on return - push result on caller’s operand stack - point pc to return address - destroy frame !90 Code Pattern: Return from Method Call
  • 91.
  • 92.
  • 93.
    Stack Frames !93 00 01 02 03 04 05 06 2A 10 40 B6 00 01 AC aload_0 bipush invokevirtual 01 ireturn optop: 02 methodarea stack heap 00 01 02 03 04 05 06 4303 4303 0000 0040 local variables 00 01 02 03 04 05 06 4303 4303 pc: 03
  • 94.
    Stack Frames !94 pc: 80 80 81 82 83 84 85 86 2B 59 68 AC 00 00 00 iload_1 dup imul ireturn optop:01 method area stack heap 00 01 02 03 04 05 06 4303 4303 0000 0040 local variables 00 01 02 03 04 05 06 4303 4303 local variables 00 01 02 03 04 05 06 4303 4303 0000 0040 optop: 00 stack 00 01 02 03 04 05 06
  • 95.
    Stack Frames !95 pc: 81 80 81 82 83 84 85 86 2B 59 68 AC 00 00 00 iload_1 dup imul ireturn optop:01 method area stack heap 00 01 02 03 04 05 06 4303 4303 0000 0040 local variables 00 01 02 03 04 05 06 4303 4303 local variables 00 01 02 03 04 05 06 4303 4303 0000 0040 optop: 01 stack 00 01 02 03 04 05 06 0000 0040
  • 96.
    Stack Frames !96 pc: 81 80 81 82 83 84 85 86 2B 59 68 AC 00 00 00 iload_1 dup imul ireturn optop:01 method area stack heap 00 01 02 03 04 05 06 4303 4303 0000 0040 local variables 00 01 02 03 04 05 06 4303 4303 local variables 00 01 02 03 04 05 06 4303 4303 0000 0040 optop: 02 stack 00 01 02 03 04 05 06 0000 0040 0000 0040
  • 97.
    Stack Frames !97 pc: 82 80 81 82 83 84 85 86 2B 59 68 AC 00 00 00 iload_1 dup imul ireturn optop:01 method area stack heap 00 01 02 03 04 05 06 4303 4303 0000 0040 local variables 00 01 02 03 04 05 06 4303 4303 local variables 00 01 02 03 04 05 06 4303 4303 0000 0040 optop: 01 stack 00 01 02 03 04 05 06 0000 1000
  • 98.
    Stack Frames !98 00 01 02 03 04 05 06 2A 10 40 B6 00 01 AC aload_0 bipush invokevirtual 01 ireturn optop: 01 methodarea stack heap 00 01 02 03 04 05 06 0000 1000 local variables 00 01 02 03 04 05 06 4303 4303 pc: 06
  • 99.
  • 100.
    Java Compiler !100 > ls Course.java >javac -verbose Course.java [parsing started Course.java] [parsing completed 8ms] [loading java/lang/Object.class(java/lang:Object.class)] [checking university.Course] [wrote Course.class] [total 411ms] > ls Course.class Course.java
  • 101.
    Class Files: Format !101 magicnumber CAFEBABE class file version (minor, major) constant pool count + constant pool access flags this class super class interfaces count + interfaces fields count + fields methods count + methods attribute count + attributes
  • 102.
    Jasmin Intermediate Language !102 .classpublic Exp .method public static fac(I)I iload 1 ifne else iconst_1 ireturn else: iload 1 dup iconst_1 isub invokestatic Exp/fac(I)I imul ireturn .end method
  • 103.
  • 104.
    !104 Except where otherwisenoted, this work is licensed under