+ All Categories
Home > Science > Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose...

Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose...

Date post: 23-Aug-2014
Category:
Upload: thomas-wuerthinger
View: 380 times
Download: 7 times
Share this document with a friend
Description:
Multi-language runtimes providing simultaneously high performance for several programming languages still remain an illusion. Industrial-strength managed language runtimes are built with a focus on one language (e.g., Java or C#). Other languages may compile to the bytecode formats of those managed language runtimes. However, the performance characteristics of the bytecode generation approach are often lagging behind compared to language runtimes specialized for a specific language. The performance of JavaScript is for example still orders of magnitude better on specialized runtimes (e.g., V8 or SpiderMonkey). We present a solution to this problem by providing guest languages with a new way of interfacing with the host runtime. The semantics of the guest language is communicated to the host runtime not via generating bytecodes, but via an interpreter written in the host language. This gives guest languages a simple way to express the semantics of their operations including language-specific mechanisms for collecting profiling feedback. The efficient machine code is derived from the interpreter via automatic partial evaluation. The main components reused from the underlying runtime are the compiler and the garbage collector. They are both agnostic to the executed guest languages. The host compiler derives the optimized machine code for hot parts of the guest language application via partial evaluation of the guest language interpreter. The interpreter definition can guide the host compiler to generate deoptimization points, i.e., exits from the compiled code. This allows guest language operations to use speculations: An operation could for example speculate that the type of an incoming parameter is constant. Furthermore, the guest language interpreter can use global assumptions about the system state that are registered with the compiled code. Finally, part of the interpreter's code can be excluded from the partial evaluation and remain shared across the system. This is useful for avoiding code explosion and appropriate for infrequently executed paths of an operation. These basic mechanisms are provided by the underlying language-agnostic host runtime and allow separation of concerns between guest and host runtime. We implemented Truffle, the guest language runtime framework, on top of the Graal compiler and the HotSpot virtual machine. So far, there are prototypes for C, J, Python, JavaScript, R, Ruby, and Smalltalk running on top of the Truffle framework. The prototypes are still incomplete with respect to language semantics. However, most of them can run non-trivial benchmarks to demonstrate the core promise of the Truffle system: Multiple languages within one runtime system at competitive performance.
Popular Tags:
29
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
Transcript
Page 1: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 2: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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.

Page 3: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Agenda

§  Graal §  Truffle

§  Community

§  Q&A

Page 4: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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, ...

Page 5: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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.

Page 6: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 7: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 8: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 9: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 10: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 11: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 12: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

+ =

...

Page 13: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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;

}

Page 14: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Agenda

§  Graal

§  Truffle §  Community

§  Q&A

Page 15: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 16: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 17: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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.

Page 18: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 19: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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  

Page 20: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Agenda

§  Graal

§  Truffle

§  Community §  Q&A

Page 21: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 22: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 23: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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/

Page 24: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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).

Page 25: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Your Language or Compiler Extension? http://openjdk.java.net/projects/graal/

[email protected]

$ 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

Page 26: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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…

Page 27: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Q/A

http://openjdk.java.net/projects/graal/

[email protected]

@thomaswue

Page 28: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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

Page 29: Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime

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


Recommended