graal and truffle -...
TRANSCRIPT
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime
Thomas Wuerthinger Oracle Labs @thomaswue 24-April-2014, Keynote at MODULARITY in Lugano
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 2
Disclaimer
The following is intended to provide some insight into a line of research in Oracle Labs. 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 in connection with any Oracle product or service remains at the sole discretion of Oracle. Any views expressed in this presentation are my own and do not necessarily reflect the views of Oracle.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 3
Agenda
§ Graal § Truffle
§ Community
§ Q&A
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 4
Dimensions of Extensibility
Architectures Host Runtimes
Compilation Policy Programming Languages
Graal
X86, SPARC, HSAIL, PTX, ... HotSpotVM, SubstrateVM, ...
Java, JavaScript, Python, R, Ruby, C, Smalltalk, ...
Baseline, Mid-tier, Optimizing, Vectorizing, ...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 5
Modularity
Graal
Truffle
runtime-specific isa-specific
Graal extension
Graal/Truffle bridge
Truffle language
Fine-grained modular structure with Rich Client Platforms like Eclipse or NetBeans as role models.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 6
Specific to Host Runtime § Field/Array Access
– object/array layout, read/write barriers, … § Allocation
– garbage collector, thread-local buffer, … § Type Checks
– class hierarchy organization, … § Locking
– monitor system, monitor enter/exit, … § JDK intrinsifications
– hashCode, clone, reflection, … § Invocations
§ Safepoints
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 7
Levels of Lowering
Java
Lowered
Runtime-Specific
ISA-Specific
JavaArrayStore
NullCheck Length BoundsCheck TypeCheck Store
Read Write Barrier Cmp UCmp NullCheck
Read&Check Write Shift Read&Cmp UCmp
Read
Write
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 8
Snippets for Graph Construction
int max(int a, int b) { if (a > b) return a; else return b;}
Node max(ValueNode a, ValueNode b) { IfNode ifNode = new IfNode(new IntegerLessThanNode(a, b)); ifNode.trueSuccessor().setNext(new ReturnNode(a)); ifNode.falseSuccessor().setNext(new ReturnNode(b)); return ifNode;}
Manual construction:
Expression as snippet:
Data Code
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 9
Simple API API Provider API User
request
data
ü Can capture statically x Limited flexibility
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 10
Callback API API Provider API User
request including callback
callback with data
callback with data
callback with data
request returns
ü High flexibility x Cannot capture statically
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 11
Snippet API API Provider API User
request
code as data
ü High flexibility ü Can capture statically
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 12
Snippet Lifecycle
Bytecodes PreparedIR Graph Specialized
IR Graphs
Preparation Specialization Instantiation
Once Few Times Many Times
...aload_0 getfieldifne 10 aload_1 arraylength...
Frequency:
Java Bytecode Parsing
Node IntrinsificationExhaustive Method Inlining
Constant Folding, Canonicalization
Graph Duplication
Node IntrinsificationConstant Folding, Canonicalization
Constant Parameter ReplacementGraph DuplicationGraph Inlining in Target MethodConstant Folding, Canonicalization
Steps:
Target Method with High-level
Node
SpecializedIR Graph
of Snippet
Target Method with Low-level
Nodes
+ =
...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 13
Snippet Example: Convert
@Snippetstatic int f2i(float input, int result) {
if (probability(SLOW_PATH,result == Integer.MIN_VALUE)) {
if (Float.isNaN(input)) {return 0;
} else if (input > 0.0f) {return Integer.MAX_VALUE;
}}return result;
}
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 14
Agenda
§ Graal
§ Truffle § Community
§ Q&A
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 15
Technical Approach Speculate and Optimize…
U
U U
U
U I
I I
G
G I
I I
G
G
Node Rewriting for Profiling Feedback
AST InterpreterRewritten Nodes
AST InterpreterUninitialized Nodes
Compilation usingPartial Evaluation
Compiled Code
Node Transitions
S
UI
D
G
Uninitialized Integer
Generic
DoubleString
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 16
Technical Approach … and Deoptimize and Reoptimize!
I
I I
G
G I
I I
G
G
Deoptimizationto AST Interpreter
D
I D
G
G D
I D
G
G
Node Rewriting to Update Profiling Feedback
Recompilation usingPartial Evaluation
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 17
Technical Approach Three main parts for driving partial evaluation
§ Limit partial evaluation expansion – Annotation @SlowPath on a method stops the inclusion of a method
in the expansion.
§ Dynamic speculation – Call to CompilerDirectives.transferToInterpreter()
advises the partial evaluator to stop and place a deoptimization exit.
§ Global speculation – Assumption objects can be used for global speculations about the
system state. Checking the assumption in compiled code poses no runtime overhead.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 18
Peak Performance: JavaScript Speedup relative to V8
1.0
1.5
0.6 0.7
0.9
2.6
0.5
1.4
0.8 1.
0
0.7
0.8 1.
0
0.7
1.1
1.6
0.6
1.1
1.2
0.9
0.0
0.5
1.0
1.5
2.0
2.5
3.0
richa
rds
delta
blue
crypto
raytr
ace
navie
r-stok
es
splay
earle
y-boy
er
box2
d
gbem
u
Compo
site
Truffle
SpiderMonkey
Selection of benchmarks from Google‘s Octane benchmark suite v1.0 latest versions of V8, Truffle, and SpiderMonkey as of December 2013
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 19
Peak Performance: C Speedup relative to GCC O0
1 1 1 1 1 1
2.7
2.0 2.0
1.9
2.6
3.2
2.5
1.7
2.0
1.9
2.7
3.4
2.1
1.8 1.9
1.0
2.8
3.4
0
0.5
1
1.5
2
2.5
3
3.5
4
fannkuch-redux fasta mandelbrot meteor-contest nbody spectralnorm
GCC O0GCC BestClang BestTruf f leC
Grimmer, Rigger, Schatz, Stadler, Mössenböck: TruffleC: Dynamic Execution of C on the Java Virtual Machine; to be submitted
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 20
Agenda
§ Graal
§ Truffle
§ Community § Q&A
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 21
Graal OpenJDK Project
Graal
Truffle
JavaScript
HotSpotVM
R Ruby
Java Scala
Python Smalltalk C J
http://openjdk.java.net/projects/graal/
§ Development of Graal/Truffle core artifacts and APIs § Highly active: 30+ contributors over last 12 months § Highly modular: 80+ individual modules
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 22
Research Areas
Language Implementation
General Language Research
Compiler Construction
Experimentation with new language features, new languages, new
execution models
Language-independent instrumentation, cross-language research, automatic partial
evaluation experiments
Core compiler construction research, heterogenuous computing, advanced
architectures and backends
Truffle Interpreters
Truffle
Graal
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 23
Graal/Truffle Related Research Projects (1)
§ TruffleRuby – Development in the JRuby repository (lead Chris Seaton). – https://github.com/jruby/jruby – http://blog.jruby.org/2014/01/truffle_graal_high_performance_backend/
§ FastR – Joint effort of a group from Purdue University (Prof. Jan Vitek) and a
team at Oracle Labs (lead Michael Haupt). – https://bitbucket.org/allr/fastr
§ ZipPy – Development by a group from University of California, Irvine (Prof.
Michael Franz). – https://bitbucket.org/ssllab/zippy
§ TruffleSOM – Development by Stefan Marr at: https://github.com/smarr/
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 24
Graal/Truffle Related Research Projects (2) § C and Language Interoperability
– Experiment by students at JKU Linz (Matthias Grimmer and Manuel Rigger).
§ JavaScript – Effort done by the core Graal/Truffle team.
§ Debugging – Effort by Micheal van de Vanter from Oracle Labs.
§ SubstrateVM – Team at Oracle Labs led by Christian Wimmer is developing an alternative
host runtime.
§ Graal IR Instrumentation – Research by Yudi Zheng (USI Lugano) on instrumenting Graal IR.
§ GPU Offload – Research by Christopher Dubach et al. from the University of Edinburgh. – Graal is the compiler of choice for Project Sumatra (HSAIL/PTX offload).
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 25
Your Language or Compiler Extension? http://openjdk.java.net/projects/graal/
$ hg clone http://hg.openjdk.java.net/graal/graal $ cd graal $ ./mx --vm server build $ ./mx ideinit $ ./mx --vm server unittest SumTest
§ Truffle API License: GPLv2 with Classpath Exception
§ Graal License: GPLv2
https://wiki.openjdk.java.net/display/Graal/Main
§ Graal Resources
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 26
Acknowledgements Oracle Labs Danilo Ansaloni Daniele Bonetta Laurent Daynès Erik Eckstein Michael Haupt Peter Kessler David Leibs Mick Jordan Tom Rodriguez Roland Schatz Chris Seaton Doug Simon Lukas Stadler Michael Van De Vanter Adam Welc Christian Wimmer Christian Wirth Mario Wolczko Thomas Würthinger Laura Hill Interns Miguel Garcia Gutierrez Shams Imam
Stephen Kell Gregor Richards Rifat Shariyar JKU Linz Prof. Hanspeter Mössenböck Stefan Anzinger Gilles Duboscq Josef Eisl Matthias Grimmer Christian Häubl Josef Haider Christian Humer Christian Huber David Leopoldseder Manuel Rigger Georg Schmid Bernhard Urban Andreas Wöß University of Edinburgh Christophe Dubach Juan José Fumero Alfonso Ranjeet Singh Toomas Remmelg
LaBRI Floréal Morandat University of California, Irvine Prof. Michael Franz Codrut Stancu Gulfem Savrun Yeniceri Wei Zhang Purdue University Prof. Jan Vitek Tomas Kalibera Petr Maj Lei Zhao T. U. Dortmund Prof. Peter Marwedel Helena Kotthaus Ingo Korb University of California, Davis Prof. Duncan Temple Lang Nicholas Ulle And many more…
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 27
Q/A
http://openjdk.java.net/projects/graal/
@thomaswue