Vortragsfolien

Werbung
HOTPATH VM
An Effective JIT Compiler for Resource-constrained Devices
based on the paper by Andreas Gal, Christian W. Probst and Michael Franz, VEE ’06
Donnerstag, 8. Dezember 11
INTRODUCTION
Donnerstag, 8. Dezember 11
INTRODUCTION
• Most
important factor: speed
Donnerstag, 8. Dezember 11
INTRODUCTION
• Most
important factor: speed
• Overlooked: power
Donnerstag, 8. Dezember 11
consumption, memory footprint
INTRODUCTION
• Most
important factor: speed
• Overlooked: power
• Embedded
Donnerstag, 8. Dezember 11
consumption, memory footprint
JIT compilers (simpler algorithms)
JAMVM
Donnerstag, 8. Dezember 11
JAMVM
• GNU
classpath-based
Donnerstag, 8. Dezember 11
JAMVM
• GNU
classpath-based
• Own
intermediate representation
Donnerstag, 8. Dezember 11
JAMVM
• GNU
classpath-based
• Own
intermediate representation
• HotpathVM
Donnerstag, 8. Dezember 11
as add-on
JAMVM
• GNU
classpath-based
• Own
intermediate representation
• HotpathVM
• Integrated
Donnerstag, 8. Dezember 11
as add-on
w/ 20 lines of code
HOTPATHVM
Donnerstag, 8. Dezember 11
HOTPATHVM
• 150
kB memory footprint
Donnerstag, 8. Dezember 11
HOTPATHVM
• 150
kB memory footprint
• Searching
Donnerstag, 8. Dezember 11
for hot code by tracing
HOTPATHVM
• 150
kB memory footprint
• Searching
• Cold
Donnerstag, 8. Dezember 11
for hot code by tracing
code for interpreter
HOTPATHVM
• 150
kB memory footprint
• Searching
• Cold
for hot code by tracing
code for interpreter
• Optimizing
Donnerstag, 8. Dezember 11
and compiling traces
TRACE SELECTION
Donnerstag, 8. Dezember 11
TRACE SELECTION
• Problem: bytecode
Donnerstag, 8. Dezember 11
is not purely sequential
TRACE SELECTION
• Problem: bytecode
is not purely sequential
• Solution: Software Trace
Donnerstag, 8. Dezember 11
Scheduling
TRACE SELECTION
• Problem: bytecode
is not purely sequential
• Solution: Software Trace
• Limited
Donnerstag, 8. Dezember 11
to loops
Scheduling
IDENTIFYING LOOP HEADERS
Donnerstag, 8. Dezember 11
IDENTIFYING LOOP HEADERS
• Backward
Donnerstag, 8. Dezember 11
jump → record destination
IDENTIFYING LOOP HEADERS
• Backward
jump → record destination
• Assumption: bytecode
Donnerstag, 8. Dezember 11
is forward
IDENTIFYING LOOP HEADERS
• Backward
jump → record destination
• Assumption: bytecode
• Counter
Donnerstag, 8. Dezember 11
is forward
for backward jumps
IDENTIFYING LOOP HEADERS
• Backward
jump → record destination
• Assumption: bytecode
• Counter
• Saved
Donnerstag, 8. Dezember 11
is forward
for backward jumps
in intermediate representation
IDENTIFYING LOOP HEADERS
• Backward
jump → record destination
• Assumption: bytecode
• Counter
• Saved
• Record
Donnerstag, 8. Dezember 11
is forward
for backward jumps
in intermediate representation
after threshold is exceeded
TRACE EXAMPLE
Donnerstag, 8. Dezember 11
TRACE EXAMPLE
public static void main(String args[]) {
int i, k = 0;
for (i = 0; i < 1000, ++i)
++k;
System.out.println(k);
}
Donnerstag, 8. Dezember 11
TRACE EXAMPLE
public static void main(String args[]) {
int i, k = 0;
for (i = 0; i < 1000, ++i)
++k;
System.out.println(k);
}
Donnerstag, 8. Dezember 11
iconst_0
istore_2
iconst_0
istore_1
A: iload_1
sipush 1000
if_icmpge B
iinc 2,1
iinc 1,1
goto A
B: getstatic System.out
iload_2
invokevirtual println(int)
return
TRACE EXAMPLE
public static void main(String args[]) {
int i, k = 0;
for (i = 0; i < 1000, ++i)
hotspot
++k;
System.out.println(k);
}
Donnerstag, 8. Dezember 11
iconst_0
istore_2
iconst_0
istore_1
A: iload_1
sipush 1000
if_icmpge B
iinc 2,1
iinc 1,1
goto A
B: getstatic System.out
iload_2
invokevirtual println(int)
return
TRACE EXAMPLE
public static void main(String args[]) {
int i, k = 0;
for (i = 0; i < 1000, ++i)
hotspot
++k;
System.out.println(k);
}
Donnerstag, 8. Dezember 11
iconst_0
istore_2
iconst_0
istore_1
A: iload_1
sipush 1000
if_icmpge B
hotpath
iinc 2,1
iinc 1,1
goto A
B: getstatic System.out
iload_2
invokevirtual println(int)
return
RECORDING TRACES
Donnerstag, 8. Dezember 11
RECORDING TRACES
• Meta
block after each instruction
Donnerstag, 8. Dezember 11
RECORDING TRACES
• Meta
block after each instruction
• Second
Donnerstag, 8. Dezember 11
stop-loss threshold
RECORDING TRACES
• Meta
block after each instruction
• Second
• No
stop-loss threshold
overhead without tracer
Donnerstag, 8. Dezember 11
RECORDING TRACES
• Meta
block after each instruction
• Second
• No
stop-loss threshold
overhead without tracer
• Guards
Donnerstag, 8. Dezember 11
for branches
GUARDS
Donnerstag, 8. Dezember 11
GUARDS
• Ensures
Donnerstag, 8. Dezember 11
following the hotpath
GUARDS
• Ensures
following the hotpath
• Returns
Donnerstag, 8. Dezember 11
control to VM on failure
GUARDS
• Ensures
following the hotpath
• Returns
• Reset
control to VM on failure
values from intermediate representation
Donnerstag, 8. Dezember 11
BRANCHES
Donnerstag, 8. Dezember 11
BRANCHES
• Multiple
Donnerstag, 8. Dezember 11
hot paths in loop
BRANCHES
• Multiple
• Lazy
hot paths in loop
recording
Donnerstag, 8. Dezember 11
BRANCHES
• Multiple
• Lazy
hot paths in loop
recording
• Secondary
Donnerstag, 8. Dezember 11
traces (like Dynamo)
BRANCHES
• Multiple
• Lazy
hot paths in loop
recording
• Secondary
• Updates
Donnerstag, 8. Dezember 11
traces (like Dynamo)
guard instruction
BRANCHES
• Multiple
• Lazy
hot paths in loop
recording
• Secondary
• Updates
Donnerstag, 8. Dezember 11
traces (like Dynamo)
guard instruction
STOP CONDITIONS
Donnerstag, 8. Dezember 11
STOP CONDITIONS
• Successful
Donnerstag, 8. Dezember 11
recording
STOP CONDITIONS
• Successful
• Aborted
Donnerstag, 8. Dezember 11
recording
recording on rare events
STOP CONDITIONS
• Successful
• Aborted
recording
recording on rare events
• Exceptions
Donnerstag, 8. Dezember 11
STOP CONDITIONS
• Successful
• Aborted
recording
recording on rare events
• Exceptions
• Native
Donnerstag, 8. Dezember 11
method invocation
COMPILING TRACES
Donnerstag, 8. Dezember 11
COMPILING TRACES
• Compiling
Donnerstag, 8. Dezember 11
complete traces only
COMPILING TRACES
• Compiling
complete traces only
• Assumption: trace
Donnerstag, 8. Dezember 11
is executed repeatedly
COMPILING TRACES
• Compiling
complete traces only
• Assumption: trace
Donnerstag, 8. Dezember 11
is executed repeatedly
COMPILING TRACES
• Compiling
complete traces only
• Assumption: trace
• Stack
is executed repeatedly
Deconstruction
Donnerstag, 8. Dezember 11
COMPILING TRACES
• Compiling
complete traces only
• Assumption: trace
• Stack
is executed repeatedly
Deconstruction
• Code Analysis
Donnerstag, 8. Dezember 11
COMPILING TRACES
• Compiling
complete traces only
• Assumption: trace
• Stack
Deconstruction
• Code Analysis
• Code
is executed repeatedly
Generation
Donnerstag, 8. Dezember 11
STACK DECONSTRUCTION
Donnerstag, 8. Dezember 11
STACK DECONSTRUCTION
• Generates
Donnerstag, 8. Dezember 11
SSA-based IR
STACK DECONSTRUCTION
• Generates
•𝜑
SSA-based IR
pseudo instruction
Donnerstag, 8. Dezember 11
STACK DECONSTRUCTION
x = 5
• Generates
•𝜑
SSA-based IR
if x > 5
pseudo instruction
x = 5
x = 7
x = 7
Donnerstag, 8. Dezember 11
STACK DECONSTRUCTION
xx1 == 55
• Generates
•𝜑
SSA-based IR
if
if xx1 >> 55
pseudo instruction
xx2 = 5
xx3 == 77
= 27,x3)
x4 = x𝜑(x
Donnerstag, 8. Dezember 11
STACK DECONSTRUCTION
xx1 == 55
• Generates
•𝜑
SSA-based IR
if
if xx1 >> 55
pseudo instruction
• Flags
loop invariant code
xx2 = 5
xx3 == 77
= 27,x3)
x4 = x𝜑(x
Donnerstag, 8. Dezember 11
STACK DECONSTRUCTION
xx1 == 55
• Generates
•𝜑
SSA-based IR
if
if xx1 >> 55
pseudo instruction
• Flags
loop invariant code
xx2 = 5
xx3 == 77
= 27,x3)
x4 = x𝜑(x
Donnerstag, 8. Dezember 11
CODE ANALYSIS
Donnerstag, 8. Dezember 11
CODE ANALYSIS
• Constant
Donnerstag, 8. Dezember 11
Propagation
CODE ANALYSIS
• Constant
• Loop
Propagation
Peeling
Donnerstag, 8. Dezember 11
CODE ANALYSIS
• Constant
• Loop
Propagation
Peeling
• Common
Donnerstag, 8. Dezember 11
subexpression elimination
CODE ANALYSIS
• Constant
• Loop
Propagation
Peeling
• Common
• Invariant
Donnerstag, 8. Dezember 11
subexpression elimination
code motion
CODE GENERATION
Donnerstag, 8. Dezember 11
CODE GENERATION
• Generating
Donnerstag, 8. Dezember 11
code backwards
CODE GENERATION
• Generating
• Enables
Donnerstag, 8. Dezember 11
code backwards
to emit special machine code
CODE GENERATION
• Generating
• Enables
• Constant
Donnerstag, 8. Dezember 11
code backwards
to emit special machine code
Folding
SIDE EXITS
Donnerstag, 8. Dezember 11
SIDE EXITS
• Leaving
Donnerstag, 8. Dezember 11
the hot path
SIDE EXITS
• Leaving
the hot path
• Generator
Donnerstag, 8. Dezember 11
generates compensation code
SIDE EXITS
• Leaving
the hot path
• Generator
• Special
Donnerstag, 8. Dezember 11
generates compensation code
case: inline methods
SIDE EXITS
• Leaving
the hot path
• Generator
• Special
case: inline methods
• Writing
Donnerstag, 8. Dezember 11
generates compensation code
back current state
WALKTHROUGH
Donnerstag, 8. Dezember 11
WALKTHROUGH
Java Code
Donnerstag, 8. Dezember 11
WALKTHROUGH
Java Code
Donnerstag, 8. Dezember 11
compilation
WALKTHROUGH
Java Code
Donnerstag, 8. Dezember 11
compilation
Bytecode
WALKTHROUGH
Bytecode
Donnerstag, 8. Dezember 11
WALKTHROUGH
Bytecode
Donnerstag, 8. Dezember 11
stack
deconstruction
WALKTHROUGH
Bytecode
Donnerstag, 8. Dezember 11
stack
deconstruction
SSA
WALKTHROUGH
Bytecode
stack
deconstruction
• Flag
Donnerstag, 8. Dezember 11
invariant code
SSA
WALKTHROUGH
SSA
Donnerstag, 8. Dezember 11
WALKTHROUGH
SSA
Donnerstag, 8. Dezember 11
analysis
optimization
WALKTHROUGH
SSA
Donnerstag, 8. Dezember 11
analysis
optimization
SSA
WALKTHROUGH
SSA
analysis
optimization
• Constant
SSA
Propagation
• Loop Peeling
• Common subexpression elimination
• Invariant code motion
Donnerstag, 8. Dezember 11
WALKTHROUGH
SSA
Donnerstag, 8. Dezember 11
WALKTHROUGH
SSA
Donnerstag, 8. Dezember 11
generation
WALKTHROUGH
SSA
Donnerstag, 8. Dezember 11
generation
Machine code
WALKTHROUGH
SSA
generation
• Constant
Donnerstag, 8. Dezember 11
Folding
Machine code
BE
Donnerstag, 8. Dezember 11
NCHMAR
KS
BE
NCHMAR
KS
250
execution time in s
200
150
100
50
0
Donnerstag, 8. Dezember 11
LU
SOR
FFT
Java VM
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
250
execution time in s
200
150
100
50
0
Donnerstag, 8. Dezember 11
LU
SOR
FFT
Java VM
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
250
execution time in s
200
150
100
50
0
Donnerstag, 8. Dezember 11
LU
SOR
FFT
Java VM
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
250
execution time in s
200
150
100
50
0
Donnerstag, 8. Dezember 11
LU
SOR
FFT
Java VM
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
250
execution time in s
200
150
100
50
0
Donnerstag, 8. Dezember 11
LU
SOR
FFT
Java VM
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
Donnerstag, 8. Dezember 11
NCHMAR
KS
BE
NCHMAR
KS
20
18
16
speedup factor
14
12
10
8
6
4
2
0
Donnerstag, 8. Dezember 11
LU
SOR
Java VM
FFT
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
20
18
16
speedup factor
14
12
10
8
6
4
2
0
Donnerstag, 8. Dezember 11
LU
SOR
Java VM
FFT
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
20
18
16
speedup factor
14
12
10
8
6
4
2
0
Donnerstag, 8. Dezember 11
LU
SOR
Java VM
FFT
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
20
18
16
speedup factor
14
12
10
8
6
4
2
0
Donnerstag, 8. Dezember 11
LU
SOR
Java VM
FFT
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
BE
NCHMAR
KS
20
18
16
speedup factor
14
12
10
8
6
4
2
0
Donnerstag, 8. Dezember 11
LU
SOR
Java VM
FFT
JamVM
SCR
Linpack NumSort MonteCarlo
HotpathVM
Hotspot VM
OUTLOOK
Donnerstag, 8. Dezember 11
OUTLOOK
• Trace
Donnerstag, 8. Dezember 11
Merging
OUTLOOK
• Trace
Merging
• Support
Donnerstag, 8. Dezember 11
additional architectures (ARM)
OUTLOOK
• Trace
Merging
• Support
• Use
additional architectures (ARM)
outside embedded environment
Donnerstag, 8. Dezember 11
HOTPATH VM
An Effective JIT Compiler for Resource-constrained Devices
Donnerstag, 8. Dezember 11
Zugehörige Unterlagen
Herunterladen