How to create Polyglot Applications using
GraalVM
@owais_zahid
@owaiszahid
Know your speaker
• Software Development Manager at Autodesk
• Over 14 years of experience working around the globe
• Focus areas
• Cloud Platforms
• Resiliency and Scalability
• Love to code in JavaScript
• Avid fan of AS ROMA @owais_zahid
@owaiszahid
Interoperability
What to do for
Interoperability
Apache
Thrift
Swig
Protocol
Buffer
Java Native
Interface
AWS Layers
and Runtime
GraalVM
And many
more…
What is
GraalVM
GraalVM is a polyglot (multi-
lingual) Virtual Machine
Allows a common stack for
applications running in JavaScript,
Python, Ruby, Java, Scala, C / C++ n
many more.
Provides interoperability in a
shared runtime
JEP 243 (JVMCI) JEP 295 (AOTC)
Java HotSpot VM SubstrateVM
Graal VM Architecture
JEP 243 (JVMCI) JEP 295 (AOTC)
Java HotSpot VM SubstrateVM
Graal Compiler
Graal Compiler
Graal
Written in Java
Easy to maintain
Embeddable
Support for Truffle based Languages
Graal
Compiler
Truffle
Language implementation framework
Currently supports Ruby, Python, R
Provision to support new languages
Works with Graal
Compiler to provide
Low-overhead language
interoperations
Language agnostic
instrumentation
Sulong
LLVM bitcode interpreter based
on truffle framework
Support C/C++, Fortran and all
languages that can be
converted to LLVM bitcode
Ahead of
Time
Compilation
Create Native Image with Graal AOT
Compilation
Substrate VM executes native code
Reduces startup time and lower runtime
memory overheads
AOT support added in JDK 9
(experimental). See JEP 295
Native vs JVM
• Graal supports two modes of
execution
• JVM
Better peak performance and
support for dynamic programming
• Native
Better startup time and lesser
memory footprint
Should I be using Graal?
This Photo by Unknown Author is licensed under CC BY-SA-NC
Benchmarks
0
50
100
150
200
250
300
350
400
450
500
Embedded Templating
1000IPS
EBR Benchmark
Jruby TruffleRuby
0
2
4
6
8
10
12
14
16
base64
IPS
Base64 Benchmark
Jruby TruffleRuby
0.5
9.3
4.3
0
1
2
3
4
5
6
7
8
9
10
ExecutionTime
Json Benchmark (JVM)
Jruby TruffleRuby Truffle-Node
Benchmarks
0.5
6.9
0.2
0
1
2
3
4
5
6
7
8
ExecutionTime
Json Benchmark (Native)
Jruby TruffleRuby Truffle-Node
Benchmarks
Demo # 1
Ruby - Node Interop
Demo # 2
Java - NodeJS Interop
Demo # 3
CSE v2 on Graal
Ruby – Java Polyglot
NodeJS – Java Polyglot
Demo # 4
Graal Tools
You can’t optimize what you can’t measure
- Ilya Grigorik
Lesson
Learns
Better suited for custom code, libraries
and SDKs
There are some performance gaps in
truffle implementations
JDK 10+ is recommended for
containerize applications
Not widely used in production apps
(yet!)
References
Git https://github.com/zaknuces/graal-benchmarks
https://github.com/oracle/graal
https://github.com/graalvm/
Autodesk Cloud
Platform
https://forge.autodesk.com/
https://knowledge.autodesk.com/
Open JDK https://openjdk.java.net/jeps/295
https://openjdk.java.net/jeps/243
Research
Papers
https://chrisseaton.com/truffleruby/ropes-manlang.pdf
https://2016.ecoop.org/event/icooolps-2016-sulong-execution-of-llvm-based-languages-
on-the-jvm
Thank you
@owais_zahidFor questions or comments:
#VoxxedDaysGraal

HOW TO CREATE AWESOME POLYGLOT APPLICATIONS USING GRAALVM

Editor's Notes

  • #5 Swig focuses on C++ -> other language interop (using interface file) Proto Buf -> Better serialization
  • #7 Add Subtrate VM in architecture
  • #8 Add Subtrate VM in architecture
  • #15 Native vs JVM
  • #17 Benchmark (Graal) (Mine) truffle native results are bad were 4 IPS at best.
  • #18 Benchmark (Graal) (Mine) Truffle-Node Native : 0.26 sec Truffle Ruby jvm : 18 sec ---------------------
  • #21 Notification Service
  • #22 Java – Ruby (CSE SDK)
  • #25 Show an example of Chrome Dev Tool Show an example of CPU Sampler Change Example Show VisualVM