Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

JVM++: The Graal VM

5 405 vues

Publié le

Presentation on the Graal VM at BG OUG (http://www.bgoug.org/) summer conference, 3-5June, 2016, Borovetz, Bulgaria

Publié dans : Logiciels

JVM++: The Graal VM

  1. 1. JVM++: The Graal VM Martin Toshev, BGOUG, 04.06.2016
  2. 2. Special thanks to Thomas Wuerthinger and Oracle Labs for inspiring this presentation …
  3. 3. Who am I Software consultant (CoffeeCupConsulting) BG JUG board member (http://jug.bg) OpenJDK and Oracle RDBMS enthusiast
  4. 4. Who am I Author of Learning RabbitMQ
  5. 5. Agenda • Overview of the Graal VM • Building and managing Graal • Performance benchmarks • Future directions
  6. 6. Overview of the Graal VM
  7. 7. Overview of the Graal VM Some background … static compilation vs dynamic compilation static compiler source code (e.g. JVM bytecode) dynamic compiler runtime machine code runtime source code (e.g. JVM bytecode) machine code
  8. 8. Overview of the Graal VM • The javac tool performs static compilation of Java sources to bytecode • The JVM may perform dynamic compilation of bytecode to machine code for optimization using a JIT (Just-in-Time) compiler
  9. 9. Overview of the Graal VM • Graal is a new JIT (Just-in-Time) compiler for the JVM • Brings the performance of Java to scripting languages (via the Truffle API) • written in Java
  10. 10. Overview of the Graal VM • In essence the Graal JIT compiler generates machine code from an optimized AST rather than bytecode • However the Graal VM has both AST and bytecode interpreters
  11. 11. Overview of the Graal VM • The Graal VM supports the following types of compilers (apart from the Graal JIT compiler): --vm server-nograal // server compiler --vm server // server compiler using Graal --vm graal // Graal compiler using Graal --vm client-nograal // client compiler --vm client // client compiler running Graal
  12. 12. Overview of the Graal VM • The Truffle API: – is a Java API – provides AST (Abstract Syntax Tree) representation of source code – provides a mechanism to convert the generated AST into a Graal IR (intermediate representation)
  13. 13. Overview of the Graal VM • The Truffle API is declarative (uses Java annotations) • The AST graph generated by Truffle is a mixture of control flow and data flow graph • Essential feature of the Truffle API is the ability to specify node specializations used in node rewriting
  14. 14. Overview of the Graal VM • The Truffle API is used in conjunction with custom annotation processor that generates code based on the Truffle annotations used in the interpreter classes Truffle Interpreter javac Annotation processor Compiled Interpreter Generated Interpreter source code
  15. 15. Overview of the Graal VM • General architecture: HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) Maxine VM (Java) Graal <–> Maxine adapter (Java)
  16. 16. Overview of the Graal VM • Let’s see, for example, how a JavaScript interpreter works in Graal …
  17. 17. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) Run JavaScript file: app.js
  18. 18. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) JavaScript Interpreter parses app.js and converts it to Truffle AST
  19. 19. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) The app.js Truffle AST is converted to Graal IR (AST)
  20. 20. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) The Graal VM has bytecode and AST interpreters along with a JIT compiler (optimizations and AST lowering is performed to generate machine code and perform partial evaluation)
  21. 21. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) When parts of app.js are compiled to machine code by the Graal compiler the compiled code is transferred to Hotspot for execution by means of Hotspot APIs and with the help of a Graal – Hotspot adapter interface
  22. 22. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) Compiled code can also be deoptimized and control is transferred back to the interpreter (e.g. when an exception occurs, an assumption fails or a guard is reached)
  23. 23. Overview of the Graal VM • Optimizations done on the Graal IR include: – method inlining – partial escape analysis – inline caching – constant folding – arithmetic optimizations and others …
  24. 24. Overview of the Graal VM • Currently supported languages include: – JavaScript (Graal.JS) – R (FastR) – Ruby (RubyTruffle) – Experimental interpreters for C, Python, Smalltalk, LLVM IR and others … (some are not open-sourced as of the time of this presentation)
  25. 25. Overview of the Graal VM • The SimpleLanguage project provides a showcase on how to use the Truffle APIs Source file Parser Truffle AST Graal VM
  26. 26. Building the Graal VM
  27. 27. Building the Graal VM • The Graal VM interoperates with JEP 243: Java- Level JVM Compiler Interface • In that regard two modes of operation are supported – via the Graal VM or via the JVMCI (JVM Compiler Interface)
  28. 28. Building the Graal VM • Early access builds of Graal available for download • You can build Graal on any supported platform (Windows, Linux, MacOS, Solaris) from source code
  29. 29. Building the Graal VM git clone https://github.com/graalvm/mx.git export PATH=$PWD/mx:$PATH git clone https://github.com/graalvm/graal-core.git cd graal-core mx --vm graal build mx vm
  30. 30. Building the Graal VM • The MX tool is a Python (2.7) tool that manages the Graal projects and allows to: - update sources and run JUnit tests and benchmarks; - builds (sub)projects (Java and C++ sources can be built separately); - runs VM tools (such as IGV or c1visualizer) that can aid development of Graal or language interpreters; - can be used to generate IDE project files for Graal development (support for Eclipse and NetBeans)
  31. 31. The Graal VM demo
  32. 32. Performance benchmarks
  33. 33. Performance benchmarks • According to various JVM benchmarks such as SPECjvm2008 and Scala Dacapo the Graal compiler positions between the client and server JVM compilers (source: One VM to Rule Them All, Thomas Wuertinger) • In general Truffle interpreters provide much better performance for some dynamic languages
  34. 34. Performance benchmarks • Graal.JS – shows improvement of 1.5x in some cases with a peak of 2.6x compared to V8 (running Google Octane’s benchmark) • RubyTruffle – shows improvements between 1.5x and 4.5x in some cases with a peak of 14x compared to JRuby • FastR - shows improvements between 2x and 39x in some cases with a peak of 94x compared to GnuR (source: One VM to Rule Them All, Thomas Wuertinger)
  35. 35. Future directions
  36. 36. Future directions • Graal provides an extensible framework for researching and experimenting with other compiler optimizations • In that regard new types of compiler optimization may be introduced in the VM that address runtime behavior in certain scenarios
  37. 37. Future directions • Graal provides an extensible framework for creating language interpreters further simplified by the Truffle API • In that regard more languages can be introduced that run in the Graal VM • Currently existing languages that compile to bytecode may support Truffle in the future
  38. 38. Future directions • Graal provides an extensible framework for different types of operating systems and CPU architectures • In that regard CPU architectures and operating systems might be supported by Graal
  39. 39. Thank you ! Q&A
  40. 40. References Graal Project http://openjdk.java.net/projects/graal/ Graal - A New Just In Time Compiler for the JVM http://www.oracle.com/technetwork/oracle-labs/program- languages/overview/index.html Graal VM: GitHub repositories https://github.com/graalvm
  41. 41. References Graal - A Bytecode Agnostic Compiler for the JVM, Thomas Wuerthinger, JVM Language Summit http://medianetwork.oracle.com/video/player/1113230360001 Graal and Truffle: One VM to Rule Them All http://www.slideshare.net/ThomasWuerthinger/graal-truffle- ethdec2013?qid=848a4965-9768-40d5-b167- ccd8eb7d1659&v=&b=&from_search=2
  42. 42. References Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime http://www.slideshare.net/ThomasWuerthinger/2014-0424-graal- modularity?qid=0e86ed21-0b8f-4087-9212- 68f76546d674&v=&b=&from_search=4 Dynamic Compilation - Thomas Wuerthinger https://www.youtube.com/watch?v=RLsG2kE1EMI https://www.youtube.com/watch?v=U_QpToYLsO0 JVMLS 2012: Graal http://medianetwork.oracle.com/video/player/1785432492001
  43. 43. References Graal Tutorial at CGO 2015 by Christian Wimmer http://lafo.ssw.uni-linz.ac.at/papers/2015_CGO_Graal.pdf Writing a language in Truffle: Part 1 - Using Truffle and Graal https://cesquivias.github.io/blog/2014/10/13/writing-a-language-in-truffle- part-1-a-simple-slow-interpreter/ Writing a language in Truffle: Part 2 - Using Truffle and Graal http://cesquivias.github.io/blog/2014/12/02/writing-a-language-in-truffle- part-2-using-truffle-and-graal/
  44. 44. References Graal publications, JKU, Linz http://ssw.jku.at/Research/Projects/JVM/Graal.html Truffle publications, JKU, Linz http://ssw.jku.at/Research/Projects/JVM/Truffle.html
  45. 45. References R as a citizen in a Polyglot world: The promise of the Truffle framework http://user2015.math.aau.dk/presentations/112.pdf Truffle/C Interpreter http://www.manuelrigger.at/downloads/trufflec_thesis.pdf Graal.JS - high-performance JavaScript on the JVM talk by Christian Wirth https://www.youtube.com/watch?v=OUo3BFMwQFo

×