Graal and Truffle: One VM to Rule Them All

Thomas Wuerthinger
Thomas WuerthingerSenior Research Director at Oracle
Graal and Truffle:
One VM to Rule Them All

Thomas Wuerthinger
Oracle Labs
@thomaswue
12-December-2013,
at ETH Zurich
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.

2

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Agenda

§  One VM to Rule Them All?
§  Dynamic Compilation
§  Graal Compiler
§  Truffle System
§  Q&A

3

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
One Language to Rule Them All?
Let’s ask a search engine…

4

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
One Language to Rule Them All?
Let’s ask Stack Overflow…

5

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Relative Speed of Programming Languages
(as measured by the Computer Language Benchmarks Game, ~1y ago)

One VM to for all languages means
interoperability and being able to
choose the best language for the task!

3

Goal:

6

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Agenda

§  One VM to Rule Them All?
§  Dynamic Compilation
§  Graal Compiler
§  Truffle System
§  Q&A

7

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Static versus Dynamic Compilation (1)
§  Static (or ahead-of-time) Compilation
–  Compilation happens before program is run.
–  Can include profiling feedback from sample application runs.

§  Dynamic (or just-in-time) Compilation
–  Compilation happens while the program is running.
–  Base line execution (interpreter or simple compiler) gathers

profiling feeback.
–  Optimization => Deoptimization => Reoptimization cycles.
–  On-stack-replacement (OSR) to switch between the tiers (two or

more execution modes.

8

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Static versus Dynamic Compilation (2)
§  Static (or ahead-of-time) Compilation
–  Fast start-up, because compilation and profiling is not part of

application execution time.
–  Predictable performance as only the source program affects the

generated machine code.
§  Dynamic (or just-in-time) Compilation
–  Can exploit exact target platform properties when generating

machine code.
–  Profiling feedback captures part of the application behavior and

increases code quality.
–  The deoptimization capabilities allow the optimized code to be

incomplete and/or use aggressive speculation.
–  Can use assumptions about the current state of the system (e.g.,
loaded classes) in the generated code.

9

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Profiling Feedback for Java
§  Branch probabilities
–  Never taken branches can be omitted.
–  Exact probabilities allows if-cascade reordering.

§  Loop frequencies
–  Guide loop unrolling and loop invariant motion.

§  Type profile
–  Optimize instanceof, checkcast type checks (i.e., speculate that

only a specific set of types occurs)
–  Optimize virtual calls or interface calls.

Profiling feedback only helps when the program behavior during
the observed period matches the overall program behavior.

10

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Static Single Assignment (SSA) Form
§  Every variable is assigned only once.
§  Phis capture values coming from different control flow branches.
§  Commonly used in compilers as it simplifies optimizations and

traversal along the def-use and use-def chain.

...
if (condition) {
x = value1 + value2;
} else {
x = value2;
}
return x;

11

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

...
if (condition) {
x1 = value1 + value2;
} else {
x2 = value2;
}
x3 = phi(x1, x2);
return x3;
Agenda

§  One VM to Rule Them All?
§  Dynamic Compilation
§  Graal Compiler
§  Truffle System
§  Q&A

12

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Graal is an …

... extensible,
dynamic compiler using
object-oriented Java programming,
a graph intermediate representation,
and Java snippets.

13

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
HotSpotVM versus GraalVM
30k LOC

120k LOC

60k LOC

Client

Server

Graal

Compiler Interface

Compilation Queue

Compilation Queue

Compiler Interface

HotSpot

HotSpot

C++

14

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Java
Why Java?
Robustness: Runtime exceptions not fatal.
Reflection: Annotations instead of macros.
Meta-Evaluation: IR subgraph expressible in Java code.
Extensibility: No language barrier to the application.
Tooling: Java IDEs speed up the development process.

15

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Snippets for Graph Construction
Manual construction:
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;	
}

Expression as snippet:
int max(int a, int b) {	
if (a > b) return a;	
else return b;	
}

16

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Data

Code
Lowering
§  Replace one node with multiple other nodes.
–  New nodes provide more detailed description of semantics.
–  New nodes can be optimized and moved separately.

§  General Java lowerings
–  Example: Replace an array store with null check, bounds check,

store check, write operation.
if (array != null && index >= 0 && index < array.length && 	
canAssign(array.getClass().getComponentType(), value)) {	
*(array + 16 + index*8) = value;	
} else { deoptimize; }

§  VM specific lowerings
–  Examples: Replace a monitorenter with the code dependent on the

locking schemes used by the VM

17

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Gradual Lowering
3

Nodes per bytecode

2.5

2

Graal
1.5

Client
Server

1

0.5

0

After parsing

After optimizations

After lowering

Before code emission

Numbers obtained while running the DaCapo benchmark suite.

18

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Extensibility
•  Multiple Target Platforms (AMD64, SPARC, PTX, HSAIL)
•  Multiple Runtimes (HotSpot and Maxine)
•  Adding new types of Nodes
•  Adding new compiler Phases
abstract	
  class	
  Phase	
  {	
  abstract	
  void	
  run(Graph	
  g);	
  }
for	
  (IfNode	
  n	
  :	
  graph.getNodes(IfNode.class))	
  {	
  ...	
  }

Compiler has about 100 different individual modules.

19

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Graph IR
• 

Static single assignment (SSA) form with def-use and use-def edges.

• 

Program dependence graph (sea of nodes), but with explicit
distinction between control flow and data flow edges.

• 

Graph visualization tools: IdealGraphVisualizer and c1visualizer.
...	
  

condition	
  

If	
  

...
if (condition) {
result = value1 + value2;
} else {
result = value2;
}
return result;

Begin	
  

Begin	
  

End	
  

End	
  

Merge	
  

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Add	
  

Phi	
  

Return	
  

20

value1	
  

value2	
  
Guards
int get(x) {
return x.field;
}

21

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Guards
int get(x) {
if (cond) return x.field;
else return 0;
}

22

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Eliding Exception Edges
Catch
Operation

Operation
Operation

Actual

Potential
Invoke

1296646

14454

1.11%

BoundsCheck

166770

498

0.30%

NullCheck

1525061

686

0.04%

OutOfMemory

110078

0

0.00%

CheckCast

99192

0

0.00%

DivRem

6082

0

0.00%

MonitorNullCheck

33631

0

0.00%

TOTAL

3237460

15638

0.48%

Numbers obtained while running the DaCapo benchmark suite.

23

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Graal GPU Backends
JavaScript, Ruby,
Python, …

Java bytecodes

Truffle AST

Graal IR

PTX

24

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

HSAIL
Java Peak Performance
§  SPECjvm2008
114

120

100

100
80

76

60
40
20
0

Client

Graal

Server

Configura*on:	
  Intel	
  Core	
  i7-­‐3770	
  @	
  3,4	
  Ghz,	
  4	
  Cores	
  8	
  Threads,	
  16	
  GB	
  RAM	
  
Comparison	
  against	
  HotSpot	
  changeset	
  tag	
  hs25-­‐b37	
  from	
  June	
  13,	
  2013	
  

25

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Scala Peak Performance
§  Scala-Dacapo Benchmark Suite
120

100

100

106

80

61
60
40
20
0

Client

Graal

Server

Configura*on:	
  Intel	
  Core	
  i7-­‐3770	
  @	
  3,4	
  Ghz,	
  4	
  Cores	
  8	
  Threads,	
  16	
  GB	
  RAM	
  
Comparison	
  against	
  HotSpot	
  changeset	
  tag	
  hs25-­‐b37	
  from	
  June	
  13,	
  2013	
  

26

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Your Compiler Extension?
http://openjdk.java.net/projects/graal/
graal-dev@openjdk.java.net
$ hg clone http://hg.openjdk.java.net/graal/graal
$ cd graal
$ ./mx.sh --vm graal build
$ ./mx.sh ideinit
$ ./mx.sh --vm graal vm

§  Graal Resources

https://wiki.openjdk.java.net/display/Graal/Main
§  Graal License: GPLv2

27

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Agenda

§  One VM to Rule Them All?
§  Dynamic Compilation
§  Graal Compiler
§  Truffle System
§  Q&A

28

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
“Write Your Own Language”
Current situation

Prototype a new language
Parser and language work to build
syntax tree (AST), AST Interpreter
Write a “real” VM
In C/C++, still using AST interpreter,
spend a lot of time implementing
runtime system, GC, …
People start using it
People complain about performance
Define a bytecode format and
write bytecode interpreter
Performance is still bad
Write a JIT compiler
Improve the garbage collector

29

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

How it should be

Prototype a new language in Java
Parser and language work to build
syntax tree (AST)
Execute using AST interpreter
People start using it
And it is already fast
Truffle: System Structure

Written by:
Application
Developer

Written in:

Guest Language Application

Guest Language

Language
Developer

Guest Language Implementation

Managed Host Language

VM Expert

Host Services

Managed Host Language
or Unmanaged Language

OS Expert

OS

30

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Unmanaged Language
(typically C or C++)
Speculate and Optimize …

Node Rewriting
for Profiling Feedback

U

Compilation using
Partial Evaluation

G

G
U

U

Node Transitions
U

U

I
Uninitialized

S
AST Interpreter
Uninitialized Nodes

I

G
I

I

D

String

Double

G
Generic

31

I

Integer

I

U

I

G

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

AST Interpreter
Rewritten Nodes

Compiled Code
Partial Evaluation
§  Example function:
–  f(x, y) = x + y + 1

§  Partial evaluation of example function:
–  g(y) = f(1, y) = 1 + y + 1 = y + 2

§  Interpreter function:
–  f(program, arguments) = calculations to interpret the program

§  Partial evaluation of interpreter function (first Futamura projection):
–  g(arguments) = f(#specificProgram, arguments) = compiled version of

#specificProgram that takes arguments as parameters

32

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
… and Deoptimize and Reoptimize!

Deoptimization
to AST Interpreter

Node Rewriting to Update
Profiling Feedback

G

Recompilation using
Partial Evaluation

G

G
I
I

G
I

G

D

G

I

I
I

33

D

G

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

I

I

D

G
D
Object add(Object a, Object b) {
if(a instanceof Integer && b instanceof Integer) {
return (int)a + (int)b;
} else if (a instanceof String && b instanceof String) {
return (String)a + (String)b;
} else {
return genericAdd(a, b);
}
}

int add(int a,

String add(String a,

int b) {

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

return genericAdd(a, b);

return a + b;
}

34

Object b) {

String b) {

return a + b;
}

Object add(Object a,

}
Node Implementation
class IAddNode extends BinaryNode {
int executeInt(Frame f) throws UnexpectedResult {
int a;
try {
a = left.executeInt(f);
} catch (UnexpectedResult ex) {
throw rewrite(f, ex.result, right.execute(f));
}
int b;
try {
b = right.executeInt(f);
} catch (UnexpectedResult ex) {
throw rewrite(f, a, ex.result);
}
try {
return Math.addExact(a, b);
} catch (ArithmeticException ex) {
throw rewrite(f, a, b);
}
}

35

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Uninitialized

Double

String

Generic

36

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Specializing
FSA
Truffle DSL
@Specialization(rewriteOn=ArithmeticException.class)
int addInt(int a, int b) {
return Math.addExact(a, b);
}
@Specialization
double addDouble(double a, double b) {
return a + b;
}
@Generic
Object addGeneric(Frame f, Object a, Object b) {
// Handling of String omitted for simplicity.
Number aNum = Runtime.toNumber(f, a);
Number bNum = Runtime.toNumber(f, b);
return Double.valueOf(aNum.doubleValue() +
bNum.doubleValue());
}

37

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Inline Caching
uninitialized

monomorphic

polymorphic

U

S

megamorphic

S

G
U

S

…

S

U

38

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Method Inlining

39

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Method Inlining

40

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Truffle API Compiler Directives
§  Guards
if(condition)	
  {	
  
	
  	
  //	
  some	
  code	
  that	
  is	
  only	
  valid	
  if	
  condition	
  is	
  true	
  
}	
  else	
  {	
  
	
  	
  CompilerDirectives.transferToInterpreter();	
  
}	
  

§  Assumptions
Assumption	
  assumption	
  =	
  Truffle.getRuntime().createAssumption();	
  

assumption.check();	
  
//	
  some	
  code	
  that	
  is	
  only	
  valid	
  if	
  assumption	
  is	
  true	
  

assumption.invalidate();	
  

41

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Performance Number Disclaimers
§  All Truffle numbers reflect the current development snapshot.
–  Subject to change at any time (hopefully improve)
–  You have to know a benchmark to understand why it is slow or fast

§  We are not claiming to have complete language implementations.
–  JavaScript: quite complete, passing 99.8% of ECMAScript262 tests
–  Ruby: passing >45% of RubySpec language tests
–  R: early prototype

§  We measure against latest versions of competitors.
§  We measure peak performance (i.e., giving each benchmark enough

iterations to warmup before starting measurement).

§  Benchmarks that are not shown
–  may not run at all, or
–  may not run fast

42

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Peak Performance: JavaScript
Speedup relative to V8
2.6

3.0
Truffle
SpiderMonkey

2.5

0.8

1.0
0.9

1.2

1.1

0.9
1.1

0.5
0.6

0.7
0.7

1.0
0.6

1.0

0.8

1.0
0.7

1.5

1.4

1.5

1.6

2.0

0.5

te

u
C

om

po

si

em
gb

x2
bo

bo
yrle

d

r
ye

y
la
ea

na

vi

er

-s

to
k

sp

es

e
ra
y

tra
c

to
cr
yp

bl
lta
de

ric

ha

rd

s

ue

0.0

Selection of benchmarks from Google‘s Octane benchmark suite v1.0

43

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Peak Performance: Ruby
Speedup relative to JRuby 1.7.5

14

14
14

16
MRI 2.0.0
Topaz

12

Truf f le
10

0

44

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

0.6
1.0
1.7

1.8

0.8

1.7
2.7
1.1

0.5

0.2

0.4
0.3
0.7

2

1.7
2.7

4

0.7

4.7
4.5

6

4.9

8
Peak Performance: R
94

Speedup relative to GNUR
100.0
90.0
80.0
70.0
60.0

22

30.0

0.0

45

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

0.8

2.7

2.1

10.0

2.0

14

20.0

23

40.0

24

38

39

50.0
Language Implementations

Simple
Language

Ruby

C

R

46

JavaScript

Python

Smalltalk

Your
language?

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

Java
Your Language?
http://openjdk.java.net/projects/graal/
graal-dev@openjdk.java.net
$ hg clone http://hg.openjdk.java.net/graal/graal
$ cd graal
$ ./mx.sh --vm server build
$ ./mx.sh ideinit
$ ./mx.sh --vm server unittest SumTest

§  Truffle API Resources

https://wiki.openjdk.java.net/display/Graal/Truffle+FAQ+and+Guidelines
§  Truffle API License: GPLv2 with Classpath Exception

47

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Acknowledgements
Oracle Labs
Laurent Daynès
Erik Eckstein
Michael Haupt
Peter Kessler
Christos Kotselidis
David Leibs
Roland Schatz
Chris Seaton
Doug Simon
Michael Van De Vanter
Christian Wimmer
Christian Wirth
Mario Wolczko
Thomas Würthinger
Laura Hill (Manager)
Interns
Danilo Ansaloni
Daniele Bonetta
Shams Imam
Stephen Kell
Gregor Richards
Rifat Shariyar

48

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

JKU Linz
Prof. Hanspeter Mössenböck
Gilles Duboscq
Matthias Grimmer
Christian Häubl
Josef Haider
Christian Humer
Christian Huber
Manuel Rigger
Lukas Stadler
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
http://openjdk.java.net/projects/graal/
graal-dev@openjdk.java.net
@thomaswue

Q/A

49

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
50

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
51

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
1 of 51

Recommended

JVM++: The Graal VM by
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VMMartin Toshev
6K views45 slides
Introduction to GraalVM by
Introduction to GraalVMIntroduction to GraalVM
Introduction to GraalVMSHASHI KUMAR
350 views14 slides
GraalVM by
GraalVMGraalVM
GraalVMNexThoughts Technologies
923 views15 slides
Cloud Native Java GraalVM 이상과 현실 by
Cloud Native Java GraalVM 이상과 현실Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실Taewan Kim
3.5K views88 slides
GraalVM Native and Spring Boot 3.0 by
GraalVM Native and Spring Boot 3.0GraalVM Native and Spring Boot 3.0
GraalVM Native and Spring Boot 3.0MoritzHalbritter
186 views26 slides
GraalVM Overview Compact version by
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact versionscalaconfjp
2K views70 slides

More Related Content

What's hot

Top 10 reasons to migrate to Gradle by
Top 10 reasons to migrate to GradleTop 10 reasons to migrate to Gradle
Top 10 reasons to migrate to GradleStrannik_2013
2.5K views71 slides
Scalability, Availability & Stability Patterns by
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
515.7K views196 slides
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013 by
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013mumrah
61.2K views43 slides
From cache to in-memory data grid. Introduction to Hazelcast. by
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
42.6K views83 slides
Quarkus - a next-generation Kubernetes Native Java framework by
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkSVDevOps
606 views42 slides
Quarkus Denmark 2019 by
Quarkus Denmark 2019Quarkus Denmark 2019
Quarkus Denmark 2019Max Andersen
606 views44 slides

What's hot(20)

Top 10 reasons to migrate to Gradle by Strannik_2013
Top 10 reasons to migrate to GradleTop 10 reasons to migrate to Gradle
Top 10 reasons to migrate to Gradle
Strannik_20132.5K views
Scalability, Availability & Stability Patterns by Jonas Bonér
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
Jonas Bonér515.7K views
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013 by mumrah
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
mumrah61.2K views
From cache to in-memory data grid. Introduction to Hazelcast. by Taras Matyashovsky
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky42.6K views
Quarkus - a next-generation Kubernetes Native Java framework by SVDevOps
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java framework
SVDevOps606 views
Quarkus Denmark 2019 by Max Andersen
Quarkus Denmark 2019Quarkus Denmark 2019
Quarkus Denmark 2019
Max Andersen606 views
Cassandra Introduction & Features by DataStax Academy
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
DataStax Academy31.9K views
Introduction to Redis by Dvir Volk
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk121K views
Modern Java Workshop by Simon Ritter
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
Simon Ritter739 views
Mastering Java Bytecode With ASM - 33rd degree, 2012 by Anton Arhipov
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012
Anton Arhipov8K views
Building flexible ETL pipelines with Apache Camel on Quarkus by Ivelin Yanev
Building flexible ETL pipelines with Apache Camel on QuarkusBuilding flexible ETL pipelines with Apache Camel on Quarkus
Building flexible ETL pipelines with Apache Camel on Quarkus
Ivelin Yanev395 views
Introduction to Apache Camel by Claus Ibsen
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
Claus Ibsen5.6K views
A visual introduction to Apache Kafka by Paul Brebner
A visual introduction to Apache KafkaA visual introduction to Apache Kafka
A visual introduction to Apache Kafka
Paul Brebner4.7K views
Introduction to Apache ZooKeeper by Saurav Haloi
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
Saurav Haloi128.4K views
How Apache Kafka® Works by confluent
How Apache Kafka® WorksHow Apache Kafka® Works
How Apache Kafka® Works
confluent11.4K views
Top 5 Mistakes to Avoid When Writing Apache Spark Applications by Cloudera, Inc.
Top 5 Mistakes to Avoid When Writing Apache Spark ApplicationsTop 5 Mistakes to Avoid When Writing Apache Spark Applications
Top 5 Mistakes to Avoid When Writing Apache Spark Applications
Cloudera, Inc.127.8K views
Stability Patterns for Microservices by pflueras
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservices
pflueras1.9K views

Viewers also liked

Graal Tutorial at CGO 2015 by Christian Wimmer by
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerThomas Wuerthinger
4.9K views92 slides
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ... by
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...Thomas Wuerthinger
3.3K views29 slides
Ruby memory model by
Ruby memory modelRuby memory model
Ruby memory modelHari Krishnan‎
988 views36 slides
Automated Debugging: Are We There Yet? by
Automated Debugging: Are We There Yet?Automated Debugging: Are We There Yet?
Automated Debugging: Are We There Yet?Alex Orso
2.2K views84 slides
The HercuLeS HLS Environment by
The HercuLeS HLS EnvironmentThe HercuLeS HLS Environment
The HercuLeS HLS Environmentkaveirious
1.4K views56 slides
Graal VM: Multi-Language Execution Platform by
Graal VM: Multi-Language Execution PlatformGraal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution PlatformThomas Wuerthinger
3.3K views23 slides

Viewers also liked(15)

Graal Tutorial at CGO 2015 by Christian Wimmer by Thomas Wuerthinger
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian Wimmer
Thomas Wuerthinger4.9K views
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ... by Thomas Wuerthinger
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Thomas Wuerthinger3.3K views
Automated Debugging: Are We There Yet? by Alex Orso
Automated Debugging: Are We There Yet?Automated Debugging: Are We There Yet?
Automated Debugging: Are We There Yet?
Alex Orso2.2K views
The HercuLeS HLS Environment by kaveirious
The HercuLeS HLS EnvironmentThe HercuLeS HLS Environment
The HercuLeS HLS Environment
kaveirious1.4K views
Graal VM: Multi-Language Execution Platform by Thomas Wuerthinger
Graal VM: Multi-Language Execution PlatformGraal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution Platform
Thomas Wuerthinger3.3K views
Model Slicing by ClarkTony
Model SlicingModel Slicing
Model Slicing
ClarkTony49.9K views
2016 JavaOne Deconstructing REST Security by David Blevins
2016 JavaOne Deconstructing REST Security2016 JavaOne Deconstructing REST Security
2016 JavaOne Deconstructing REST Security
David Blevins1K views
The HaLVM: A Simple Platform for Simple Platforms by The Linux Foundation
The HaLVM: A Simple Platform for Simple PlatformsThe HaLVM: A Simple Platform for Simple Platforms
The HaLVM: A Simple Platform for Simple Platforms
The Linux Foundation30.5K views
Programing Slicing and Its applications by Ankur Jain
Programing Slicing and Its applicationsPrograming Slicing and Its applications
Programing Slicing and Its applications
Ankur Jain2.7K views
Java 9 – The Ultimate Feature List by Takipi
Java 9 – The Ultimate Feature ListJava 9 – The Ultimate Feature List
Java 9 – The Ultimate Feature List
Takipi73.6K views
Ten Reasons Why You Should Prefer PostgreSQL to MySQL by anandology
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
anandology46.5K views

Similar to Graal and Truffle: One VM to Rule Them All

Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ... by
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...AMD Developer Central
4.8K views39 slides
Production Time Profiling Out of the Box by
Production Time Profiling Out of the BoxProduction Time Profiling Out of the Box
Production Time Profiling Out of the BoxMarcus Hirt
1.6K views32 slides
20160908 hivemall meetup by
20160908 hivemall meetup20160908 hivemall meetup
20160908 hivemall meetupTakeshi Yamamuro
1.9K views15 slides
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs by
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMayank Prasad
951 views36 slides
MySQL Replication by
MySQL ReplicationMySQL Replication
MySQL ReplicationMark Swarbrick
724 views53 slides
Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St... by
Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St...Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St...
Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St...Spark Summit
670 views21 slides

Similar to Graal and Truffle: One VM to Rule Them All(20)

Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ... by AMD Developer Central
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Production Time Profiling Out of the Box by Marcus Hirt
Production Time Profiling Out of the BoxProduction Time Profiling Out of the Box
Production Time Profiling Out of the Box
Marcus Hirt1.6K views
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs by Mayank Prasad
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
Mayank Prasad951 views
Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St... by Spark Summit
Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St...Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St...
Accelerating Spark Genome Sequencing in Cloud—A Data Driven Approach, Case St...
Spark Summit670 views
A MySQL Odyssey - A Blackhole Crossover by Keith Hollman
A MySQL Odyssey - A Blackhole CrossoverA MySQL Odyssey - A Blackhole Crossover
A MySQL Odyssey - A Blackhole Crossover
Keith Hollman919 views
OSI_MySQL_Performance Schema by Mayank Prasad
OSI_MySQL_Performance SchemaOSI_MySQL_Performance Schema
OSI_MySQL_Performance Schema
Mayank Prasad617 views
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by... by scalaconfjp
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...
Run Scala Faster with GraalVM on any Platform / GraalVMで、どこでもScalaを高速実行しよう by...
scalaconfjp842 views
2015 Java update and roadmap, JUG sevilla by Trisha Gee
2015  Java update and roadmap, JUG sevilla2015  Java update and roadmap, JUG sevilla
2015 Java update and roadmap, JUG sevilla
Trisha Gee13.1K views
"Quantum" Performance Effects by Sergey Kuksenko
"Quantum" Performance Effects"Quantum" Performance Effects
"Quantum" Performance Effects
Sergey Kuksenko4.8K views
AskTom: How to Make and Test Your Application "Oracle RAC Ready"? by Markus Michalewicz
AskTom: How to Make and Test Your Application "Oracle RAC Ready"?AskTom: How to Make and Test Your Application "Oracle RAC Ready"?
AskTom: How to Make and Test Your Application "Oracle RAC Ready"?
Markus Michalewicz1.5K views
(ZDM) Zero Downtime DB Migration to Oracle Cloud by Ruggero Citton
(ZDM) Zero Downtime DB Migration to Oracle Cloud(ZDM) Zero Downtime DB Migration to Oracle Cloud
(ZDM) Zero Downtime DB Migration to Oracle Cloud
Ruggero Citton204 views
Premier integration with logix, pf drives and ft view (pf755) by confidencial
Premier integration with logix, pf drives and ft view (pf755)Premier integration with logix, pf drives and ft view (pf755)
Premier integration with logix, pf drives and ft view (pf755)
confidencial 1.7K views
Java and Serverless - A Match Made In Heaven, Part 2 by Curity
Java and Serverless - A Match Made In Heaven, Part 2Java and Serverless - A Match Made In Heaven, Part 2
Java and Serverless - A Match Made In Heaven, Part 2
Curity66 views
How to lock a Python in a cage? Managing Python environment inside an R project by WLOG Solutions
How to lock a Python in a cage?  Managing Python environment inside an R projectHow to lock a Python in a cage?  Managing Python environment inside an R project
How to lock a Python in a cage? Managing Python environment inside an R project
WLOG Solutions577 views
Java Memory Hogs.pdf by Gurbinder3
Java Memory Hogs.pdfJava Memory Hogs.pdf
Java Memory Hogs.pdf
Gurbinder39 views

Recently uploaded

Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
17 views1 slide
Spesifikasi Lengkap ASUS Vivobook Go 14 by
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14Dot Semarang
35 views1 slide
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
15 views13 slides
RADIUS-Omnichannel Interaction System by
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction SystemRADIUS
15 views21 slides
Empathic Computing: Delivering the Potential of the Metaverse by
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the MetaverseMark Billinghurst
470 views80 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
27 views43 slides

Recently uploaded(20)

Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta15 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... by NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS37 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views

Graal and Truffle: One VM to Rule Them All

  • 1. Graal and Truffle: One VM to Rule Them All Thomas Wuerthinger Oracle Labs @thomaswue 12-December-2013, at ETH Zurich
  • 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. 2 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 3. Agenda §  One VM to Rule Them All? §  Dynamic Compilation §  Graal Compiler §  Truffle System §  Q&A 3 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 4. One Language to Rule Them All? Let’s ask a search engine… 4 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 5. One Language to Rule Them All? Let’s ask Stack Overflow… 5 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 6. Relative Speed of Programming Languages (as measured by the Computer Language Benchmarks Game, ~1y ago) One VM to for all languages means interoperability and being able to choose the best language for the task! 3 Goal: 6 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 7. Agenda §  One VM to Rule Them All? §  Dynamic Compilation §  Graal Compiler §  Truffle System §  Q&A 7 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 8. Static versus Dynamic Compilation (1) §  Static (or ahead-of-time) Compilation –  Compilation happens before program is run. –  Can include profiling feedback from sample application runs. §  Dynamic (or just-in-time) Compilation –  Compilation happens while the program is running. –  Base line execution (interpreter or simple compiler) gathers profiling feeback. –  Optimization => Deoptimization => Reoptimization cycles. –  On-stack-replacement (OSR) to switch between the tiers (two or more execution modes. 8 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 9. Static versus Dynamic Compilation (2) §  Static (or ahead-of-time) Compilation –  Fast start-up, because compilation and profiling is not part of application execution time. –  Predictable performance as only the source program affects the generated machine code. §  Dynamic (or just-in-time) Compilation –  Can exploit exact target platform properties when generating machine code. –  Profiling feedback captures part of the application behavior and increases code quality. –  The deoptimization capabilities allow the optimized code to be incomplete and/or use aggressive speculation. –  Can use assumptions about the current state of the system (e.g., loaded classes) in the generated code. 9 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 10. Profiling Feedback for Java §  Branch probabilities –  Never taken branches can be omitted. –  Exact probabilities allows if-cascade reordering. §  Loop frequencies –  Guide loop unrolling and loop invariant motion. §  Type profile –  Optimize instanceof, checkcast type checks (i.e., speculate that only a specific set of types occurs) –  Optimize virtual calls or interface calls. Profiling feedback only helps when the program behavior during the observed period matches the overall program behavior. 10 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 11. Static Single Assignment (SSA) Form §  Every variable is assigned only once. §  Phis capture values coming from different control flow branches. §  Commonly used in compilers as it simplifies optimizations and traversal along the def-use and use-def chain. ... if (condition) { x = value1 + value2; } else { x = value2; } return x; 11 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. ... if (condition) { x1 = value1 + value2; } else { x2 = value2; } x3 = phi(x1, x2); return x3;
  • 12. Agenda §  One VM to Rule Them All? §  Dynamic Compilation §  Graal Compiler §  Truffle System §  Q&A 12 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 13. Graal is an … ... extensible, dynamic compiler using object-oriented Java programming, a graph intermediate representation, and Java snippets. 13 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 14. HotSpotVM versus GraalVM 30k LOC 120k LOC 60k LOC Client Server Graal Compiler Interface Compilation Queue Compilation Queue Compiler Interface HotSpot HotSpot C++ 14 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Java
  • 15. Why Java? Robustness: Runtime exceptions not fatal. Reflection: Annotations instead of macros. Meta-Evaluation: IR subgraph expressible in Java code. Extensibility: No language barrier to the application. Tooling: Java IDEs speed up the development process. 15 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 16. Snippets for Graph Construction Manual construction: 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; } Expression as snippet: int max(int a, int b) { if (a > b) return a; else return b; } 16 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Data Code
  • 17. Lowering §  Replace one node with multiple other nodes. –  New nodes provide more detailed description of semantics. –  New nodes can be optimized and moved separately. §  General Java lowerings –  Example: Replace an array store with null check, bounds check, store check, write operation. if (array != null && index >= 0 && index < array.length && canAssign(array.getClass().getComponentType(), value)) { *(array + 16 + index*8) = value; } else { deoptimize; } §  VM specific lowerings –  Examples: Replace a monitorenter with the code dependent on the locking schemes used by the VM 17 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 18. Gradual Lowering 3 Nodes per bytecode 2.5 2 Graal 1.5 Client Server 1 0.5 0 After parsing After optimizations After lowering Before code emission Numbers obtained while running the DaCapo benchmark suite. 18 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 19. Extensibility •  Multiple Target Platforms (AMD64, SPARC, PTX, HSAIL) •  Multiple Runtimes (HotSpot and Maxine) •  Adding new types of Nodes •  Adding new compiler Phases abstract  class  Phase  {  abstract  void  run(Graph  g);  } for  (IfNode  n  :  graph.getNodes(IfNode.class))  {  ...  } Compiler has about 100 different individual modules. 19 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 20. Graph IR •  Static single assignment (SSA) form with def-use and use-def edges. •  Program dependence graph (sea of nodes), but with explicit distinction between control flow and data flow edges. •  Graph visualization tools: IdealGraphVisualizer and c1visualizer. ...   condition   If   ... if (condition) { result = value1 + value2; } else { result = value2; } return result; Begin   Begin   End   End   Merge   Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Add   Phi   Return   20 value1   value2  
  • 21. Guards int get(x) { return x.field; } 21 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 22. Guards int get(x) { if (cond) return x.field; else return 0; } 22 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 24. Graal GPU Backends JavaScript, Ruby, Python, … Java bytecodes Truffle AST Graal IR PTX 24 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. HSAIL
  • 25. Java Peak Performance §  SPECjvm2008 114 120 100 100 80 76 60 40 20 0 Client Graal Server Configura*on:  Intel  Core  i7-­‐3770  @  3,4  Ghz,  4  Cores  8  Threads,  16  GB  RAM   Comparison  against  HotSpot  changeset  tag  hs25-­‐b37  from  June  13,  2013   25 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 26. Scala Peak Performance §  Scala-Dacapo Benchmark Suite 120 100 100 106 80 61 60 40 20 0 Client Graal Server Configura*on:  Intel  Core  i7-­‐3770  @  3,4  Ghz,  4  Cores  8  Threads,  16  GB  RAM   Comparison  against  HotSpot  changeset  tag  hs25-­‐b37  from  June  13,  2013   26 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 27. Your Compiler Extension? http://openjdk.java.net/projects/graal/ graal-dev@openjdk.java.net $ hg clone http://hg.openjdk.java.net/graal/graal $ cd graal $ ./mx.sh --vm graal build $ ./mx.sh ideinit $ ./mx.sh --vm graal vm §  Graal Resources https://wiki.openjdk.java.net/display/Graal/Main §  Graal License: GPLv2 27 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 28. Agenda §  One VM to Rule Them All? §  Dynamic Compilation §  Graal Compiler §  Truffle System §  Q&A 28 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 29. “Write Your Own Language” Current situation Prototype a new language Parser and language work to build syntax tree (AST), AST Interpreter Write a “real” VM In C/C++, still using AST interpreter, spend a lot of time implementing runtime system, GC, … People start using it People complain about performance Define a bytecode format and write bytecode interpreter Performance is still bad Write a JIT compiler Improve the garbage collector 29 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. How it should be Prototype a new language in Java Parser and language work to build syntax tree (AST) Execute using AST interpreter People start using it And it is already fast
  • 30. Truffle: System Structure Written by: Application Developer Written in: Guest Language Application Guest Language Language Developer Guest Language Implementation Managed Host Language VM Expert Host Services Managed Host Language or Unmanaged Language OS Expert OS 30 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Unmanaged Language (typically C or C++)
  • 31. Speculate and Optimize … Node Rewriting for Profiling Feedback U Compilation using Partial Evaluation G G U U Node Transitions U U I Uninitialized S AST Interpreter Uninitialized Nodes I G I I D String Double G Generic 31 I Integer I U I G Copyright © 2013, Oracle and/or its affiliates. All rights reserved. AST Interpreter Rewritten Nodes Compiled Code
  • 32. Partial Evaluation §  Example function: –  f(x, y) = x + y + 1 §  Partial evaluation of example function: –  g(y) = f(1, y) = 1 + y + 1 = y + 2 §  Interpreter function: –  f(program, arguments) = calculations to interpret the program §  Partial evaluation of interpreter function (first Futamura projection): –  g(arguments) = f(#specificProgram, arguments) = compiled version of #specificProgram that takes arguments as parameters 32 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 33. … and Deoptimize and Reoptimize! Deoptimization to AST Interpreter Node Rewriting to Update Profiling Feedback G Recompilation using Partial Evaluation G G I I G I G D G I I I 33 D G Copyright © 2013, Oracle and/or its affiliates. All rights reserved. I I D G D
  • 34. Object add(Object a, Object b) { if(a instanceof Integer && b instanceof Integer) { return (int)a + (int)b; } else if (a instanceof String && b instanceof String) { return (String)a + (String)b; } else { return genericAdd(a, b); } } int add(int a, String add(String a, int b) { Copyright © 2013, Oracle and/or its affiliates. All rights reserved. return genericAdd(a, b); return a + b; } 34 Object b) { String b) { return a + b; } Object add(Object a, }
  • 35. Node Implementation class IAddNode extends BinaryNode { int executeInt(Frame f) throws UnexpectedResult { int a; try { a = left.executeInt(f); } catch (UnexpectedResult ex) { throw rewrite(f, ex.result, right.execute(f)); } int b; try { b = right.executeInt(f); } catch (UnexpectedResult ex) { throw rewrite(f, a, ex.result); } try { return Math.addExact(a, b); } catch (ArithmeticException ex) { throw rewrite(f, a, b); } } 35 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 36. Uninitialized Double String Generic 36 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Specializing FSA
  • 37. Truffle DSL @Specialization(rewriteOn=ArithmeticException.class) int addInt(int a, int b) { return Math.addExact(a, b); } @Specialization double addDouble(double a, double b) { return a + b; } @Generic Object addGeneric(Frame f, Object a, Object b) { // Handling of String omitted for simplicity. Number aNum = Runtime.toNumber(f, a); Number bNum = Runtime.toNumber(f, b); return Double.valueOf(aNum.doubleValue() + bNum.doubleValue()); } 37 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 39. Method Inlining 39 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 40. Method Inlining 40 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 41. Truffle API Compiler Directives §  Guards if(condition)  {      //  some  code  that  is  only  valid  if  condition  is  true   }  else  {      CompilerDirectives.transferToInterpreter();   }   §  Assumptions Assumption  assumption  =  Truffle.getRuntime().createAssumption();   assumption.check();   //  some  code  that  is  only  valid  if  assumption  is  true   assumption.invalidate();   41 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 42. Performance Number Disclaimers §  All Truffle numbers reflect the current development snapshot. –  Subject to change at any time (hopefully improve) –  You have to know a benchmark to understand why it is slow or fast §  We are not claiming to have complete language implementations. –  JavaScript: quite complete, passing 99.8% of ECMAScript262 tests –  Ruby: passing >45% of RubySpec language tests –  R: early prototype §  We measure against latest versions of competitors. §  We measure peak performance (i.e., giving each benchmark enough iterations to warmup before starting measurement). §  Benchmarks that are not shown –  may not run at all, or –  may not run fast 42 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 43. Peak Performance: JavaScript Speedup relative to V8 2.6 3.0 Truffle SpiderMonkey 2.5 0.8 1.0 0.9 1.2 1.1 0.9 1.1 0.5 0.6 0.7 0.7 1.0 0.6 1.0 0.8 1.0 0.7 1.5 1.4 1.5 1.6 2.0 0.5 te u C om po si em gb x2 bo bo yrle d r ye y la ea na vi er -s to k sp es e ra y tra c to cr yp bl lta de ric ha rd s ue 0.0 Selection of benchmarks from Google‘s Octane benchmark suite v1.0 43 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 44. Peak Performance: Ruby Speedup relative to JRuby 1.7.5 14 14 14 16 MRI 2.0.0 Topaz 12 Truf f le 10 0 44 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 0.6 1.0 1.7 1.8 0.8 1.7 2.7 1.1 0.5 0.2 0.4 0.3 0.7 2 1.7 2.7 4 0.7 4.7 4.5 6 4.9 8
  • 45. Peak Performance: R 94 Speedup relative to GNUR 100.0 90.0 80.0 70.0 60.0 22 30.0 0.0 45 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 0.8 2.7 2.1 10.0 2.0 14 20.0 23 40.0 24 38 39 50.0
  • 47. Your Language? http://openjdk.java.net/projects/graal/ graal-dev@openjdk.java.net $ hg clone http://hg.openjdk.java.net/graal/graal $ cd graal $ ./mx.sh --vm server build $ ./mx.sh ideinit $ ./mx.sh --vm server unittest SumTest §  Truffle API Resources https://wiki.openjdk.java.net/display/Graal/Truffle+FAQ+and+Guidelines §  Truffle API License: GPLv2 with Classpath Exception 47 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 48. Acknowledgements Oracle Labs Laurent Daynès Erik Eckstein Michael Haupt Peter Kessler Christos Kotselidis David Leibs Roland Schatz Chris Seaton Doug Simon Michael Van De Vanter Christian Wimmer Christian Wirth Mario Wolczko Thomas Würthinger Laura Hill (Manager) Interns Danilo Ansaloni Daniele Bonetta Shams Imam Stephen Kell Gregor Richards Rifat Shariyar 48 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. JKU Linz Prof. Hanspeter Mössenböck Gilles Duboscq Matthias Grimmer Christian Häubl Josef Haider Christian Humer Christian Huber Manuel Rigger Lukas Stadler 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
  • 50. 50 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 51. 51 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.