This document provides a high-level summary of GraalVM and its capabilities for running applications and languages on the Java Virtual Machine. Specifically, it discusses how GraalVM allows running JavaScript, Python, Ruby, R, Java and C/C++ efficiently on the JVM through projects like Truffle and Substrate. It also summarizes GraalVM's polyglot capabilities for interoperability between languages and ahead-of-time compilation of Java into native binaries.
8. WHATS IN
FOR ME?• Better JVM performance
• Maintainable JIT compiler
• Faster evolution of Java
• With Truffle Language Runtime
–Run JavaScript, Ruby, R, Python,
LLVM code efficiently on the JVM
• With Substrate VM
–Binaries for Language Runtimes
–AOT compiled native images of
your applications
Lego box
10. HOW CAN
I USE IT?• Dedicated GraalVM Download
or using sdkman
gu (graal-updater) Utility
js/node, ruby, python, R runtimes
native-image tool
• Java 11 with command line flags
-XX:+UnlockExperimentalVMOptions
-XX:+EnableJVMCI -XX:+UseJVMCICompiler
https://www.graalvm.org/downloads/
11. JAVA 11
sdk use java 11.0.1-open
java -Diterations=3
CountUppercase
I‘m happy to be back in Portland,
OR for OSCON 2019
-XX:+UnlockExperimentalVMOptions
-XX:+UseJVMCICompiler
-Dgraal.PrintCompilation=true
12. GRAALVMsdk install java 19.1.0-grl
gu install R python ruby native-image
gu list
ComponentId Version Component name
-----------------------------------
graalvm 19.1.0 GraalVM Core
R 19.1.0 FastR
native-image 19.1.0 Native Image
python 19.1.0 Graal.Python
ruby 19.1.0 TruffleRuby
java –version
OpenJDK 64-Bit GraalVM CE 19.1.0 (build
25.212-b03-jvmci-20-b04, mixed mode)
Lego Instructions built
13. PYTHON
# graalpython fac.py 2500
import sys
def fac(n):
if n==1: return 1
else: return fac(n-1)*n
x = int(sys.argv[1])
print("Factorial for {} is {}"
.format(x,fac(x)))
18. VISION STATEMENT
Create an extensible, modular, dynamic,
and aggressive compiler using object-
oriented and reflective Java programming, a graph-
based and visualizable intermediate representation,
and Java snippets.
—ThomasWürthinger
19. G R A A L ! ?
• JIT-Compiler implemented in Java !?!
• Aggressively optimizing
–e.g. inlining POJOS/DTOS
–Inlining streams
–Speeds up many typical Java/Scala
programs
• Uses compute graph for
optimization
• New compiler interface (JVMCI)
22. GraalVM is a high-performance,
embeddable, polyglotVirtual Machine for
running applications written in JavaScript,
Python, Ruby, R, JVM-based languages like
Java, Scala, Kotlin, and LLVM-based
languages such as C and C++.
Additionally, GraalVM allows efficient
interoperability between programming
languages and compiling Java applications
ahead-of-time into native executables for
faster startup time and lower memory
overhead. https://github.com/oracle/graal/releases
BIGGER ON
THE INSIDE
23.
24. • Collection of Research Projects
– TruffleRuby / FastR
• Maxine (Research)VM in Java
• „A Joke?“
• „Java-on-Java“ John Rose
– Project Metropolis
• Power Combo:
– Substrate-VM
– Truffle
– Graal Compiler
– AOT Compilation
HISTORY
27. NATIVE
IMAGE
• Aggressive Ahead of time compilation (AOT)
• Extremely fast startup time
• Small binary executables for current OS
• Class initialization during build
• For FaaS, Commandline
• Microservices: Micronaut, Helidon, Quarkus,
Spring (soon)
• No classloading / class metadata
• Limitations:
– no reflection, no later classloading, no initializer
dynamics
– Slow build
https://medium.com/graalvm/lightweight-cloud-native-java-applications-
35d56bc45673
29. TRUFFLE
• Language Runtime
• API & Type system
• Implement language constructs
• Annotated Java Methods
– Tooling,Testing
• Generic or specialized operations
31. TRUFFLE
GRAAL• Integrates with Graal Compiler
• Partial Evaluation
• Optimize special cases based on
steady state assumption
• Deoptimize (trap) on failed
assumptions
35. JAVASCRIP
T
• Main target language via graaljs
• Replacement for Rhino/Nashorn
• EcmaScript 2019 & Node.js
(10.15.2) compat
• 90% of 95k npm packages
• Graaljs can run slowly w/o Graal
• ScriptEngine support
• org.graalvm.js:js/js-scriptengine
https://www.graalvm.org/docs/reference-manual/languages/js/
36. GRAAL
PYTHON
• Early stage support Python 3.7
• Goal: „SciPy“ support
• No python debugger, but
GraalVMs
https://www.graalvm.org/docs/reference-manual/languages/python/
37. FAST-R
• Compatible with GNU R (3.5.1)
• Much faster than other R
implementations
• R/Rscript
• Install packages (e.g. ggplot2, Shiny)
• Minimal: graphics package
• Compatibility checker
• Tools (debugger, profiler)
• Java based Graphics
https://www.graalvm.org/docs/reference-manual/languages/r/
39. LLVM
• LLVM 6.0.0 Bitcode
• Via Sulong a LLVM implementation
in Java via Truffle
• Can use native libraries
• lli to execute LLVM Bitcode
• Sandbox in GraalVM Enterprise
– sandbox libraries
– virtualize syscalls
– memory on managed heap
https://medium.com/graalvm/safe-and-sandboxed-execution-of-
native-code-f6096b35c360
41. TRUFFLE
• Based on Truffle Implementations
of dynamic languages
• Joint underlying API / Typesystem
• Context
– eval
– bind
– invoke
• Source
• Value.*
docs.oracle.com/en/graalvm/enterprise/19/sdk/org/graalvm/polyglot/Context.html
42. VALUE
• The „Any“ type across languages
– Scalar
– List/Array
– Host/Proxy Object w/ Members
– Function/Invoke/Executable
• Provides some semantics and
conversions
• Removes need for (de)serialization
• Thread safety depends on language
support
docs.oracle.com/en/graalvm/enterprise/19/sdk/org/graalvm/polyglot/Value.html
52. POLYGLOT EXAMPLE (JAVA+R)
library(ggplot2)
data <<- numeric(100)
function(dataHolder) {
svg()
data <<-
c(data[2:100],dataHolder$value)
plot <- ggplot(data=
data.frame(systemLoad=data,
time =-99:0),
aes(x=time, y=systemLoad, group=1)) +
geom_line(color="orange") +
expand_limits(x=0, y=0)
print(plot)
svg.off()
}
53. POLYGLOT SHELL
Context context = Context.newBuilder().allowAllAccess(true).build();
Set<String> languages = context.getEngine().getLanguages().keySet();
out.println("Shell for " + languages + ":");
String language = languages.iterator().next();
while (true) {
out.print(language + "> ");
String line = input.readLine();
if (line == null) break;
else if (languages.contains(line)) language = line;
else {
Source source = Source.newBuilder(language, line, "<shell>")
.interactive(true).buildLiteral();
context.eval(source);
}
}
54. POLYGLOT
OPTIONS
Print GraalVM version information and exit.
--version:graalvm
Print GraalVM version information and continue execution.
--show-version:graalvm
Start with Debugger
--inspect
Run using the native launcher with limited Java access
--native
Run on the JVM with Java access.
--jvm
Run with all other guest languages accessible.
--polyglot
Pass options to the host VM
--vm.[option]
Options for all installed languages, tools, host VM
--help:languages,tools,vm,expert
Internal options for debugging language impl and tools.
--help:internal
60. WHY?
• Allow “programmatic“ extensions
• Move processing to data, avoid network
transfers
• Not just procedures in
– PL/SQL
– Java
• Reuse existing code
– public packages (e.g. validators, data
science, visualization)
– domain specific code
• Because you can!
61. EXTENDING
DATABASES• „Multilingual Engine“
– native library integration
• Available from Oracle Labs
• For Oracle and MySQL
• Deploy custom functions in JavaScript,
R, Python with dbjs
dbjs deploy -u <user> -p <pass>
-c localhost:1521/ORCLCDB <package>
• Create statically and call from SQL
https://www.graalvm.org/docs/examples/mle-oracle/
62. SQL FUNCTION IN JAVASCRIPT
CREATE OR REPLACE JAVASCRIPT SOURCE NAMED "hello.js" AS
module.exports.greet = function(a) { return "Hello " + a; };
CREATE OR REPLACE FUNCTION greet(a IN VARCHAR2) RETURN VARCHAR2 AS
LANGUAGE JAVASCRIPT NAME 'hello.js.greet(a string) return string‘;
SELECT greet('GraalVM') FROM DUAL;
Hello GraalVM
64. NEO4J IN
A TWEET@Neo4j is an open-source native
graph database designed to store,
manage and query highly connected
data efficiently with the Cypher
Query Language.
It runs transactional and analytic
workloads, supports visualization
and is extendable with custom
functions.
neo4j.com/developer
65. NEO4J
• Runs on the JVM
• Full Stack database
• Declarative Graph Query
Language
• Binary Protocol
• Drivers for most languages
• Visual Browser
• Integrations like GraphQL, Kafka
• Custom Procedures and Functions
67. TALK RECOMMENDATION
// top 10 talks (that I‘ve not see)
// that peers who like the same talks I did also liked
MATCH (me:User {name:“Michael“})
-[:FAVORITED]->(:Event)<-[:FAVORITED]-(peer:User)
-[:FAVORITED]->(reco:Event)
WHERE NOT (me)-[:FAVORITED]->(reco)
RETURN reco.name, count(*) AS freq
ORDER BY freq DESC LIMIT 10
70. NEO4J
CUSTOM
FUNCTIONS• Annotated Java Methods
• Loaded at startup
• Computation or Aggregation
with Functions
• Data processing & streaming with
Procedures
• Accessible from Cypher Query
Language
73. POLYGLOT
FUNCTIONS
• Using Truffle API
• Declare + invoke function with
params, or
• Execute code with bindings
1. Use Context to run polyglot code
2. Use Cypher to declare dynamic
language functions
3. Install language files from directory
4. Store code in db to restore at
restart / in cluster
90. THE GOOD
• It works!
– All the languages
– JVM Interop
– Polyglot Interop
• Continuous improvements by the
Oracle Team
• Lots of great docs & articles
• Adding those database extensions
was really easy
92. THE BAD
• Python support still preliminary
• Too many polyglot indirections are
costly
• Interop a bit kludgy
• Error messages not that helpful
• No automatic mapping of
collection types (map/hash/dict)
and (list/collection) – only for
arrays
95. Graphs in AI and ML
Alicia Frame, Senior Data Scientist, Neo4j
Jake Graham, Lead Product Manager for AI and Graph Analytics
Intro to Neo4j for Developers
Jennifer Reif, Developer Relations Engineer, Neo4j
Neo4j Bolt Driver Architecture Now and inThe Future
Nigel Small,Tech Lead for Neo4j Drivers team
GRANDstack: Graphs ALL the Way Down
William Lyon, Software Engineer, Neo4j Labs
All-new SDN-RX: Reactive Spring Data Neo4j
Gerrit Meier, Software Engineer, Neo4j
Graph Embeddings
Alicia Frame, Senior Data Scientist, Neo4j
Graph ModelingTips andTricks
Max De Marzi, Field Engineer and Graph Expert, Neo4j
APOC Pearls -The bestTips andTricks
Michael Hunger, Director of Neo4j Labs
Visualizing Graph Data in JavaScript
Will Lyon, Software Engineer, Neo4j Labs
Creating a Data Marvel (Comics) with Spring and Neo4j
Jennifer Reif, Developer Relations Engineer, Neo4j
Keynote and Announcements
Emil Eifrem, CEO and Co-Creator of Neo4j
October 10
8am NYC, 1pm London, 530pm Mumbai