ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Run * on the JVM
Interpreters on the JVM with
Graal and Truffle
Balazs Varga / @vbalazs
Agenda
¡ñ Compiled, interpreted applications and VMs
¡ñ Interpreters under the hood
¡ñ Interpreter on the JVM
¡ð Existing solutions
¡ð Future
¡ñ Summary
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
Virtual Machines (runtimes)
Operating system
Libraries
Java compiler
Operating system
Libraries
Executable
JVM bytecode
Java source code
Libraries
JVM
bytecode
Java Runtime Env.
GC Libraries
Interpreters under the hood
1. Tokenize
2. Parse
3. AST
Ruby Tokens
Abstract Syntax Tree
nodes
C
Machine
Language
interpret
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.
Interpreter on the JVM
Ruby source code compiled to Java bytecode
Operating system
Libraries
JRuby interpreter
Java Runtime Env.
GC Libraries
Why?
Existing solutions
The future is here: Truffle and Graal
Goal: Native support for interpreters
Requirements:
¡ñ simplicity
¡ñ generality
¡ñ performance
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
Truffle
¡ñ Java framework for writing AST interpreters
¡ñ node specialization with tree rewriting
¡ñ define compiler optimizations, directives
¡ð assumptions
Graal
¡ñ 100% Java-based JIT framework
¡ð JIT: Just In Time (compiler)
¡ñ dynamic compiler
¡ñ directly control code generation
¡ñ graph intermediate representation
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.
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.
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?
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/
Questions?

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
  • 4. Virtual Machines (runtimes) Operating system Libraries Java compiler Operating system Libraries Executable JVM bytecode Java source code Libraries JVM bytecode Java Runtime Env. GC Libraries
  • 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/