Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Polyglot on the JVM with Graal (English)

4.519 visualizaciones

Publicado el

Presentation slides delivered at JJUG CCC 2017 Spring (English)

Publicado en: Tecnología
  • Sé el primero en comentar

Polyglot on the JVM with Graal (English)

  1. 1. 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
  2. 2. 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
  3. 3. 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
  4. 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | What’s Graal? What’s Graal VM? 4
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Polyglot in Graal VM 8
  9. 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The One VM Concept High performance polyglot virtual machine 9
  10. 10. 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 <chris@iterativedesigns.com>, 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).
  11. 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Impl Impl Impl Impl 11 VM VM VM VM
  12. 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | VM Impl Impl Impl Impl 12
  13. 13. 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
  14. 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 14 Graal VM Polyglot C HotSpot JVMCI Graal Truffle LLVM (Sulong) RRubyJavaScript Java
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JavaScript in Graal VM 18
  19. 19. 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%
  20. 20. 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
  21. 21. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby in Graal VM 21
  22. 22. 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%
  23. 23. 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
  24. 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | “But, it’s easy to optimize that kind of code!” 24
  25. 25. 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
  26. 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | “Real Ruby is much more complex!” 26
  27. 27. 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
  28. 28. 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
  29. 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 29 Metaprogramming send Dynamically created symbol Actual logic method dynamic method calls
  30. 30. 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
  31. 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | PSD.rb kernels 0.1 1 10 100 1000 GraalVM JRuby+invokedynamic Ruby 31
  32. 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Polyglot 32
  33. 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | REST public internet REST private intranet 33
  34. 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | REST public internet 34
  35. 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | REST public internet 35
  36. 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How we do polyglot in Graal VM 36
  37. 37. 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
  38. 38. 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
  39. 39. 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
  40. 40. 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
  41. 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby JavaScript 41
  42. 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ruby JS 42
  43. 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Performance 43
  44. 44. 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
  45. 45. 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
  46. 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 46 JavaScript (V8) Rewritten in JavaScript and call it on V8
  47. 47. 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
  48. 48. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 48 In case of Rhino
  49. 49. 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
  50. 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 50 In case of Nashorn
  51. 51. 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
  52. 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 52 In case of Graal VM
  53. 53. 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
  54. 54. 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
  55. 55. 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
  56. 56. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How Graal achieves this 56
  57. 57. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Hotspot JIT 57
  58. 58. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Hotspot JIT Graal Truffle 58
  59. 59. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Basics of Truffle and Graal 59
  60. 60. 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
  61. 61. 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
  62. 62. 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 DoubleString 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
  63. 63. 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 DoubleString 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
  64. 64. 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
  65. 65. 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
  66. 66. 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
  67. 67. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 67
  68. 68. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 68 Frequently executed call
  69. 69. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 69
  70. 70. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 70 Even if another language… Frequently executed call
  71. 71. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 71
  72. 72. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 72
  73. 73. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Looking at how effective this is 73
  74. 74. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 74
  75. 75. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 75
  76. 76. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 76
  77. 77. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 77
  78. 78. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 78
  79. 79. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 79
  80. 80. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 80
  81. 81. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How to use Graal VM 81
  82. 82. 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
  83. 83. 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)
  84. 84. 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
  85. 85. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Appendix 85
  86. 86. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 86 http://www.oracle.com/technetwork/oracle-labs/program-languages Search for “Graal OTN”
  87. 87. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 87 https://github.com/graalvm Search for “GitHub GraalVM”
  88. 88. 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
  89. 89. 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

×