Skip to content

Commit e9764e5

Browse files
committed
Update RunOnJDK.md
1 parent 2974b5c commit e9764e5

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

docs/user/RunOnJDK.md

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,41 @@ GraalVM JavaScript is optimized for execution as part of GraalVM, or in an embed
1010
This guarantees best possible performance by using the [GraalVM compiler](https://github.com/oracle/graal) as the optimizing compiler, and potentially [Native Image](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/README.md) to ahead-of-time compile the engine into a native binary.
1111

1212
As GraalVM JavaScript is a Java application, it is possible to execute it on a stock Java VM like OpenJDK.
13-
When executed without the GraalVM compiler, JavaScript performance will be significantly worse.
13+
When executed without the Graal Compiler, JavaScript performance will be significantly worse.
1414
While the JIT compilers available on stock JVMs can execute and JIT-compile the GraalVM JavaScript codebase, they cannot optimize it to its full performance potential.
1515
This document describes how to run GraalVM JavaScript on stock Java VMs, and shows how you can use the GraalVM compiler as a JIT compiler to guarantee the best possible performance.
1616

1717
## GraalVM JavaScript on Maven Central
1818
GraalVM JavaScript is open source and regularly pushed to Maven Central Repository by the community.
19-
You can find it as package [org.graalvm.js](https://mvnrepository.com/artifact/org.graalvm.js/js).
19+
You can find it as pom artifact [org.graalvm.polyglot:js](https://mvnrepository.com/artifact/org.graalvm.polyglot/js).
2020

21-
There is an example Maven project for GraalVM JavaScript on JDK11 (or later) using the GraalVM compiler at [graal-js-jdk11-maven-demo](https://github.com/graalvm/graal-js-jdk11-maven-demo).
22-
The example contains a Maven project for a JavaScript benchmark (a prime number generator).
21+
There are example Maven projects for GraalVM JavaScript on JDK21 (or later) using the Graal compiler:
22+
* [Polyglot Embedding Demo](https://github.com/graalvm/polyglot-embedding-demo).
23+
Example Maven and Gradle projects for a simple JavaScript "Hello World" application.
24+
* [JS Maven Demo](https://github.com/oracle/graaljs/tree/master/graal-js/test/maven-demo)
25+
This example contains a Maven project for a JavaScript benchmark (a prime number generator).
2326
It allows a user to compare the performance of GraalVM JavaScript running with or without the GraalVM compiler as the optimizing compiler.
24-
Running with the GraalVM compiler will siginificantly improve the execution performance of any relatively large JavaScript codebase.
27+
Running with the GraalVM compiler will significantly improve the execution performance of any relatively large JavaScript codebase.
2528

26-
In essence, the example POM file activates JVMCI to install additional JIT compilers, and configures the JIT compiler to be the GraalVM compiler by providing it on `--module-path` and `--upgrade-module-path`.
27-
28-
## GraalVM JavaScript on JDK 11+
29-
The Maven example given above is the preferred way to start on JDK 11 (or newer).
30-
Working without Maven, you can provide the JAR files manually to the `java` command.
31-
Using `--upgrade-module-path` executes GraalVM JavaScript with the GraalVM compiler, guaranteeing the best performance.
32-
The GraalVM JAR files can be downloaded from [org.graalvm at Maven](https://mvnrepository.com/artifact/org.graalvm), and the ICU4J library from [org.ibm.icu at Maven](https://mvnrepository.com/artifact/com.ibm.icu/icu4j).
33-
34-
*On Linux and MacOS*
35-
```shell
36-
JARS=/path/to/JARs
37-
JDK=/path/to/JDK
38-
$JDK/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler --module-path=$JARS/graal-sdk-22.2.0.jar:$JARS/truffle-api-22.2.0.jar --upgrade-module-path=$JARS/compiler-22.2.0.jar:$JARS/compiler-management-22.2.0.jar -cp $JARS/launcher-common-22.2.0.jar:$JARS/js-launcher-22.2.0.jar:$JARS/js-22.2.0.jar:$JARS/truffle-api-22.2.0.jar:$JARS/graal-sdk-22.2.0.jar:$JARS/js-scriptengine-22.2.0.jar:$JARS/regex-22.2.0.jar:$JARS/icu4j-71.1.jar com.oracle.truffle.js.shell.JSLauncher
39-
```
40-
41-
*On Windows* - similar to the Linux/MacOS command but adapted to the syntax of Window's shell:
42-
```shell
43-
set JARs=c:\path\to\jars
44-
set JDK=c:\path\to\jdk
45-
%JDK%\bin\java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler --module-path=%JARS%\graal-sdk-22.2.0.jar;%JARS%\truffle-api-22.2.0.jar --upgrade-module-path=%JARS%\compiler-22.2.0.jar;%JARS%\compiler-management-22.2.0.jar -cp %JARS%\launcher-common-22.2.0.jar;%JARS%\js-launcher-22.2.0.jar;%JARS%\js-22.2.0.jar;%JARS%\truffle-api-22.2.0.jar;%JARS%\graal-sdk-22.2.0.jar;%JARS%\js-scriptengine-22.2.0.jar;%JARS%\regex-22.2.0.jar;%JARS\icu4j-71.1.jar com.oracle.truffle.js.shell.JSLauncher
46-
```
47-
48-
To start a Java application instead and launch GraalVM JavaScript via GraalVM SDK's `Context` (encouraged) or a `ScriptEngine` (supported, but discouraged), _launcher-common-*.jar_ and _js-launcher-*.jar_ can be omitted.
29+
In essence, the example `pom.xml` file activates JVMCI to install additional JIT compilers, and configures the JIT compiler to be the Graal Compiler by providing it on `--module-path` and `--upgrade-module-path`.
4930

5031
### ScriptEngine JSR 223
51-
GraalVM JavaScript can be started via `ScriptEngine` when _js-scriptengine.jar_ is included on the classpath.
52-
The engine registers under several different names, e.g., `Graal.js`.
53-
Note that the Nashorn engine might be available under its names as well, if available on the JDK.
32+
GraalVM JavaScript can be started via `ScriptEngine` when _js-scriptengine.jar_ is included on the module path.
33+
The engine registers under several different names, including `Graal.js`, `js`, `JavaScript`, and `javascript`.
34+
Note that the Nashorn engine might be available under its names as well, if on the module path.
5435

5536
To start GraalVM JavaScript from `ScriptEngine`, the following code can be used:
5637

5738
```java
58-
new ScriptEngineManager().getEngineByName("graal.js");
39+
new ScriptEngineManager().getEngineByName("Graal.js");
5940
```
6041

6142
To list all available engines:
6243

6344
```java
64-
List<ScriptEngineFactory> engines = (new ScriptEngineManager()).getEngineFactories();
65-
for (ScriptEngineFactory f: engines) {
66-
System.out.println(f.getLanguageName()+" "+f.getEngineName()+" "+f.getNames().toString());
45+
List<ScriptEngineFactory> engines = new ScriptEngineManager().getEngineFactories();
46+
for (ScriptEngineFactory f : engines) {
47+
System.out.println(f.getLanguageName() + " " + f.getEngineName() + " " + f.getNames());
6748
}
6849
```
6950

0 commit comments

Comments
 (0)