Run * on the JVM - Simonyi Conference Budapest April 15

Preview:

Citation preview

Run * on the JVMInterpreters 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

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

Virtual Machines (runtimes)

Operating system

Libraries

Java compiler

Operating system

Libraries

ExecutableJVM bytecodeJava source code

Libraries

JVMbytecode

Java Runtime Env.

GC Libraries

Interpreters under the hood

1. Tokenize2. Parse3. AST

Ruby Tokens Abstract Syntax Treenodes C Machine

Languageinterpret

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.

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 agnosticdynamic 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?

Recommended