SlideShare a Scribd company logo
1 of 45
JVM++: The Graal VM
Martin Toshev,
BGOUG, 04.06.2016
Special thanks to Thomas Wuerthinger and
Oracle Labs for inspiring this presentation …
Who am I
Software consultant (CoffeeCupConsulting)
BG JUG board member (http://jug.bg)
OpenJDK and Oracle RDBMS enthusiast
Who am I
Author of Learning RabbitMQ
Agenda
• Overview of the Graal VM
• Building and managing Graal
• Performance benchmarks
• Future directions
Overview of the Graal VM
Overview of the Graal VM
Some background …
static compilation vs dynamic compilation
static compiler
source code (e.g. JVM bytecode)
dynamic compiler
runtime
machine code
runtime
source code (e.g. JVM bytecode)
machine code
Overview of the Graal VM
• The javac tool performs static compilation of Java
sources to bytecode
• The JVM may perform dynamic compilation of
bytecode to machine code for optimization using a
JIT (Just-in-Time) compiler
Overview of the Graal VM
• Graal is a new JIT (Just-in-Time) compiler for the
JVM
• Brings the performance of Java to scripting
languages (via the Truffle API)
• written in Java
Overview of the Graal VM
• In essence the Graal JIT compiler generates
machine code from an optimized AST rather than
bytecode
• However the Graal VM has both AST and bytecode
interpreters
Overview of the Graal VM
• The Graal VM supports the following types of
compilers (apart from the Graal JIT compiler):
--vm server-nograal // server compiler
--vm server // server compiler using Graal
--vm graal // Graal compiler using Graal
--vm client-nograal // client compiler
--vm client // client compiler running Graal
Overview of the Graal VM
• The Truffle API:
– is a Java API
– provides AST (Abstract Syntax Tree) representation of
source code
– provides a mechanism to convert the generated AST
into a Graal IR (intermediate representation)
Overview of the Graal VM
• The Truffle API is declarative (uses Java
annotations)
• The AST graph generated by Truffle is a mixture of
control flow and data flow graph
• Essential feature of the Truffle API is the ability to
specify node specializations used in node rewriting
Overview of the Graal VM
• The Truffle API is used in conjunction with custom
annotation processor that generates code based
on the Truffle annotations used in the interpreter
classes
Truffle
Interpreter
javac
Annotation
processor
Compiled
Interpreter
Generated
Interpreter
source code
Overview of the Graal VM
• General architecture:
HotSpot VM (C++)
Graal (Java)
Truffle (Java) Java Other JVM language
JavaScript Ruby R
Other interpreted
language
Graal <–> Hotspot adapter (C++, Java)
Maxine VM (Java)
Graal <–> Maxine
adapter (Java)
Overview of the Graal VM
• Let’s see, for example, how a JavaScript interpreter
works in Graal …
Overview of the Graal VM
HotSpot VM (C++)
Graal (Java)
Truffle (Java) Java Other JVM language
JavaScript Ruby R
Other interpreted
language
Graal <–> Hotspot adapter (C++, Java)
Run JavaScript file: app.js
Overview of the Graal VM
HotSpot VM (C++)
Graal (Java)
Truffle (Java) Java Other JVM language
JavaScript Ruby R
Other interpreted
language
Graal <–> Hotspot adapter (C++, Java)
JavaScript Interpreter parses app.js and converts it to Truffle AST
Overview of the Graal VM
HotSpot VM (C++)
Graal (Java)
Truffle (Java) Java Other JVM language
JavaScript Ruby R
Other interpreted
language
Graal <–> Hotspot adapter (C++, Java)
The app.js Truffle AST is converted to Graal IR (AST)
Overview of the Graal VM
HotSpot VM (C++)
Graal (Java)
Truffle (Java) Java Other JVM language
JavaScript Ruby R
Other interpreted
language
Graal <–> Hotspot adapter (C++, Java)
The Graal VM has bytecode and AST interpreters along with a JIT compiler
(optimizations and AST lowering is performed to generate machine code
and perform partial evaluation)
Overview of the Graal VM
HotSpot VM (C++)
Graal (Java)
Truffle (Java) Java Other JVM language
JavaScript Ruby R
Other interpreted
language
Graal <–> Hotspot adapter (C++, Java)
When parts of app.js are compiled to machine code by the Graal compiler
the compiled code is transferred to Hotspot for execution by means of
Hotspot APIs and with the help of a Graal – Hotspot adapter interface
Overview of the Graal VM
HotSpot VM (C++)
Graal (Java)
Truffle (Java) Java Other JVM language
JavaScript Ruby R
Other interpreted
language
Graal <–> Hotspot adapter (C++, Java)
Compiled code can also be deoptimized and control is transferred back to
the interpreter (e.g. when an exception occurs, an assumption fails or a
guard is reached)
Overview of the Graal VM
• Optimizations done on the Graal IR include:
– method inlining
– partial escape analysis
– inline caching
– constant folding
– arithmetic optimizations and others …
Overview of the Graal VM
• Currently supported languages include:
– JavaScript (Graal.JS)
– R (FastR)
– Ruby (RubyTruffle)
– Experimental interpreters for C, Python, Smalltalk, LLVM
IR and others …
(some are not open-sourced as of the time of this presentation)
Overview of the Graal VM
• The SimpleLanguage project provides a showcase
on how to use the Truffle APIs
Source file Parser Truffle AST Graal VM
Building the Graal VM
Building the Graal VM
• The Graal VM interoperates with JEP 243: Java-
Level JVM Compiler Interface
• In that regard two modes of operation are
supported – via the Graal VM or via the JVMCI
(JVM Compiler Interface)
Building the Graal VM
• Early access builds of Graal available for download
• You can build Graal on any supported platform
(Windows, Linux, MacOS, Solaris) from source
code
Building the Graal VM
git clone https://github.com/graalvm/mx.git
export PATH=$PWD/mx:$PATH
git clone https://github.com/graalvm/graal-core.git
cd graal-core
mx --vm graal build
mx vm
Building the Graal VM
• The MX tool is a Python (2.7) tool that manages the
Graal projects and allows to:
- update sources and run JUnit tests and benchmarks;
- builds (sub)projects (Java and C++ sources can be built
separately);
- runs VM tools (such as IGV or c1visualizer) that can aid
development of Graal or language interpreters;
- can be used to generate IDE project files for Graal development
(support for Eclipse and NetBeans)
The Graal VM
demo
Performance benchmarks
Performance benchmarks
• According to various JVM benchmarks such as SPECjvm2008
and Scala Dacapo the Graal compiler positions between the
client and server JVM compilers
(source: One VM to Rule Them All, Thomas Wuertinger)
• In general Truffle interpreters provide much better
performance for some dynamic languages
Performance benchmarks
• Graal.JS – shows improvement of 1.5x in some cases
with a peak of 2.6x compared to V8 (running Google Octane’s
benchmark)
• RubyTruffle – shows improvements between 1.5x and 4.5x in some
cases with a peak of 14x compared to JRuby
• FastR - shows improvements between 2x and 39x in some cases
with a peak of 94x compared to GnuR
(source: One VM to Rule Them All, Thomas Wuertinger)
Future directions
Future directions
• Graal provides an extensible framework for
researching and experimenting with other
compiler optimizations
• In that regard new types of compiler optimization
may be introduced in the VM that address runtime
behavior in certain scenarios
Future directions
• Graal provides an extensible framework for
creating language interpreters further simplified by
the Truffle API
• In that regard more languages can be introduced
that run in the Graal VM
• Currently existing languages that compile to
bytecode may support Truffle in the future
Future directions
• Graal provides an extensible framework for
different types of operating systems and CPU
architectures
• In that regard CPU architectures and operating
systems might be supported by Graal
Thank you !
Q&A
References
Graal Project
http://openjdk.java.net/projects/graal/
Graal - A New Just In Time Compiler for the JVM
http://www.oracle.com/technetwork/oracle-labs/program-
languages/overview/index.html
Graal VM: GitHub repositories
https://github.com/graalvm
References
Graal - A Bytecode Agnostic Compiler for the JVM, Thomas Wuerthinger, JVM
Language Summit
http://medianetwork.oracle.com/video/player/1113230360001
Graal and Truffle: One VM to Rule Them All
http://www.slideshare.net/ThomasWuerthinger/graal-truffle-
ethdec2013?qid=848a4965-9768-40d5-b167-
ccd8eb7d1659&v=&b=&from_search=2
References
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for
Building a Multipurpose Runtime
http://www.slideshare.net/ThomasWuerthinger/2014-0424-graal-
modularity?qid=0e86ed21-0b8f-4087-9212-
68f76546d674&v=&b=&from_search=4
Dynamic Compilation - Thomas Wuerthinger
https://www.youtube.com/watch?v=RLsG2kE1EMI
https://www.youtube.com/watch?v=U_QpToYLsO0
JVMLS 2012: Graal
http://medianetwork.oracle.com/video/player/1785432492001
References
Graal Tutorial at CGO 2015 by Christian Wimmer
http://lafo.ssw.uni-linz.ac.at/papers/2015_CGO_Graal.pdf
Writing a language in Truffle: Part 1 - Using Truffle and Graal
https://cesquivias.github.io/blog/2014/10/13/writing-a-language-in-truffle-
part-1-a-simple-slow-interpreter/
Writing a language in Truffle: Part 2 - Using Truffle and Graal
http://cesquivias.github.io/blog/2014/12/02/writing-a-language-in-truffle-
part-2-using-truffle-and-graal/
References
Graal publications, JKU, Linz
http://ssw.jku.at/Research/Projects/JVM/Graal.html
Truffle publications, JKU, Linz
http://ssw.jku.at/Research/Projects/JVM/Truffle.html
References
R as a citizen in a Polyglot world: The promise of the Truffle framework
http://user2015.math.aau.dk/presentations/112.pdf
Truffle/C Interpreter
http://www.manuelrigger.at/downloads/trufflec_thesis.pdf
Graal.JS - high-performance JavaScript on the JVM talk by Christian Wirth
https://www.youtube.com/watch?v=OUo3BFMwQFo

More Related Content

What's hot

HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOUHOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
Lucas Jellema
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java framework
SVDevOps
 

What's hot (20)

Spring Native and Spring AOT
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOT
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOUHOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
 
SpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondSpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and Beyond
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java framework
 
GraalVM Overview Compact version
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact version
 
AOT and Native with Spring Boot 3.0
AOT and Native with Spring Boot 3.0AOT and Native with Spring Boot 3.0
AOT and Native with Spring Boot 3.0
 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservices
 
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
 
JVM Under The Hood WDI.pdf
JVM Under The Hood WDI.pdfJVM Under The Hood WDI.pdf
JVM Under The Hood WDI.pdf
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Java Class Loader
Java Class LoaderJava Class Loader
Java Class Loader
 
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
 
Gradle
GradleGradle
Gradle
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...
 
炎炎夏日學 Android 課程 - Part1: Kotlin 語法介紹
炎炎夏日學 Android 課程 -  Part1: Kotlin 語法介紹炎炎夏日學 Android 課程 -  Part1: Kotlin 語法介紹
炎炎夏日學 Android 課程 - Part1: Kotlin 語法介紹
 

Viewers also liked

Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Thomas Wuerthinger
 
Graal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian Wimmer
Thomas Wuerthinger
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Martin Toshev
 
The HaLVM: A Simple Platform for Simple Platforms
The HaLVM: A Simple Platform for Simple PlatformsThe HaLVM: A Simple Platform for Simple Platforms
The HaLVM: A Simple Platform for Simple Platforms
The Linux Foundation
 

Viewers also liked (20)

Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
 
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
 
Graal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian Wimmer
 
Graal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution PlatformGraal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution Platform
 
Scalable SAAS Meetup - Oct 6th
Scalable SAAS Meetup - Oct 6thScalable SAAS Meetup - Oct 6th
Scalable SAAS Meetup - Oct 6th
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
Security Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java PlatformSecurity Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java Platform
 
Writing Stored Procedures with Oracle Database 12c
Writing Stored Procedures with Oracle Database 12cWriting Stored Procedures with Oracle Database 12c
Writing Stored Procedures with Oracle Database 12c
 
2016 JavaOne Deconstructing REST Security
2016 JavaOne Deconstructing REST Security2016 JavaOne Deconstructing REST Security
2016 JavaOne Deconstructing REST Security
 
Writing Stored Procedures in Oracle RDBMS
Writing Stored Procedures in Oracle RDBMSWriting Stored Procedures in Oracle RDBMS
Writing Stored Procedures in Oracle RDBMS
 
Writing Java Stored Procedures in Oracle 12c
Writing Java Stored Procedures in Oracle 12cWriting Java Stored Procedures in Oracle 12c
Writing Java Stored Procedures in Oracle 12c
 
Modular Java
Modular JavaModular Java
Modular Java
 
RxJS vs RxJava: Intro
RxJS vs RxJava: IntroRxJS vs RxJava: Intro
RxJS vs RxJava: Intro
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
KDB database (EPAM tech talks, Sofia, April, 2015)
KDB database (EPAM tech talks, Sofia, April, 2015)KDB database (EPAM tech talks, Sofia, April, 2015)
KDB database (EPAM tech talks, Sofia, April, 2015)
 
Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink
Gábor Horváth - Code Generation in Serializers and Comparators of Apache FlinkGábor Horváth - Code Generation in Serializers and Comparators of Apache Flink
Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink
 
Security Architecture of the Java platform
Security Architecture of the Java platformSecurity Architecture of the Java platform
Security Architecture of the Java platform
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
 
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
 
The HaLVM: A Simple Platform for Simple Platforms
The HaLVM: A Simple Platform for Simple PlatformsThe HaLVM: A Simple Platform for Simple Platforms
The HaLVM: A Simple Platform for Simple Platforms
 

Similar to JVM++: The Graal VM

Java ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many LanguagesJava ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many Languages
elliando dias
 

Similar to JVM++: The Graal VM (20)

Javantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin ToshevJavantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin Toshev
 
GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance Interoperability
 
GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22
 
GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18
 
HOW TO CREATE AWESOME POLYGLOT APPLICATIONS USING GRAALVM
HOW TO CREATE AWESOME POLYGLOT APPLICATIONS USING GRAALVMHOW TO CREATE AWESOME POLYGLOT APPLICATIONS USING GRAALVM
HOW TO CREATE AWESOME POLYGLOT APPLICATIONS USING GRAALVM
 
Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!
 
PL-4042, Wholly Graal: Accelerating GPU offload for Java/Sumatra using the Op...
PL-4042, Wholly Graal: Accelerating GPU offload for Java/Sumatra using the Op...PL-4042, Wholly Graal: Accelerating GPU offload for Java/Sumatra using the Op...
PL-4042, Wholly Graal: Accelerating GPU offload for Java/Sumatra using the Op...
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
 
Java 40 versions_sgp
Java 40 versions_sgpJava 40 versions_sgp
Java 40 versions_sgp
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Python Streaming Pipelines with Beam on Flink
Python Streaming Pipelines with Beam on FlinkPython Streaming Pipelines with Beam on Flink
Python Streaming Pipelines with Beam on Flink
 
Flink Forward Berlin 2018: Thomas Weise & Aljoscha Krettek - "Python Streamin...
Flink Forward Berlin 2018: Thomas Weise & Aljoscha Krettek - "Python Streamin...Flink Forward Berlin 2018: Thomas Weise & Aljoscha Krettek - "Python Streamin...
Flink Forward Berlin 2018: Thomas Weise & Aljoscha Krettek - "Python Streamin...
 
Java1 in mumbai
Java1 in mumbaiJava1 in mumbai
Java1 in mumbai
 
Java script anywhere. What Nombas was doing pre-acquisition.
Java script anywhere. What Nombas was doing pre-acquisition.Java script anywhere. What Nombas was doing pre-acquisition.
Java script anywhere. What Nombas was doing pre-acquisition.
 
Java ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many LanguagesJava ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many Languages
 
Asm.js introduction
Asm.js introductionAsm.js introduction
Asm.js introduction
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 

More from Martin Toshev

Semantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12cSemantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12c
Martin Toshev
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
Martin Toshev
 

More from Martin Toshev (15)

Building highly scalable data pipelines with Apache Spark
Building highly scalable data pipelines with Apache SparkBuilding highly scalable data pipelines with Apache Spark
Building highly scalable data pipelines with Apache Spark
 
Big data processing with Apache Spark and Oracle Database
Big data processing with Apache Spark and Oracle DatabaseBig data processing with Apache Spark and Oracle Database
Big data processing with Apache Spark and Oracle Database
 
Jdk 10 sneak peek
Jdk 10 sneak peekJdk 10 sneak peek
Jdk 10 sneak peek
 
Semantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12cSemantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12c
 
Practical security In a modular world
Practical security In a modular worldPractical security In a modular world
Practical security In a modular world
 
Java 9 Security Enhancements in Practice
Java 9 Security Enhancements in PracticeJava 9 Security Enhancements in Practice
Java 9 Security Enhancements in Practice
 
Java 9 sneak peek
Java 9 sneak peekJava 9 sneak peek
Java 9 sneak peek
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
Oracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsOracle Database 12c Attack Vectors
Oracle Database 12c Attack Vectors
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
java2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Serversjava2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Servers
 
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Recently uploaded (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

JVM++: The Graal VM

  • 1. JVM++: The Graal VM Martin Toshev, BGOUG, 04.06.2016
  • 2. Special thanks to Thomas Wuerthinger and Oracle Labs for inspiring this presentation …
  • 3. Who am I Software consultant (CoffeeCupConsulting) BG JUG board member (http://jug.bg) OpenJDK and Oracle RDBMS enthusiast
  • 4. Who am I Author of Learning RabbitMQ
  • 5. Agenda • Overview of the Graal VM • Building and managing Graal • Performance benchmarks • Future directions
  • 6. Overview of the Graal VM
  • 7. Overview of the Graal VM Some background … static compilation vs dynamic compilation static compiler source code (e.g. JVM bytecode) dynamic compiler runtime machine code runtime source code (e.g. JVM bytecode) machine code
  • 8. Overview of the Graal VM • The javac tool performs static compilation of Java sources to bytecode • The JVM may perform dynamic compilation of bytecode to machine code for optimization using a JIT (Just-in-Time) compiler
  • 9. Overview of the Graal VM • Graal is a new JIT (Just-in-Time) compiler for the JVM • Brings the performance of Java to scripting languages (via the Truffle API) • written in Java
  • 10. Overview of the Graal VM • In essence the Graal JIT compiler generates machine code from an optimized AST rather than bytecode • However the Graal VM has both AST and bytecode interpreters
  • 11. Overview of the Graal VM • The Graal VM supports the following types of compilers (apart from the Graal JIT compiler): --vm server-nograal // server compiler --vm server // server compiler using Graal --vm graal // Graal compiler using Graal --vm client-nograal // client compiler --vm client // client compiler running Graal
  • 12. Overview of the Graal VM • The Truffle API: – is a Java API – provides AST (Abstract Syntax Tree) representation of source code – provides a mechanism to convert the generated AST into a Graal IR (intermediate representation)
  • 13. Overview of the Graal VM • The Truffle API is declarative (uses Java annotations) • The AST graph generated by Truffle is a mixture of control flow and data flow graph • Essential feature of the Truffle API is the ability to specify node specializations used in node rewriting
  • 14. Overview of the Graal VM • The Truffle API is used in conjunction with custom annotation processor that generates code based on the Truffle annotations used in the interpreter classes Truffle Interpreter javac Annotation processor Compiled Interpreter Generated Interpreter source code
  • 15. Overview of the Graal VM • General architecture: HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) Maxine VM (Java) Graal <–> Maxine adapter (Java)
  • 16. Overview of the Graal VM • Let’s see, for example, how a JavaScript interpreter works in Graal …
  • 17. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) Run JavaScript file: app.js
  • 18. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) JavaScript Interpreter parses app.js and converts it to Truffle AST
  • 19. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) The app.js Truffle AST is converted to Graal IR (AST)
  • 20. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) The Graal VM has bytecode and AST interpreters along with a JIT compiler (optimizations and AST lowering is performed to generate machine code and perform partial evaluation)
  • 21. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) When parts of app.js are compiled to machine code by the Graal compiler the compiled code is transferred to Hotspot for execution by means of Hotspot APIs and with the help of a Graal – Hotspot adapter interface
  • 22. Overview of the Graal VM HotSpot VM (C++) Graal (Java) Truffle (Java) Java Other JVM language JavaScript Ruby R Other interpreted language Graal <–> Hotspot adapter (C++, Java) Compiled code can also be deoptimized and control is transferred back to the interpreter (e.g. when an exception occurs, an assumption fails or a guard is reached)
  • 23. Overview of the Graal VM • Optimizations done on the Graal IR include: – method inlining – partial escape analysis – inline caching – constant folding – arithmetic optimizations and others …
  • 24. Overview of the Graal VM • Currently supported languages include: – JavaScript (Graal.JS) – R (FastR) – Ruby (RubyTruffle) – Experimental interpreters for C, Python, Smalltalk, LLVM IR and others … (some are not open-sourced as of the time of this presentation)
  • 25. Overview of the Graal VM • The SimpleLanguage project provides a showcase on how to use the Truffle APIs Source file Parser Truffle AST Graal VM
  • 27. Building the Graal VM • The Graal VM interoperates with JEP 243: Java- Level JVM Compiler Interface • In that regard two modes of operation are supported – via the Graal VM or via the JVMCI (JVM Compiler Interface)
  • 28. Building the Graal VM • Early access builds of Graal available for download • You can build Graal on any supported platform (Windows, Linux, MacOS, Solaris) from source code
  • 29. Building the Graal VM git clone https://github.com/graalvm/mx.git export PATH=$PWD/mx:$PATH git clone https://github.com/graalvm/graal-core.git cd graal-core mx --vm graal build mx vm
  • 30. Building the Graal VM • The MX tool is a Python (2.7) tool that manages the Graal projects and allows to: - update sources and run JUnit tests and benchmarks; - builds (sub)projects (Java and C++ sources can be built separately); - runs VM tools (such as IGV or c1visualizer) that can aid development of Graal or language interpreters; - can be used to generate IDE project files for Graal development (support for Eclipse and NetBeans)
  • 33. Performance benchmarks • According to various JVM benchmarks such as SPECjvm2008 and Scala Dacapo the Graal compiler positions between the client and server JVM compilers (source: One VM to Rule Them All, Thomas Wuertinger) • In general Truffle interpreters provide much better performance for some dynamic languages
  • 34. Performance benchmarks • Graal.JS – shows improvement of 1.5x in some cases with a peak of 2.6x compared to V8 (running Google Octane’s benchmark) • RubyTruffle – shows improvements between 1.5x and 4.5x in some cases with a peak of 14x compared to JRuby • FastR - shows improvements between 2x and 39x in some cases with a peak of 94x compared to GnuR (source: One VM to Rule Them All, Thomas Wuertinger)
  • 36. Future directions • Graal provides an extensible framework for researching and experimenting with other compiler optimizations • In that regard new types of compiler optimization may be introduced in the VM that address runtime behavior in certain scenarios
  • 37. Future directions • Graal provides an extensible framework for creating language interpreters further simplified by the Truffle API • In that regard more languages can be introduced that run in the Graal VM • Currently existing languages that compile to bytecode may support Truffle in the future
  • 38. Future directions • Graal provides an extensible framework for different types of operating systems and CPU architectures • In that regard CPU architectures and operating systems might be supported by Graal
  • 40. References Graal Project http://openjdk.java.net/projects/graal/ Graal - A New Just In Time Compiler for the JVM http://www.oracle.com/technetwork/oracle-labs/program- languages/overview/index.html Graal VM: GitHub repositories https://github.com/graalvm
  • 41. References Graal - A Bytecode Agnostic Compiler for the JVM, Thomas Wuerthinger, JVM Language Summit http://medianetwork.oracle.com/video/player/1113230360001 Graal and Truffle: One VM to Rule Them All http://www.slideshare.net/ThomasWuerthinger/graal-truffle- ethdec2013?qid=848a4965-9768-40d5-b167- ccd8eb7d1659&v=&b=&from_search=2
  • 42. References Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for Building a Multipurpose Runtime http://www.slideshare.net/ThomasWuerthinger/2014-0424-graal- modularity?qid=0e86ed21-0b8f-4087-9212- 68f76546d674&v=&b=&from_search=4 Dynamic Compilation - Thomas Wuerthinger https://www.youtube.com/watch?v=RLsG2kE1EMI https://www.youtube.com/watch?v=U_QpToYLsO0 JVMLS 2012: Graal http://medianetwork.oracle.com/video/player/1785432492001
  • 43. References Graal Tutorial at CGO 2015 by Christian Wimmer http://lafo.ssw.uni-linz.ac.at/papers/2015_CGO_Graal.pdf Writing a language in Truffle: Part 1 - Using Truffle and Graal https://cesquivias.github.io/blog/2014/10/13/writing-a-language-in-truffle- part-1-a-simple-slow-interpreter/ Writing a language in Truffle: Part 2 - Using Truffle and Graal http://cesquivias.github.io/blog/2014/12/02/writing-a-language-in-truffle- part-2-using-truffle-and-graal/
  • 44. References Graal publications, JKU, Linz http://ssw.jku.at/Research/Projects/JVM/Graal.html Truffle publications, JKU, Linz http://ssw.jku.at/Research/Projects/JVM/Truffle.html
  • 45. References R as a citizen in a Polyglot world: The promise of the Truffle framework http://user2015.math.aau.dk/presentations/112.pdf Truffle/C Interpreter http://www.manuelrigger.at/downloads/trufflec_thesis.pdf Graal.JS - high-performance JavaScript on the JVM talk by Christian Wirth https://www.youtube.com/watch?v=OUo3BFMwQFo

Editor's Notes

  1. The JVM may also perform deoptimization.
  2. This essentially means the Graal VM can run in client/server mode but also use the Graal JIT compiler in certain scenarios
  3. Truffle can be used for static analysis as well
  4. Truffle can be used for static analysis as well
  5. Without Graal you will be need to write a bytecode compiler.
  6. There are high level optimization on the AST and low level optimization (after the AST is lowered).
  7. In inline caching the callee is cached at the call site instead of a dynamic callee method lookup. -
  8. Some of the languages are not open-sourced as of the time of this presentation (such as GraalJS). Interpreter executables are provided in the official distribution under <GraalVM>/bin/ (e.g. <GraalVM>/bin/js for GraalJS)
  9. Up to JDK 9 Graal had to use a modified version of Hotspot. With JDK9 the JVMCI enables the deployment of Graal on top of an existing JVM without further modifications (using JVMCI).