|
1 | 1 | # Java Stream Benchmark |
2 | 2 |
|
3 | | -This repository contains the code for a simple Java Stream benchmark designed to run on a JDK. |
4 | | - |
| 3 | +This repository contains the code for a simple Java Stream benchmark designed to run on the [GraalVM JDK](http://graalvm.org) and the [Oracle JDK](https://www.oracle.com/java/technologies/downloads/). |
5 | 4 | ## Preparation |
6 | 5 |
|
7 | 6 | 1. Download and install the GraalVM JDK using [SDKMAN!](https://sdkman.io/). For other installation options, visit the [Downloads page](https://www.graalvm.org/downloads/). |
@@ -29,23 +28,36 @@ Now you can run this benchmark with whatever `java` you have on your machine and |
29 | 28 | Note that the results you see can be influenced by the hardware you are running this benchmark on, the CPU load, and other factors. |
30 | 29 | Interpret them responsibly. |
31 | 30 |
|
32 | | -## Run the Benchmark |
| 31 | +### GraalVM JDK with Graal JIT |
| 32 | + |
| 33 | +Run the benchmark with the default GraalVM JIT compiler by executing the _target/benchmarks.jar_ file: |
| 34 | +```bash |
| 35 | +java -jar target/benchmarks.jar |
| 36 | +``` |
| 37 | + |
| 38 | +### GraalVM JDK with Graal JIT Deactivated |
33 | 39 |
|
34 | | -1. Run the benchmark on the **GraalVM JDK with the default JIT compiler (Graal)** by executing the _target/benchmarks.jar_ file: |
| 40 | +Now deactivate the Graal compiler and run the benchmark on the same JVM (GraalVM): |
| 41 | +```bash |
| 42 | +java -XX:-UseJVMCICompiler -jar target/benchmarks.jar |
| 43 | +``` |
| 44 | +This way, the Graal JIT compiler is not be used as the JVMCI compiler and the JVM uses its default one (C2). |
| 45 | + |
| 46 | +### Oracle JDK with Graal JIT |
| 47 | + |
| 48 | +Note that starting with Oracle JDK 23, the **Oracle GraalVM JIT compiler (Graal JIT) is now included among the JITs available as part of the Oracle JDK**. |
| 49 | +Read more in [this blog post](https://blogs.oracle.com/java/post/including-the-graal-jit-in-oracle-jdk-23). |
| 50 | + |
| 51 | +1. Switch the JVM from GraalVM (Oracle GraalVM or Community Edition) to Oracle JDK 23 or higher. You can quickly do that with using [SDKMAN!](https://sdkman.io/): |
35 | 52 | ```bash |
36 | | - java -jar target/benchmarks.jar |
| 53 | + sdk install java 23.0.1-oracle |
37 | 54 | ``` |
38 | 55 |
|
39 | | -2. Now **deactivate the Graal compiler** using the `-XX:-UseJVMCICompiler` option and run the benchmark on the same JVM (GraalVM): |
| 56 | +2. Run this benchmark with the Graal JIT compiler enabled. For that, pass the `-XX:+UseGraalJIT` option to `java`: |
40 | 57 | ```bash |
41 | | - java -XX:-UseJVMCICompiler -jar target/benchmarks.jar |
| 58 | + java -XX:+UnlockExperimentalVMOptions -XX:+UseGraalJIT -jar target/benchmarks.jar |
42 | 59 | ``` |
43 | | - This way, the Graal JIT compiler is not be used as the JVMCI compiler and the JVM uses its default one. |
44 | | - |
45 | | -## Learn More |
46 | 60 |
|
47 | | -Learn more about the Graal JIT compiler from [its official documentation](https://www.graalvm.org/reference-manual/java/compiler/). |
| 61 | +> To switch between JVMs in the same terminal window (without affecting the global setting), use the `sdk` tool. For example, to switch back to Oracle GraalVM for JDK 23, run: `sdk use java 23.0.1-graal`. |
48 | 62 |
|
49 | | -Note that starting with Oracle JDK 23, the **Oracle GraalVM JIT compiler (Graal JIT) is now included among the JITs available as part of the Oracle JDK**. |
50 | | -To run a Java application on Oracle JDK with the Graal JIT compiler, pass the `-XX:+UseGraalJIT` option to `java`. |
51 | | -Read more in [this blog post](https://blogs.oracle.com/java/post/including-the-graal-jit-in-oracle-jdk-23). |
| 63 | +Learn more about the Graal JIT compiler from [its official documentation](https://www.graalvm.org/reference-manual/java/compiler/). |
0 commit comments