-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Describe the issue
Potential missed optimization in GraalVM C2 JIT compiler
Steps to reproduce the issue
Here is the program:
public final class Sum {
private double sum;
private double comp;
public Sum(final double initialValue) {
sum = initialValue;
comp = 0.1;
}
static double twoSumLow(double a, double b, double sum) {
final double bVirtual = sum - a;
return (a - (sum - bVirtual)) + (b - bVirtual);
}
public void add(final double t) {
final double newSum = (sum % comp);
comp += twoSumLow(t, comp, newSum);
sum += comp;
}
public static void main(String[] args) {
int N = 50000000;
Sum s = new Sum(1.0);
for (int i = 0; i < N; ++i) {
s.add(0.1);
}
// System.out.println(s.sum);
}
}
Run the program with C1 and C2 respectively:
# Set $JAVA_HOME to corresponding JDKs before running
javac Sum.java
time java -XX:TieredStopAtLevel=1 Sum
time java -XX:TieredStopAtLevel=4 Sum
Below is the result I got on my machine (the exact numbers vary depending on the machine, but the performance difference should be noticeable, try increasing N if not):
Oracle 21:
java -XX:TieredStopAtLevel=1 Sum 5.52s user 0.02s system 100% cpu 5.535 total
java -XX:TieredStopAtLevel=4 Sum 5.58s user 0.01s system 100% cpu 5.573 total
Oracle 23:
java -XX:TieredStopAtLevel=1 Sum 0.68s user 0.01s system 100% cpu 0.692 total
java -XX:TieredStopAtLevel=4 Sum 0.72s user 0.02s system 100% cpu 0.737 total
Graal 25:
java -XX:TieredStopAtLevel=1 Sum 0.71s user 0.03s system 102% cpu 0.714 total
java -XX:TieredStopAtLevel=4 Sum 5.82s user 0.02s system 101% cpu 5.774 total
It looks like Oracle 23 (HotSpot JIT compiler) adds some new optimization(s), making the program run much faster. Such optimization(s) are not present in GraalVM yet.
Describe GraalVM and your environment:
- GraalVM version: CE 25.0.0-dev-20250122_1329, 23.0.1+11.1
- JDK major version: 25, 23
- OS: Ubuntu 20.04
- Architecture: AMD64