Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Turning the JVM into a Polyglot VM with Graal

Turning the JVM into a Polyglot VM with Graal

Oracle Code, London, 2017

Chris Seaton

April 20, 2017
Tweet

More Decks by Chris Seaton

Other Decks in Programming

Transcript

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

    | Turning the JVM into a Polyglot VM with Graal Chris Seaton Research Manager Oracle Labs April 2017
  2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | Safe Harbor Statement 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. Oracle reserves the right to alter its development plans and practices at any time, and 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.
  3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 9 Goal: Computer Language Benchmarks Game
  4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 10 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 Define a bytecode format and write bytecode interpreter People complain about performance Write a JIT compiler Improve the garbage collector Performance is still bad Current situation How it should be
  5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 11 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 Define a bytecode format and write bytecode interpreter People complain about performance Write a JIT compiler Improve the garbage collector Performance is still bad 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 Current situation How it should be
  6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 13 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 <[email protected]>, 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).
  7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

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

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

    | clamp in Pure Ruby 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM JRuby+invokedynamic Ruby Operations Per Second This is what GraalVM is giving you for Ruby before we even start talking about JavaScript
  10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | Not only have we rewritten in JavaScript, but the JavaScript code is simpler than the Ruby
  11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

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

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

    | clamp in Ruby and JavaScript with JRuby and 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
  14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

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

    | clamp in all configurations 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
  16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | clamp in all configurations 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
  17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | Conventional JVM implementations of languages work by emitting JVM bytecode – the same thing that the Java compiler does
  18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | Slightly confusing terminology… • Graal is a new JIT compiler for the JVM • Graal VM is the JVM, with Graal, Truffle, and our languages bundled in it • Truffle uses Graal on your behalf
  19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 57 Guest Language Compiler internal data structures, optimisation passes, machine code, … Graal
  20. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 58 Guest Language Graal Truffle language interpreter
  21. 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
  22. 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
  23. 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
  24. 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.
  25. 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.
  26. 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.
  27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 66 codon.com/compilers-for-free Presentation, by Tom Stuart, licensed under a Creative Commons Attribution ShareAlike 3.0
  28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 20/04/2017 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
  29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | 20/04/2017 Oracle Confidential – Internal/Restricted/Highly Restricted 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
  30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | • We’re not really suggesting that people routinely write alternate methods in different languages
  31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | • We’re not really suggesting that people routinely write alternate methods in different languages • More about removing the consideration of performance from the decision if you do want to combine languages
  32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | • Could make all library ecosystems available to all applications • May be useful for unifying a front-end and back-end • May be useful in handling legacy applications and incremental changes in implementation language
  33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

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

    | Java 9 – runs on an unmodified JVM Hotspot Graal Truffle JS others… R Java C++
  35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

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

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

    | • Oracle Labs is building Graal VM to support polyglot programs and programmers • Extremely high performance for the languages on their own • Completely unprecedented high performance for language interoperability • Will work on an unmodified Java 9 JVM, or available as a bundle today • Still at the research stage, but moving towards being something more than that
  38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | Search for ‘graal otn’ www.oracle.com/technetwork/oracle-labs/program-languages
  39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | Search for ‘github graalvm’ github.com/graalvm
  40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | @chrisgseaton github.com/graalvm gitter.im/graalvm/graal-core Search ‘otn graalvm’
  41. 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
  42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

    | Safe Harbor Statement The preceding 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. Oracle reserves the right to alter its development plans and practices at any time, and 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.