However, we understand switching from the established Oracle JVM or OpenJDK to GraalVM is a bold step that you might not want to fully take just yet. But, you might want to try out some of the cool capabilities of the GraalVM project on a stock JVM.
org.graalvm.polyglot interface, but also with the
javax.script (JSR 223 ScriptEngine) interface. In addition, the example code is executed via ScriptEngine on the Nashorn engine (if available). An identical number of warmup and measurement iterations is executed and printed as a simple benchmark, showing the execution time necessary on the respective engine (lower values are better).
The example is available on GitHub:
JAVA_HOME point to it.
mvn clean && mvn package && mvn exec:exec@graal
For the sake of comparison, you can execute the same benchmark without Graal compilation enabled:
mvn clean && mvn package && mvn exec:exec@nograal
Some technical insights
What is happening behind the scene? In the
pom.xml file several dependencies to relevant packages are declared, including
org.graalvm.js. Those are available on Maven central and are downloaded from there.
Three arguments are passed to the JVM as declared in the plugin configuration section that enable Graal compilation on the JVM:
-XX:+UnlockExperimentalVMOptionsThis flag enables the following option
-XX:+EnableJVMCIEnables compilation of Java code via JVMCI (the Java Virtual Machine Compiler Interface)
In the future, it might be possible to provide more artifacts of GraalVM on Maven Central and allow even more languages to be executed this way on other JVMs, without the need to install the GraalVM binaries itself.