16
Run * on the JVM Interpreters on the JVM with Graal and Truffle Balazs Varga / @vbalazs

Run * on the JVM - Simonyi Conference Budapest April 15

Embed Size (px)

Citation preview

Page 1: Run * on the JVM - Simonyi Conference Budapest April 15

Run * on the JVMInterpreters on the JVM with

Graal and Truffle

Balazs Varga / @vbalazs

Page 2: Run * on the JVM - Simonyi Conference Budapest April 15

Agenda

● Compiled, interpreted applications and VMs● Interpreters under the hood● Interpreter on the JVM

○ Existing solutions○ Future

● Summary

Page 3: Run * on the JVM - Simonyi Conference Budapest April 15

Compiled, interpreted applications

Operating system

Libraries

Compiler

Operating system

Libraries

ExecutableMachine CodeC source code

Operating system

Libraries

InterpreterRuby source code(1.8) GC Libraries

compiled C source code (executable machine code)

Libraries

GC: Garbage Collector

Page 4: Run * on the JVM - Simonyi Conference Budapest April 15

Virtual Machines (runtimes)

Operating system

Libraries

Java compiler

Operating system

Libraries

ExecutableJVM bytecodeJava source code

Libraries

JVMbytecode

Java Runtime Env.

GC Libraries

Page 5: Run * on the JVM - Simonyi Conference Budapest April 15

Interpreters under the hood

1. Tokenize2. Parse3. AST

Ruby Tokens Abstract Syntax Treenodes C Machine

Languageinterpret

Page 6: Run * on the JVM - Simonyi Conference Budapest April 15

Abstract Syntax Treefunction sum(n) { var sum = 0; for (var i = 1; i < n; i++) { sum += i; } return sum; }

source: T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, M. Wolczko: One VM to Rule Them All. In Proceedings of Onward!, ACM Press, 2013.

Page 7: Run * on the JVM - Simonyi Conference Budapest April 15

Interpreter on the JVM

Ruby source code compiled to Java bytecode

Operating system

Libraries

JRuby interpreter

Java Runtime Env.

GC Libraries

Why?Existing solutions

Page 8: Run * on the JVM - Simonyi Conference Budapest April 15

The future is here: Truffle and Graal

Goal: Native support for interpreters

Requirements:● simplicity● generality● performance

Page 9: Run * on the JVM - Simonyi Conference Budapest April 15

System structure

source: Christian Wimmer and Chris Seaton speak at the JVM Language Summit, July 31, 2013.

Ruby

Javascript Python

R ...

Your language here

TruffleGraal

Language agnosticdynamic compiler Common API between

language implementation and optimization system

Substrate VM

Graal VM

Page 10: Run * on the JVM - Simonyi Conference Budapest April 15

Truffle

● Java framework for writing AST interpreters● node specialization with tree rewriting● define compiler optimizations, directives

○ assumptions

Page 11: Run * on the JVM - Simonyi Conference Budapest April 15

Graal

● 100% Java-based JIT framework○ JIT: Just In Time (compiler)

● dynamic compiler● directly control code generation● graph intermediate representation

Page 12: Run * on the JVM - Simonyi Conference Budapest April 15

Node rewrite - optimization

source: T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, M. Wolczko: One VM to Rule Them All. In Proceedings of Onward!, ACM Press, 2013.

Page 13: Run * on the JVM - Simonyi Conference Budapest April 15

Node rewrite - de- and reoptimization

source: T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, M. Wolczko: One VM to Rule Them All. In Proceedings of Onward!, ACM Press, 2013.

Page 14: Run * on the JVM - Simonyi Conference Budapest April 15

Bonus

“Write your own language!”

Before Truffle:● write a parser and an AST interpreter● create a runtime system (C/C++), GC● performance problems: bytecode, JIT, improve GC● ...???

Easy?

Page 15: Run * on the JVM - Simonyi Conference Budapest April 15

Summary

● Truffle, Graal (~ Java 9)○ “easy” to use AST interpreter framework○ high performance (compiled to machine code!)

● Bonus: “Write your own language!”● Contribute!

○ meetup.com: budapest.rb, budapest.js, …○ https://github.com/jruby/jruby○ http://openjdk.java.net/

Page 16: Run * on the JVM - Simonyi Conference Budapest April 15

Questions?