Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm using the latest (
21.0.0
) version of GraalVM for JavaScript via Maven in Nashorn compatibility mode.
Upon noticing functions like
Java.addToClassPath
and objects like
Polyglot
don't exist, I ran the sample code shown
here
:
if (typeof Graal != 'undefined') {
print(Graal.versionJS);
print(Graal.versionGraalVM);
print(Graal.isGraalRuntime());
Output:
undefined
snapshot
false
This looks weird to me. How can I access functions and objects like the above ones?
Thanks.
Graal.isGraalRuntime() returning false is a red flag. That means you are NOT using GraalVM as optimizing compiler. You can evaluate JavaScript that way, but it will be horribly slow, because the code is never compiled to machine code.
The preferred way to execute the code is obviously on GraalVM - then everything will be in place already.
To run GraalVM JavaScript on a stock JDK, there is documentation on graalvm.org: https://www.graalvm.org/reference-manual/js/RunOnJDK/#graalvm-javascript-on-jdk-11
The basic commandline you will need after you downloaded the JAR files from maven, including the GraalVM compiler itself (this should work on JDK11 or later). The relevant part there that might be different from your current setup is the --upgrade-module-path where you add GraalVM Compiler:
JARS=/path/to/JARs
JDK=/path/to/JDK
$JDK/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler --module-path=$JARS/graal-sdk-21.0.0.jar:$JARS/truffle-api-21.0.0.jar --upgrade-module-path=$JARS/compiler-21.0.0.jar:$JARS/compiler-management-21.0.0.jar -cp $JARS/launcher-common-21.0.0.jar:$JARS/js-launcher-21.0.0.jar:$JARS/js-21.0.0.jar:$JARS/truffle-api-21.0.0.jar:$JARS/graal-sdk-21.0.0.jar:$JARS/js-scriptengine-21.0.0.jar:$JARS/regex-21.0.0.jar:$JARS/icu4j-67.1.jar com.oracle.truffle.js.shell.JSLauncher
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.