graal truffle
play

Graal & Truffle How to write fast interpreters on the JVM - PowerPoint PPT Presentation

Graal & Truffle How to write fast interpreters on the JVM download: html / pdf Manuel Leduc (https://mleduc.xyz/) 1 / 17 Domain Specific Language A domain-specific language (DSL) is a computer language specialized to a particular


  1. Graal & Truffle How to write fast interpreters on the JVM download: html / pdf Manuel Leduc (https://mleduc.xyz/) 1 / 17

  2. Domain Specific Language A domain-specific language (DSL) is a computer language specialized to a particular application domain Examples awk pom CSS ... To Read Martin fowler https://martinfowler.com/dsl.html How to write fast interpreters on the JVM - download: html / pdf 2 / 17

  3. Domain Specific Language Program Abstract Syntax tree Semantics (1x2)+3 [Mult] = [l] * [r] Add l r [Add] = [l] + [r] Lit Mult [Lit] = value value = 3 r Result = 6 l Lit Lit value = 1 value = 2 How to write fast interpreters on the JVM - download: html / pdf 3 / 17

  4. Interpreter or Compiler? Compiler Interpreter + Fast - Slow(er) - Hard to implement + Easier to implement - Hard to reuse (compose, extends...) + Easier to reuse (compose, extends...) Objective Obtaining interpreters with acceptable performances on the first try. How to write fast interpreters on the JVM - download: html / pdf 4 / 17

  5. Graal 5 / 17

  6. Performance How to write fast interpreters on the JVM - download: html / pdf 6 / 17

  7. Just-In-Time Compiler and the JVM Just-In-Time (JIT) Compiler Instead of interpreting bytecode instruction one by one, parts of the bycecode are compiled at runtime before being executed JDK9 and JVMCI JVMCI = Java-Level JVM Compiler Interface C++ is replaced by Java Better Modularity Avoid JVM (Re)-Compilation How to write fast interpreters on the JVM - download: html / pdf 7 / 17

  8. JVMCI internals It simply takes a bunch of bytecode operations and yield equivalent machine level code. interface JVMCICompiler { byte [] compileMethod( byte [] bytecode); } How to write fast interpreters on the JVM - download: html / pdf 8 / 17

  9. Graal Graal is a JIT implementation build on top of the JVMCICompiler interface. Sea of Node graph Graal is based on a "sea of nodes" connected by Data Flow (blue) and Control Flow (red) annotations. Partial interpretation This graph is build by partially interpreting the bytecode. How to write fast interpreters on the JVM - download: html / pdf 9 / 17

  10. Graph Properties Annotated with runtime information Garbage collection analysis High-Level static optimizations Method inlining Constant folding Arithmetic optimizations Speculative optimizations Can be visualy inspected How to write fast interpreters on the JVM - download: html / pdf 10 / 17

  11. Truffle 11 / 17

  12. Truffle in a picture How to write fast interpreters on the JVM - download: html / pdf 12 / 17

  13. Truffle ideas High level representation of the language AST Annotated AST to assist Graal speculative optimizations. How to write fast interpreters on the JVM - download: html / pdf 13 / 17

  14. Language implementation with Truffle Simple @NodeInfo (shortName = "+") concepts public abstract class ELTAddNode extends ELTBinaryNode { @Specialization protected int add ( int left, int right) { return left + right; nodes } methods @Specialization specialization protected float add ( float left, float right) { return left + right; } "classical" interpreters @Specialization protected String add (String left, String right) { language return left + right; } metadata @Specialization stack frames protected int add (Object left, int right) { return ((Integer) left) + right; } } How to write fast interpreters on the JVM - download: html / pdf 14 / 17

  15. Polyglot Example #include <polyglot.h> int main () { void *array = polyglot_eval("js", "[1,2,42,4]"); int element = polyglot_as_i32(polyglot_get_array_element(array, 2)); printf("%d\n", element); return element; } To Read http://www.graalvm.org/docs/reference-manual/polyglot/ How to write fast interpreters on the JVM - download: html / pdf 15 / 17

  16. Scientific questions Can we reuse Truffle to define interpreters using ALE/K3/Gemoc... solutions? What new can we do if everything run fast on the JVM? What is the consequence of Polyglot for the DSL intercompatibility? How to write fast interpreters on the JVM - download: html / pdf 16 / 17

  17. Resources Really good blog post: http://chrisseaton.com/truffleruby/jokerconf17/ Another blog post: https://zeroturnaround.com/rebellabs/graal-and-truffle-for- polyglot-languages-on-jvm/ Comprehensive slides: http://lafo.ssw.uni- linz.ac.at/papers/2017_PLDI_GraalTutorial.pdf Publications: https://github.com/oracle/graal/blob/master/docs/Publications.md How to write fast interpreters on the JVM - download: html / pdf 17 / 17

Recommend


More recommend