Skip to content

Commit b84ba48

Browse files
authored
Merge pull request #330 from graalvm/compiler-category
[GR-60094] Review and update Java Streams Benchmark demo; moved to compiler demos category.
2 parents 39dc222 + 4f09c59 commit b84ba48

File tree

12 files changed

+614
-70
lines changed

12 files changed

+614
-70
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
name: java-simple-stream-benchmark
1+
name: compiler/java-stream-benchmark
22
on:
33
push:
44
paths:
5-
- 'java-simple-stream-benchmark/**'
6-
- '.github/workflows/java-simple-stream-benchmark.yml'
5+
- 'compiler/java-stream-benchmark/**'
6+
- '.github/workflows/compiler-java-stream-benchmark.yml'
77
pull_request:
88
paths:
9-
- 'java-simple-stream-benchmark/**'
10-
- '.github/workflows/java-simple-stream-benchmark.yml'
9+
- 'compiler/java-stream-benchmark/**'
10+
- '.github/workflows/compiler-java-stream-benchmark.yml'
1111
schedule:
1212
- cron: "0 0 1 * *" # run every month
1313
workflow_dispatch:
1414
permissions:
1515
contents: read
1616
jobs:
1717
run:
18-
name: Run 'java-simple-stream-benchmark'
18+
name: Run 'compiler/java-stream-benchmark'
1919
runs-on: ubuntu-latest
2020
timeout-minutes: 15
2121
strategy:
2222
matrix:
23-
java-version: ['21', 'dev']
23+
java-version: ['21', '23.0.1']
2424
steps:
2525
- uses: actions/checkout@v4
2626
- uses: graalvm/setup-graalvm@v1
2727
with:
2828
java-version: ${{ matrix.java-version }}
2929
distribution: 'graalvm'
3030
github-token: ${{ secrets.GITHUB_TOKEN }}
31-
- name: Run 'java-simple-stream-benchmark'
31+
- name: Run 'compiler/java-stream-benchmark'
3232
run: |
33-
cd java-simple-stream-benchmark
34-
./build.sh
33+
cd compiler/java-stream-benchmark
3534
./run.sh

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ cd graalvm-demos
4343
<td align="left" width="30%"><a href="/native-image/list-files/">native-image/list-files</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-list-files.yml"><img alt="native-image/list-files" src="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-list-files.yml/badge.svg"/></a></td>
4444
<td align="left" width="70%">Demonstrates how to compile a CLI application into a native executable and then apply Profile-Guided Optimizations (PGO) for more performance gains<br><strong>Technologies: </strong>Native Image, PGO
4545
</tr>
46-
<tr>
47-
<td align="left" width="30%"><a href="/java-simple-stream-benchmark/">java-simple-stream-benchmark</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/java-simple-stream-benchmark.yml"><img alt="java-simple-stream-benchmark" src="https://github.com/graalvm/graalvm-demos/actions/workflows/java-simple-stream-benchmark.yml/badge.svg" /></a></td>
48-
<td align="left" width="70%">Demonstrates how the Graal compiler can achieve better performance for highly abstracted programs like those using Streams, Lambdas<br><strong>Technologies: </strong>Graal compiler, C2<br><strong>Reference: </strong><a href="https://luna.oracle.com/lab/d502417b-df66-45be-9fed-a3ac8e3f09b1/steps#task-2-run-demos-java-microbenchmark-harness-jmh">Simple Java Stream Benchmark</a></td>
49-
</tr>
5046
<tr>
5147
<td align="left" width="30%"><a href="/multithreading-demo/">multithreading-demo</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml"><img alt="streams" src="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml/badge.svg" /></a></td>
5248
<td align="left" width="70%">Demonstrates how to optimize a Java application that does synchronous and asynchronous threads execution<br><strong>Technologies: </strong>Native Image Build Reports, Native Build Tools Maven plugin <br><strong>Reference: </strong><a href="https://medium.com/graalvm/making-sense-of-native-image-contents-741a688dab4d">Making sense of Native Image contents</a></td>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Java Stream Benchmark
2+
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/).
4+
## Preparation
5+
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/).
7+
```bash
8+
sdk install java 23.0.1-graal
9+
```
10+
11+
2. Download or clone the repository and navigate into the benchmark directory:
12+
```bash
13+
git clone https://github.com/graalvm/graalvm-demos
14+
```
15+
```bash
16+
cd graalvm-demos/compiler/java-stream-benchmark
17+
```
18+
19+
## Build the Benchmark
20+
21+
Build the benchmark with Maven:
22+
```bash
23+
./mvnw package
24+
```
25+
Now you can run this benchmark with whatever `java` you have on your machine and compare the results between JVMs.
26+
27+
> **A note about the results**: The benchmark mode is the `AverageTime` in nanoseconds per operation, which means lower numbers are better.
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.
29+
Interpret them responsibly.
30+
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
39+
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/):
52+
```bash
53+
sdk install java 23.0.1-oracle
54+
```
55+
56+
2. Run this benchmark with the Graal JIT compiler enabled. For that, pass the `-XX:+UseGraalJIT` option to `java`:
57+
```bash
58+
java -XX:+UnlockExperimentalVMOptions -XX:+UseGraalJIT -jar target/benchmarks.jar
59+
```
60+
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`.
62+
63+
Learn more about the Graal JIT compiler from [its official documentation](https://www.graalvm.org/reference-manual/java/compiler/).

0 commit comments

Comments
 (0)