<Insert Picture Here>
Maxine: A JVM Written in Java
Michael HauptOracle LabsPotsdam, Germany
3
The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Speaker's Background
4
Technische Universität Darmstadt, 2001–2006
Doctoral research, Steamloom (virtual machine support for aspect-oriented programming)
Speaker's Background
4
Technische Universität Darmstadt, 2001–2006
Doctoral research, Steamloom (virtual machine support for aspect-oriented programming)
Hasso-Plattner-Institut Potsdam, 2006–2011
Postdoc, virtual machine architecture disentangling, SOM family, NXTalk
Speaker's Background
4
Technische Universität Darmstadt, 2001–2006
Doctoral research, Steamloom (virtual machine support for aspect-oriented programming)
Hasso-Plattner-Institut Potsdam, 2006–2011
Postdoc, virtual machine architecture disentangling, SOM family, NXTalk
Oracle Labs, Potsdam,since 2011
Maxine team, virtual machine architecture, multi-language virtual machines, code cache management, JSR292
Who Needs a JVM?
5
JVM
Who Needs a JVM?
5
application developers, end users ✔
JVM
Java
Applications
Who Needs a JVM?
5
application developers, end users ✔
researchers ✔
JVM
Java
Applications
Dynamic Compiler Garbage Collector Object Layout Runtime
Optimisations
Target Architecture Parallel
Concurrent Language Specifics Thread Migration
Concurrency AbstractionsTagging
Who Needs a JVM?
5
application developers, end users ✔
researchers ✔
programming language implementers ✔
JVM
Java
Applications
Dynamic Compiler Garbage Collector Object Layout Runtime
Optimisations
Target Architecture Parallel
Concurrent Language Specifics Thread Migration
Concurrency AbstractionsTagging
Java, Ruby, Python, Smalltalk, ...
Who Needs a JVM?
5
application developers, end users ✔
researchers ✔
programming language implementers ✔
JVM
Java
Applications
Dynamic Compiler Garbage Collector Object Layout Runtime
Optimisations
Target Architecture Parallel
Concurrent Language Specifics Thread Migration
Concurrency AbstractionsTagging
Java, Ruby, Python, Smalltalk, ...
! ! ! !
Who Needs a JVM?
5
application developers, end users ✔
researchers ✔
programming language implementers ✔
JVM
Java
Applications
Dynamic Compiler Garbage Collector Object Layout Runtime
Optimisations
Target Architecture Parallel
Concurrent Language Specifics Thread Migration
Concurrency AbstractionsTagging
Java, Ruby, Python, Smalltalk, ...
J?VM
! ! ! !
Maxine
6
almost 100 % Java
use unmodified JDK
meta-circularity studies
Home page: http://wikis.oracle.com/display/MaxineVM/Home
Source (GPLv2): https://hg.kenai.com/hg/maxine~maxine
Mailing list via: http://kenai.com/projects/maxine
Maxine
6
almost 100 % Java
use unmodified JDK
meta-circularity studies
supported on 64-bit x86
Solaris, Mac OS X, Linux
Virtual Edition: Xen
Home page: http://wikis.oracle.com/display/MaxineVM/Home
Source (GPLv2): https://hg.kenai.com/hg/maxine~maxine
Mailing list via: http://kenai.com/projects/maxine
Maxine
6
almost 100 % Java
use unmodified JDK
meta-circularity studies
full IDE support
(Eclipse, NetBeans)
tooling: Inspector
supported on 64-bit x86
Solaris, Mac OS X, Linux
Virtual Edition: Xen
Home page: http://wikis.oracle.com/display/MaxineVM/Home
Source (GPLv2): https://hg.kenai.com/hg/maxine~maxine
Mailing list via: http://kenai.com/projects/maxine
Maxine
6
almost 100 % Java
use unmodified JDK
meta-circularity studies
full IDE support
(Eclipse, NetBeans)
tooling: Inspector
supported on 64-bit x86
Solaris, Mac OS X, Linux
Virtual Edition: Xen
Home page: http://wikis.oracle.com/display/MaxineVM/Home
Source (GPLv2): https://hg.kenai.com/hg/maxine~maxine
Mailing list via: http://kenai.com/projects/maxine
dynamic compilation only
semi-space GC
modular architecture
VM Research Group at Oracle Labs
7
Home page: http://wikis.oracle.com/display/MaxineVM/Home
Source (GPLv2): https://hg.kenai.com/hg/maxine~maxine
Mailing list via: http://kenai.com/projects/maxine
DougSimon
MarioWolczko
Director
ThomasWürthinger
MichaelHaupt
ChristianWimmer
LaurentDaynès
MickJordan
MichaelVan De Vanter
Why Java?
8
language• reflection• annotations
JDK• rich and powerful API• inclusion in VM
ecosystem• IDE support• tooling
VM architecture• uniform representation• same compiler chain
Bootstrapping Maxine
9
Maxine Source Code
Bootstrapping Maxine
9
Maxine Source Code
Maxine Bytecodes
javacJust-in-Time Compilers
Memory Manager
... others ...
Host VM (HotSpot)
Bootstrapping Maxine
9
Maxine Source Code
Maxine Bytecodes
Boot Image Generator
javac
Host VM (HotSpot)
Bootstrapping Maxine
9
Maxine Source Code
Maxine Bytecodes
Boot Image Generator
javacJust-in-Time Compilers
Memory Manager
... others ...
Host VM (HotSpot)
Bootstrapping Maxine
9
Maxine Source Code
Maxine Bytecodes
Boot Image Generator
javacJust-in-Time Compilers
Memory Manager
... others ...
Host VM (HotSpot)
Bootstrapping Maxine
9
Maxine Source Code
Maxine Bytecodes
Boot Image Generator
javacJust-in-Time Compilers
Memory Manager
... others ...
Host VM (HotSpot)
Bootstrapping Maxine
9
Maxine Source Code
Maxine Bytecodes
Boot Image Generator
MaxineBoot Image
javacJust-in-Time Compilers
Memory Manager
... others ...
Host VM (HotSpot)
Bootstrapping Maxine
9
Maxine Source Code
Maxine Bytecodes
Boot Image Generator
Boot Loader
MaxineBoot Image
javacJust-in-Time Compilers
Memory Manager
... others ...
Maxine Scheme Abstractions
10
Maxine VM
Dynamic Compilers Garbage Collector Object Layout Runtime
Maxine Scheme Abstractions
10
Maxine VM
Dynamic Compilers Garbage Collector Object Layout Runtime
interface LayoutScheme
Maxine Scheme Abstractions
10
Maxine VM
Dynamic Compilers Garbage Collector Object Layout Runtime
interface LayoutScheme interface ReferenceScheme
Maxine Scheme Abstractions
10
Maxine VM
Dynamic Compilers Garbage Collector Object Layout Runtime
interface LayoutScheme interface ReferenceSchemeinterface HeapScheme
Maxine Scheme Abstractions
10
Maxine VM
Dynamic Compilers Garbage Collector Object Layout Runtime
interface LayoutScheme interface ReferenceSchemeinterface HeapScheme
interface MonitorScheme
Maxine Scheme Abstractions
10
Maxine VM
Dynamic Compilers Garbage Collector Object Layout Runtime
interface LayoutScheme interface ReferenceSchemeinterface HeapScheme
interface MonitorScheme interface RunScheme
Maxine Scheme Abstractions
10
Maxine VM
Dynamic Compilers Garbage Collector Object Layout Runtime
interface LayoutScheme interface ReferenceSchemeinterface HeapScheme
interface MonitorScheme interface RunSchemeinterface CompilationBroker
Example: ReferenceScheme
11
What you use in Maxine to access a field:
int x = Reference.fromJava(obj).readInt(24); field offset (in bytes) is computed by LayoutScheme;we assume a constant offset in this example
Example: ReferenceScheme
11
What you use in Maxine to access a field:
int x = Reference.fromJava(obj).readInt(24);
Actual call chain after forced inlining via @INLINE or @FOLD:
Reference ref = MaxineVM.vm.config.referenceScheme.toReference(obj);Pointer ptr = MaxineVM.vm.config.referenceScheme.toOrigin(ref);int x = ptr.readInt(24);
field offset (in bytes) is computed by LayoutScheme;we assume a constant offset in this example
Example: ReferenceScheme
11
What you use in Maxine to access a field:
int x = Reference.fromJava(obj).readInt(24);
Actual call chain after forced inlining via @INLINE or @FOLD:
Reference ref = MaxineVM.vm.config.referenceScheme.toReference(obj);Pointer ptr = MaxineVM.vm.config.referenceScheme.toOrigin(ref);int x = ptr.readInt(24);
All fields are marked @CONSTANT, so the compiler knows theconcrete scheme implementation used:
class DirectReferenceScheme implements ReferenceScheme { @INTRINSIC(UNSAFE_CAST) native Reference toReference(Object origin); @INTRINSIC(UNSAFE_CAST) native Word toOrigin(Reference ref);}
field offset (in bytes) is computed by LayoutScheme;we assume a constant offset in this example
Example: ReferenceScheme
11
What you use in Maxine to access a field:
int x = Reference.fromJava(obj).readInt(24);
Actual call chain after forced inlining via @INLINE or @FOLD:
Reference ref = MaxineVM.vm.config.referenceScheme.toReference(obj);Pointer ptr = MaxineVM.vm.config.referenceScheme.toOrigin(ref);int x = ptr.readInt(24);
All fields are marked @CONSTANT, so the compiler knows theconcrete scheme implementation used:
class DirectReferenceScheme implements ReferenceScheme { @INTRINSIC(UNSAFE_CAST) native Reference toReference(Object origin); @INTRINSIC(UNSAFE_CAST) native Word toOrigin(Reference ref);}
Final machine code:
movl [rax + 24], rbx
field offset (in bytes) is computed by LayoutScheme;we assume a constant offset in this example
Baseline Compiler: T1X
12
job: assemble pre-generated bytecode templates• written in Java• compiled by optimising compiler at VM build time• very small amount of glue assembly
Baseline Compiler: T1X
12
job: assemble pre-generated bytecode templates• written in Java• compiled by optimising compiler at VM build time• very small amount of glue assembly
template code for integer array load (IALOAD)@T1X_TEMPLATE(IALOAD)static int iaload(@Slot(1) Object array, @Slot(0) int index) { ArrayAccess.checkIndex(array, index); return result = ArrayAccess.getInt(array, index);}@INLINEstatic void checkIndex(Object array, int index) { int length = Layout.readArrayLength(Reference.fromJava(array)); if (UnsignedMath.aboveOrEqual(index, length)) { throw Throw.arrayIndexOutOfBoundsException(array, index); }}
@INLINEstatic int getInt(Object array, int index) { return Layout.getInt(Reference.fromJava(array), index);}
Baseline Compiler: T1X
13
instantiated template code for integer array load
mov rdi, [rsp + 16] mov esi, [rsp] mov rax, rdi movsxd rax, [rax + 16] cmp esi, eax jb L1 call Throw.indexOutOfBoundsException() nop mov rdi, rax call MaxRuntimeCalls.runtimeUnwindException nop L1: movsxd rsi, esi movsxd rax, rdi[rsi * 4 + 24] addq rsp, 0x10 mov [rsp], eax
prologue(loading of operand stack slots)
compiled template
epilogue(storing of operand stack slots)
8 bytes hub (class pointer)8 bytes misc (locking, GC)4 bytes array length4 bytes alignment
Inspector
14
Optimising Compilers: C1X and Graal
15
HotSpot VMRuntime
InterpreterObject Locking
C1 / C2
Inline Assembly
Garbage Collector Type Information
Compiler Interface
C++
Optimising Compilers: C1X and Graal
15
HotSpot VMRuntime
InterpreterObject Locking
C1 / C2
Inline Assembly
Garbage Collector Type Information
Compiler Interface
Java
C++
Maxine VMRuntime
T1XObject Locking
C1X
XIR
Garbage Collector Type Information
Compiler Interface
Optimising Compilers: C1X and Graal
15
HotSpot VMRuntime
InterpreterObject Locking
C1 / C2
Inline Assembly
Garbage Collector Type Information
Compiler Interface
Java
C++
Maxine VMRuntime
T1XObject Locking
C1X
XIR
Garbage Collector Type Information
Compiler Interface
Optimising Compilers: C1X and Graal
15
HotSpot VMRuntime
InterpreterObject Locking
C1 / C2
Inline Assembly
Garbage Collector Type Information
Compiler Interface
Java
C++
Maxine VMRuntime
T1XObject Locking
C1X
XIR
Garbage Collector Type Information
Compiler Interface
Graal VMRuntime
InterpreterObject Locking
Graal
Snippets
Garbage Collector Type Information
Compiler Interface
Optimising Compilers: C1X and Graal
15
HotSpot VMRuntime
InterpreterObject Locking
C1 / C2
Inline Assembly
Garbage Collector Type Information
Compiler Interface
Java
C++
Maxine VMRuntime
T1XObject Locking
C1X
XIR
Garbage Collector Type Information
Compiler Interface
Graal VMRuntime
InterpreterObject Locking
Graal
Snippets
Garbage Collector Type Information
Compiler Interface
Optimising Compilers: C1X and Graal
15
HotSpot VMRuntime
InterpreterObject Locking
C1 / C2
Inline Assembly
Garbage Collector Type Information
Compiler Interface
Java
C++
Maxine VMRuntime
T1XObject Locking
C1X
XIR
Garbage Collector Type Information
Compiler Interface
Graal VMRuntime
InterpreterObject Locking
Graal
Snippets
Garbage Collector Type Information
Compiler Interface
Maxine VM with GraalRuntime
T1XObject Locking
Graal
Snippets
Garbage Collector Type Information
Compiler Interface
Optimising Compilers: C1X and Graal
15
HotSpot VMRuntime
InterpreterObject Locking
C1 / C2
Inline Assembly
Garbage Collector Type Information
Compiler Interface
Java
C++
Maxine VMRuntime
T1XObject Locking
C1X
XIR
Garbage Collector Type Information
Compiler Interface
Graal VMRuntime
InterpreterObject Locking
Graal
Snippets
Garbage Collector Type Information
Compiler Interface
Maxine VM with GraalRuntime
T1XObject Locking
Graal
Snippets
Garbage Collector Type Information
Compiler Interface
Graal
16
Home page: http://openjdk.java.net/projects/graal/
Source (GPLv2): http://hg.openjdk.java.net/graal/graal/
Mailing list: [email protected]
Vision Statement
Create an extensible, modular, dynamic, and aggressive compiler using
object-oriented and reflective Java programming,
a graph-based and visualizable intermediate representation,
and Java snippets.
-- Thomas Würthinger
Collaboration with Johannes-Kepler-Universität Linz, Austria
Lukas Stadler, Gilles Duboscq, Christian Häubl, Prof. Hanspeter MössenböckJKU
Graal
17
Architecture Lowering
Memory Optimisations
VM Lowering
Loop Optimisations
Escape Analysis
Type Inference
Method Inlining
Java Bytecode Parser
Peephole Optimisations
Register Allocation
Code Generation
Java Bytecodes
Machine Code
Graal
17
Architecture Lowering
Memory Optimisations
VM Lowering
Loop Optimisations
Escape Analysis
Type Inference
Method Inlining
Java Bytecode Parser
Peephole Optimisations
Register Allocation
Code Generation
Java Bytecodes
Machine Code
Graal
17
Architecture Lowering
Memory Optimisations
VM Lowering
Loop Optimisations
Escape Analysis
Type Inference
Method Inlining
Java Bytecode Parser
Peephole Optimisations
Register Allocation
Code Generation
Java Bytecodes
Machine Code
Language dependent
Language independentVM independent
Architecture independent
VM dependentArchitecture independent
VM dependentArchitecture dependent
Performance: Maxine/C1X
18
2-socket dual core AMD Opteron 2214, 2.2 GHz, 4 total cores4 GByte main memory
Oracle Enterprise Linux, version 2.6.18-238.9.1.0.1.e15
71% 64%
58% 54%
76% 74%
151%
119%
81%
157%
191%
138%
0%
20%
40%
60%
80%
100%
120%
140%
160%
180%
200%
SPECjvm2008 DaCapo peak DaCapo startup SPECjbb2005 SciMark 2.0 JavaGrande
Client Maxine/C1X Server
Performance: GraalVM
19
Intel(R) Core(TM) i5-750 @ 2.67GHz (4 cores)8 GByte main memory
Ubuntu Linux 11.10, kernel 3.0.0-12
72%
48%
66%
77%
61%
74%
0%
20%
40%
60%
80%
100%
120%
DaCapo Scala-DaCapo SPECjvm2008
Client GraalVM Server
Maxine VM
Maxine: Code Cache Management
20
T1X
C1X
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
T1X
C1X
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
T1X
C1X
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-space
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-space
m() n()<clinit>
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-space
m() n()<clinit> o()
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-space
m() n()<clinit>
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-spaceto-spacefrom-space
m() n()<clinit>
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-spaceto-spacefrom-space
m() n()<clinit> n()<clinit>
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-spaceto-spacefrom-space
n()<clinit> n()<clinit> m()
Maxine VMT1X Cache C1X Cache
Maxine: Code Cache Management
20
m()
n()
o()
<clinit>
m()
o()
m()
o()
<clinit>
T1X
C1X
T1X Cache with Semi-Space Memory Management Scheme
to-space from-spaceto-spacefrom-space
n()<clinit> n()<clinit> m() o()
Code Cache Management: Which Methods are Live?
21
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
to-space from-space
p()
f()
g()
h()
g()
f() g() h() i() j()
k() l()
Code Cache Management: Which Methods are Live?
21
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
to-space from-space
p()
f()
g()
h()
g()
f() g() h() i() j()
k() l()
✔ ✔ ✔
Code Cache Management: Which Methods are Live?
21
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
to-space from-space
p()
f()
g()
h()
g()
f() g() h() i() j()
k() l()
k()
✔ ✔ ✔
✔
Code Cache Management: Which Methods are Live?
21
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
to-space from-space
p()
f()
g()
h()
g()
f() g() h() i() j()
k() l()
k()
j()
✔ ✔ ✔ ✔
✔
Code Cache Management: Which Methods are Live?
21
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
to-space from-space
p()
f()
g()
h()
g()
f() g() h() i() j()
k() l()
k()
j()
✔ ✔ ✔ ✔
✔
Code Cache Management: Which Methods are Live?
21
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
to-space from-space
p()
f()
g()
h()
g()
f() g() h() i() j()
k() l()
k()
j()
live methods• methods on stack• direct callees of on-stack methods
others to protect from eviction• freshly compiled, not yet installed• invocation counter within optimisation threshold• existing type profile
✔ ✔ ✔ ✔
✔
Code Cache Management: Eviction
22
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
from-space to-space
p()
f()
g()
h()
g()
i()
l()
j()
k()
f()✔ g()✔ h()✔ j()✔
k()✔
Code Cache Management: Eviction
22
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
from-space to-space
p()
f()
g()
h()
g()
i()
l()
j()
k() course of action1. invalidate unmarked methods (and vtable entries, direct calls)
f()✔ g()✔ h()✔ j()✔
k()✔
Code Cache Management: Eviction
22
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
from-space to-space
p()
f()
g()
h()
g()
j()
k() course of action1. invalidate unmarked methods (and vtable entries, direct calls)
f()✔ g()✔ h()✔ j()✔
k()✔
Code Cache Management: Eviction
22
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
from-space to-space
p()
f()
g()
h()
g()
j()
k() course of action1. invalidate unmarked methods (and vtable entries, direct calls)2. move marked methods (update vtable entries, direct calls)
f()✔ g()✔ h()✔ j()✔
k()✔
Code Cache Management: Eviction
22
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
from-space to-space
p()
f()
g()
h()
g()
j()
k() course of action1. invalidate unmarked methods (and vtable entries, direct calls)2. move marked methods (update vtable entries, direct calls)
f() g() h() j() k()
Code Cache Management: Eviction
22
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
from-space to-space
p()
f()
g()
h()
g()
j()
k() course of action1. invalidate unmarked methods (and vtable entries, direct calls)2. move marked methods (update vtable entries, direct calls)3. patch return addresses
f() g() h() j() k()
Code Cache Management: Eviction
22
t1 call stack
baseline (T1X) method optimised (C1X) method ✔ live method
o()
T1X Cache
from-space to-space
p()
f()
g()
h()
g()
j()
k() course of action1. invalidate unmarked methods (and vtable entries, direct calls)2. move marked methods (update vtable entries, direct calls)3. patch return addresses
f() g() h() j() k()
Where Do Pointers to Machine Code Occur,and How Are They Handled?
23
vtables/itables ✓directly accessible via meta-level API (actors, hubs); invalidate (replace with trampoline calls) or relocate
direct calls ✓directly accessible via target method API (safepoints); invalidate (replace with trampoline calls) or relocate
return addresses ✓ accessible during stack walking; relocate accordingly
local variables ✖ These might have to be relocated—how to determine which Address is a code pointer?member variables ✖
These might have to be relocated—how to determine which Address is a code pointer?
Where Do Pointers to Machine Code Occur,and How Are They Handled?
23
vtables/itables ✓directly accessible via meta-level API (actors, hubs); invalidate (replace with trampoline calls) or relocate
direct calls ✓directly accessible via target method API (safepoints); invalidate (replace with trampoline calls) or relocate
return addresses ✓ accessible during stack walking; relocate accordingly
local variables ✖ These might have to be relocated—how to determine which Address is a code pointer?member variables ✖
These might have to be relocated—how to determine which Address is a code pointer?
Where Do Pointers to Machine Code Occur,and How Are They Handled?
23
vtables/itables ✓directly accessible via meta-level API (actors, hubs); invalidate (replace with trampoline calls) or relocate
direct calls ✓directly accessible via target method API (safepoints); invalidate (replace with trampoline calls) or relocate
return addresses ✓ accessible during stack walking; relocate accordingly
local variables ✖ These might have to be relocated—how to determine which Address is a code pointer?member variables ✖
These might have to be relocated—how to determine which Address is a code pointer?
Where Do Pointers to Machine Code Occur,and How Are They Handled?
23
vtables/itables ✓directly accessible via meta-level API (actors, hubs); invalidate (replace with trampoline calls) or relocate
direct calls ✓directly accessible via target method API (safepoints); invalidate (replace with trampoline calls) or relocate
return addresses ✓ accessible during stack walking; relocate accordingly
local variables ✖ These might have to be relocated—how to determine which Address is a code pointer?member variables ✖
These might have to be relocated—how to determine which Address is a code pointer?
Where Do Pointers to Machine Code Occur,and How Are They Handled?
23
vtables/itables ✓directly accessible via meta-level API (actors, hubs); invalidate (replace with trampoline calls) or relocate
direct calls ✓directly accessible via target method API (safepoints); invalidate (replace with trampoline calls) or relocate
return addresses ✓ accessible during stack walking; relocate accordingly
local variables ✖ These might have to be relocated—how to determine which Address is a code pointer?member variables ✖
These might have to be relocated—how to determine which Address is a code pointer?
Tagged Code Pointers
24
Word
Address Offset
Pointer Size
CodePointer
Object
Tagged Code Pointers
24
Word
Address Offset
Pointer Size
CodePointer
Object
1 tag bit63 bits payload (offset from base code address)
Tagged Code Pointers
24
class CodePointer { ... @INLINE public static CodePointer from(long value) { if (isHosted()) { return new CodePointer(tag(value)); } return UnsafeCast.asCodePointer(tag(value)); } ...}
Word
Address Offset
Pointer Size
CodePointer
Object
1 tag bit63 bits payload (offset from base code address)
Tagged Code Pointers
24
class CodePointer { ... @INLINE public static CodePointer from(long value) { if (isHosted()) { return new CodePointer(tag(value)); } return UnsafeCast.asCodePointer(tag(value)); } ...}
@INTRINSIC(UNSAFE_CAST)public static CodePointer asCodePointer(long value) { return CodePointer.from(value);}
Word
Address Offset
Pointer Size
CodePointer
Object
1 tag bit63 bits payload (offset from base code address)
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
i
o
j
arguments
locals
operands
1
2
3
4
5
<r>0 return address
idealised stack frame layout
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
i
o
j
arguments
locals
operands
1
2
3
4
5
<r>0 return address
idealised stack frame layout
0 1 2 3 4 5
stack reference map(at instruction 6)
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
i
o
j
arguments
locals
operands
1
2
3
4
5
<r>0 return address
idealised stack frame layout
0 1 2 3 4 5
stack reference map(at instruction 6)
void x(...) { ... MyClass o = ...; CodePointer cp = ...; ...}
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
i
o
j
arguments
locals
operands
1
2
3
4
5
<r>0 return address
idealised stack frame layout
0 1 2 3 4 5
stack reference map(at instruction 6)
void x(...) { ... MyClass o = ...; CodePointer cp = ...; ...}
0 1 2 3 4 5
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
i
o
j
arguments
locals
operands
1
2
3
4
5
<r>0 return address
idealised stack frame layout
0 1 2 3 4 5
stack reference map(at instruction 6)
void x(...) { ... MyClass o = ...; CodePointer cp = ...; ...}
0 1 2 3 4 5
Maxine VM
GC code eviction
stack reference map builder
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
i
o
j
arguments
locals
operands
1
2
3
4
5
<r>0 return address
idealised stack frame layout
0 1 2 3 4 5
stack reference map(at instruction 6)
void x(...) { ... MyClass o = ...; CodePointer cp = ...; ...}
0 1 2 3 4 5
Maxine VM
GC code eviction
stack reference map builder
ignore tagged refs,scan others
Stack Reference Maps and Tagged Code Pointers
25
static void m(int i, MyClass o) { int j = 2 * i; o.f(i);}
0: iconst_21: iload_02: imul3: istore_24: aload_15: iload_26: invokevirtual <f:(I)V>9: return
i
o
j
arguments
locals
operands
1
2
3
4
5
<r>0 return address
idealised stack frame layout
0 1 2 3 4 5
stack reference map(at instruction 6)
void x(...) { ... MyClass o = ...; CodePointer cp = ...; ...}
0 1 2 3 4 5
Maxine VM
GC code eviction
stack reference map builder
ignore tagged refs,scan others
regard and relocateonly tagged refs
<Insert
26
Thank you for your attention.
Acknowledgements: these slides are joint work of the VM research group.
Home page: http://wikis.oracle.com/display/MaxineVM/Home
Source (GPLv2): https://hg.kenai.com/hg/maxine~maxine
Mailing list via: http://kenai.com/projects/maxine