Run * on the JVM interpreters on the JVM with Graal and Truffle. Truffle is a Java framework for writing AST interpreters that allows for node specialization and tree rewriting to define compiler optimizations and directives. Graal is a 100% Java-based JIT framework that acts as a dynamic compiler, allowing direct control over code generation using a graph intermediate representation. Together Truffle and Graal allow for easy implementation of interpreters on the JVM with high performance compilation to machine code.
1 of 16
Downloaded 10 times
More Related Content
Run * on the JVM - Simonyi Conference Budapest April 15
1. Run * on the JVM
Interpreters on the JVM with
Graal and Truffle
Balazs Varga / @vbalazs
2. Agenda
¡ñ Compiled, interpreted applications and VMs
¡ñ Interpreters under the hood
¡ñ Interpreter on the JVM
¡ð Existing solutions
¡ð Future
¡ñ Summary
3. Compiled, interpreted applications
Operating system
Libraries
Compiler
Operating system
Libraries
Executable
Machine Code
C source code
Operating system
Libraries
InterpreterRuby source code
(1.8) GC Libraries
compiled C source code
(executable machine code)
Libraries
GC: Garbage Collector
5. Interpreters under the hood
1. Tokenize
2. Parse
3. AST
Ruby Tokens
Abstract Syntax Tree
nodes
C
Machine
Language
interpret
6. Abstract Syntax Tree
function 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.
7. Interpreter on the JVM
Ruby source code compiled to Java bytecode
Operating system
Libraries
JRuby interpreter
Java Runtime Env.
GC Libraries
Why?
Existing solutions
8. The future is here: Truffle and Graal
Goal: Native support for interpreters
Requirements:
¡ñ simplicity
¡ñ generality
¡ñ performance
9. 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 agnostic
dynamic compiler Common API between
language implementation
and optimization system
Substrate VM
Graal VM
10. Truffle
¡ñ Java framework for writing AST interpreters
¡ñ node specialization with tree rewriting
¡ñ define compiler optimizations, directives
¡ð assumptions
11. Graal
¡ñ 100% Java-based JIT framework
¡ð JIT: Just In Time (compiler)
¡ñ dynamic compiler
¡ñ directly control code generation
¡ñ graph intermediate representation
12. 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.
13. 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.
14. 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?
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/