Slide 1

Slide 1 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Polyglot on the JVM with Graal Akihiro Nishikawa May 20, 2017 JJUG CCC 2017 Spring

Slide 2

Slide 2 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 2

Slide 3

Slide 3 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Program Agenda 3 What’s Graal? What’s Graal VM? Polyglot in Graal VM How to use Appendix 1 2 3 4

Slide 4

Slide 4 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | What’s Graal? What’s Graal VM? 4

Slide 5

Slide 5 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Graal and Graal VM • A new compiler for HotSpot written in Java and with a focus on speculative optimizations. – Based HotSpot – Aggressive high-level optimizations – JVMCI and Graal included in JDK9 (modified version of JDK8 available via OTN) 5 Graal

Slide 6

Slide 6 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Graal and Graal VM • JVM packaged with Graal, Truffle, and other languages such as JavaScript, R, Ruby, and so on. 6 Graal VM

Slide 7

Slide 7 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 7 Graal and Graal VM C++ Java HotSpot Compiler Interface Client Server HotSpot JVMCI Graal HotSpot VM Graal VM Compiler Interface Client

Slide 8

Slide 8 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Polyglot in Graal VM 8

Slide 9

Slide 9 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The One VM Concept High performance polyglot virtual machine 9

Slide 10

Slide 10 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 10 The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. It is licensed under the terms of the Creative Commons Attribution-ShareAlike 2.5 agreement JS Logo Copyright (c) 2011 Christopher Williams , MIT licence You can distribute the R logo under the terms of the Creative Commons Attribution-ShareAlike 4.0 International license (CC-BY-SA 4.0) or (at your option) the GNU General Public License version 2 (GPL-2).

Slide 11

Slide 11 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Impl Impl Impl Impl 11 VM VM VM VM

Slide 12

Slide 12 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | VM Impl Impl Impl Impl 12

Slide 13

Slide 13 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | • JavaScript – Better ECMAScript2016 score than V8 – Almost same performance as V8 – Fully support for node.js • R – Statistical language 13 • Ruby – Fork of JRuby – 5〜10x better performance • C、C++、Fortran – Native language support via LLVM Graal VM Polyglot

Slide 14

Slide 14 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 14 Graal VM Polyglot C HotSpot JVMCI Graal Truffle LLVM (Sulong) R Ruby JavaScript Java

Slide 15

Slide 15 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Truffle • Together with the Graal compiler, Truffle interpreters are automatically just-in-time compiled and programs running on top of them can reach performance of normal Java. • Provides the basic foundation for building abstract-syntax-tree (AST) interpreters that perform self-optimizations at runtime – The included TruffleDSL provides a convenient way to express such optimizations. 15 Framework for implementing languages as simple interpreters

Slide 16

Slide 16 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 16 Fully compatible including native module support! Graal.js Architecture C++ JavaScript Java node modules with only JavaScript node standard library V8 API Thread pool (libeio) Event loop (libev) DNS (c-ares) crypto (OpenSSL) Graal.js JavaScript Engine Adapter V8 API to Graal.js (via JNI) Native extensions node bindings (socket, http, …) node modules with native extensions

Slide 17

Slide 17 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | FastR • Goal: realize the advantages of the Truffle stack for R – Superior performance without resorting to C/C++/Fortran/… – Designed for data-heavy and parallel applications – CRAN / Bioconductor repository support • Not an ”incremental improvement” on GNU R – New execution engine written from scratch, based on Truffle – Designed as a drop-in replacement for GNU R • Speedup over latest GNU R interpreter – Somewhere between 2 and 10x 17 https://github.com/graalvm/fastr

Slide 18

Slide 18 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JavaScript in Graal VM 18

Slide 19

Slide 19 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Completeness 19 ECMAScript 2015 (ES6) (16298 tests/16417 tests) Failing tests are to a large part Unicode Regular Expressions 93.4% ECMAScript 2016 (ES7) Supports exponentiation operator, Array.prototype.includes Fails due to new block-level function declaration and corner- case tests of the spread operator 99.3%

Slide 20

Slide 20 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal Classic research benchmarks (Octane) 0 0.2 0.4 0.6 0.8 1 1.2 1.4 V8 (5.4.500.6) Graal.js 20 roughly level with V8

Slide 21

Slide 21 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby in Graal VM 21

Slide 22

Slide 22 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Completeness – language and core library 22 Ruby Language JRuby: 94% 96% Ruby core libraries JRuby: 95% 99%

Slide 23

Slide 23 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Classic research benchmarks – 10-20x faster 0 5 10 15 20 25 30 35 40 45 GraalVM JRuby+invokedynamic Ruby 23 Bigger score is better (based on Ruby score) Benchmarks bound by allocation or BigInteger performance

Slide 24

Slide 24 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | “But, it’s easy to optimize that kind of code!” 24

Slide 25

Slide 25 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 25 Simple local variables Vectorisation opportunities Simple floating point arithmetic Basic loops No method calls (except operators) Only types are numerical or boolean

Slide 26

Slide 26 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | “Real Ruby is much more complex!” 26

Slide 27

Slide 27 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 27 Smalltalk-style blocks instead of loops Loop bounds are objects instead of simple values Instance variables Logic hidden in methods Arrays

Slide 28

Slide 28 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 28 Arithmetic hidden in core library methods Intermediate objects Hash mapped to an array of arrays, via another array, converted back to a hash Inner loop pixels represented as a hash of r, g, b No local variables, only method calls

Slide 29

Slide 29 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 29 Metaprogramming send Dynamically created symbol Actual logic method dynamic method calls

Slide 30

Slide 30 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Chunky PNG kernels 0.01 0.1 1 10 100 1000 GraalVM JRuby+invokedynamic Ruby 30 Many of these benchmarks are optimised away entirely by GraalVM

Slide 31

Slide 31 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | PSD.rb kernels 0.1 1 10 100 1000 GraalVM JRuby+invokedynamic Ruby 31

Slide 32

Slide 32 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Polyglot 32

Slide 33

Slide 33 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | REST public internet REST private intranet 33

Slide 34

Slide 34 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | REST public internet 34

Slide 35

Slide 35 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | REST public internet 35

Slide 36

Slide 36 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How we do polyglot in Graal VM 36

Slide 37

Slide 37 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby Truffle::Interop.eval('application/language', source) value = Truffle::Interop.import(name) Truffle::Interop.export(name) 37

Slide 38

Slide 38 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JavaScript Interop.eval('application/language', source) value = Interop.import(name) Interop.export(name) // Returns 20 Interop.eval('application/javascript', '14 + 6') 38

Slide 39

Slide 39 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JavaScript in Ruby puts Truffle::Interop.eval('application/javascript', '14 + 6') 39 This returns 20 JavaScript Ruby

Slide 40

Slide 40 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JavaScript in Ruby Truffle::Interop.eval('application/javascript', "function add(a,b) { return a + b; } Interop.export('add', add.bind(this));") add = Truffle::Interop.import('add') puts add.call(14,2) 40 Uses function defined in JavaScript from Ruby JavaScript Ruby

Slide 41

Slide 41 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby JavaScript 41

Slide 42

Slide 42 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby JS 42

Slide 43

Slide 43 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Performance 43

Slide 44

Slide 44 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 44 Clamp Warms up and then reports iterations per second Random inputs stop the whole thing being totally optimized away

Slide 45

Slide 45 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM JRuby+invokedynamic Ruby Operations Per Second 45

Slide 46

Slide 46 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 46 JavaScript (V8) Rewritten in JavaScript and call it on V8

Slide 47

Slide 47 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby + JavaScript (V8) 0 50000 100000 150000 200000 250000 300000 350000 Ruby (just Ruby) Ruby (Ruby + JS with V8) Operations Per Second 47

Slide 48

Slide 48 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 48 In case of Rhino

Slide 49

Slide 49 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JRuby + JavaScript (Rhino) 0 100000 200000 300000 400000 500000 600000 JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) Operations Per Second 49

Slide 50

Slide 50 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 50 In case of Nashorn

Slide 51

Slide 51 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JRuby + JavaScript (Nashorn) 0 100000 200000 300000 400000 500000 600000 JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) JRuby+indy (Ruby + JS with Nashorn) Operations Per Second 51

Slide 52

Slide 52 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 52 In case of Graal VM

Slide 53

Slide 53 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby + JavaScript (Graal VM) 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM (just Ruby) GraalVM (Ruby + JS) JRuby+invokedynamic Ruby Operations Per Second 53

Slide 54

Slide 54 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM (just Ruby) GraalVM (Ruby + JS) JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) JRuby+indy (Ruby + JS with Nashorn) Ruby (just Ruby) Ruby (Ruby + JS with V8) Operations Per Second 54

Slide 55

Slide 55 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 1 10 100 1000 10000 100000 1000000 10000000 GraalVM (just Ruby) GraalVM (Ruby + JS) JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) JRuby+indy (Ruby + JS with Nashorn) Ruby (just Ruby) Ruby (Ruby + JS with V8) Operations Per Second 55

Slide 56

Slide 56 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How Graal achieves this 56

Slide 57

Slide 57 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Hotspot JIT 57

Slide 58

Slide 58 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Hotspot JIT Graal Truffle 58

Slide 59

Slide 59 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Basics of Truffle and Graal 59

Slide 60

Slide 60 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Basic Concepts • Common representation of programs • Keep it rich enough to not have to throw away meaning • Common optimization of the representation 60

Slide 61

Slide 61 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | x + y * z + x * y z load_local x load_local y load_local z call * call + pushq %rbp movq %rsp, %rbp movq %rdi, -8(%rbp) movq %rsi, -16(%rbp) movq %rdx, -24(%rbp) movq -16(%rbp), %rax movl %eax, %edx movq -24(%rbp), %rax imull %edx, %eax movq -8(%rbp), %rdx addl %edx, %eax popq %rbp ret 61

Slide 62

Slide 62 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | U U U U U Node Rewriting for Profiling Feedback AST Interpreter Uninitialized Nodes Node Transitions S U I D G Uninitialized Integer Generic Double String T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of Onward!, 2013. 62

Slide 63

Slide 63 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | U U U U U I I I G G Node Rewriting for Profiling Feedback AST Interpreter Rewritten Nodes AST Interpreter Uninitialized Nodes Node Transitions S U I D G Uninitialized Integer Generic Double String T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of Onward!, 2013. 63

Slide 64

Slide 64 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | I I I G G I I I G G Rewriting ng Feedback AST Interpreter Rewritten Nodes Compilation using Partial Evaluation Compiled Code I D Uninitialized Integer Generic Double T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of Onward!, 2013. 64

Slide 65

Slide 65 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of Onward!, 2013. I I I G G I I I G G Deoptimization to AST Interpreter D I Node Rewriting to Update Profiling Feedback 65

Slide 66

Slide 66 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of Onward!, 2013. I I G G D I D G G D I D G G Node Rewriting to Update Profiling Feedback Recompilation using Partial Evaluation 66

Slide 67

Slide 67 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 67

Slide 68

Slide 68 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 68 Frequently executed call

Slide 69

Slide 69 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 69

Slide 70

Slide 70 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 70 Even if another language… Frequently executed call

Slide 71

Slide 71 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 71

Slide 72

Slide 72 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 72

Slide 73

Slide 73 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Looking at how effective this is 73

Slide 74

Slide 74 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 74

Slide 75

Slide 75 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 75

Slide 76

Slide 76 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 76

Slide 77

Slide 77 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 77

Slide 78

Slide 78 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 78

Slide 79

Slide 79 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 79

Slide 80

Slide 80 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 80

Slide 81

Slide 81 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How to use Graal VM 81

Slide 82

Slide 82 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | • Includes: – JVM (RE or DK) – Java – JavaScript – Ruby – R – More in the future • Binary tarball release • Mac or Linux 82 Graal VM – everything in one package today

Slide 83

Slide 83 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 83 Java 9 – runs on an unmodified JVM Hotspot Graal Truffle JS others… Ruby Java C++ JVMCI (JVM Compiler Interface)

Slide 84

Slide 84 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 84 Java 9 – runs on an unmodified JVM Hotspot Graal Truffle JS others… Ruby via Maven etc Java 9

Slide 85

Slide 85 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Appendix 85

Slide 86

Slide 86 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 86 http://www.oracle.com/technetwork/oracle-labs/program-languages Search for “Graal OTN”

Slide 87

Slide 87 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 87 https://github.com/graalvm Search for “GitHub GraalVM”

Slide 88

Slide 88 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Acknowledgements Oracle Danilo Ansaloni Stefan Anzinger Cosmin Basca Daniele Bonetta Matthias Brantner Petr Chalupa Jürgen Christ Laurent Daynès Gilles Duboscq Martin Entlicher Brandon Fish Bastian Hossbach Christian Humer Mick Jordan Vojin Jovanovic Peter Kessler David Leopoldseder Kevin Menard Jakub Podlešák Aleksandar Prokopec Tom Rodriguez Oracle (continued) Roland Schatz Chris Seaton Doug Simon Štěpán Šindelář Zbyněk Šlajchrt Lukas Stadler Codrut Stancu Jan Štola Jaroslav Tulach Michael Van De Vanter Adam Welc Christian Wimmer Christian Wirth Paul Wögerer Mario Wolczko Andreas Wöß Thomas Würthinger JKU Linz Prof. Hanspeter Mössenböck Benoit Daloze Josef Eisl Thomas Feichtinger Matthias Grimmer Christian Häubl Josef Haider Christian Huber Stefan Marr Manuel Rigger Stefan Rumzucker Bernhard Urban University of Edinburgh Christophe Dubach Juan José Fumero Alfonso Ranjeet Singh Toomas Remmelg LaBRI Floréal Morandat University of California, Irvine Prof. Michael Franz 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 University of Lugano, Switzerland Prof. Walter Binder Sun Haiyang Yudi Zheng Oracle Interns Brian Belleville Miguel Garcia Shams Imam Alexey Karyakin Stephen Kell Andreas Kunft Volker Lanting Gero Leinemann Julian Lettner Joe Nash David Piorkowski Gregor Richards Robert Seilbeck Rifat Shariyar Alumni Erik Eckstein Michael Haupt Christos Kotselidis Hyunjin Lee David Leibs Chris Thalinger Till Westmann

Slide 89

Slide 89 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 89

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content