Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime
Upcoming SlideShare
Loading in...5
×
 

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

on

  • 512 views

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

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.

Statistics

Views

Total Views
512
Views on SlideShare
491
Embed Views
21

Actions

Likes
1
Downloads
11
Comments
0

4 Embeds 21

https://twitter.com 11
http://www.slideee.com 8
http://www.linkedin.com 1
https://www.linkedin.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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 Presentation 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-specificisa-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 WriteBarrierCmpUCmpNullCheck Read&Check WriteShiftRead&CmpUCmp 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 ProviderAPI User request data ü  Can capture statically x  Limited flexibility
  • Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10 Callback API API ProviderAPI 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 ProviderAPI User request code as data ü  High flexibility ü  Can capture statically
  • Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12 Snippet Lifecycle Bytecodes Prepared IR Graph Specialized IR Graphs Preparation Specialization Instantiation Once Few Times Many Times ... aload_0 getfield ifne 10 aload_1 arraylength ... Frequency: Java Bytecode Parsing Node Intrinsification Exhaustive Method Inlining Constant Folding, Canonicalization Graph Duplication Node Intrinsification Constant Folding, Canonicalization Constant Parameter Replacement Graph Duplication Graph Inlining in Targe Constant Folding, Cano Steps: Targ with ...
  • Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13 Snippet Example: Convert @Snippet static 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 Interpreter Rewritten Nodes AST Interpreter Uninitialized Nodes Compilation using Partial Evaluation Compiled Code Node Transitions S U I 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 Deoptimization to AST Interpreter D I D G G D I D G G Node Rewriting to Update Profiling Feedback Recompilation using Partial 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 richards deltablue crypto raytrace navier-stokes splay earley-boyer box2d gbem u C om posite 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 O0 GCC Best Clang Best TruffleC 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 RRuby 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/ graal-dev@openjdk.java.net $ 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/ graal-dev@openjdk.java.net @thomaswue
  • Copyright © 2014, Oracle and/or its affiliates. All rights reserved.28
  • Copyright © 2014, Oracle and/or its affiliates. All rights reserved.29