JDK-8349401 : Performance regression in JDK 21 for double arithmetic operations
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 21.0.6,24,25
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2025-02-04
  • Updated: 2025-03-18
  • Resolved: 2025-03-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25Resolved
Related Reports
Causes :  
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
# Java version
java 21.0.6 2025-01-21 LTS
Java(TM) SE Runtime Environment (build 21.0.6+8-LTS-188)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.6+8-LTS-188, mixed mode, sharing)

# Operating system details
$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

A DESCRIPTION OF THE PROBLEM :
Performance regression in JDK 21 for double arithmetic operations
compared to JDK 17. The issue seems to be fixed in JDK 23, but JDK 23
is still slower than JDK 17. Similar issue in Graal: https://github.com/oracle/graal/issues/10609

REGRESSION : Last worked in version 17.0.14

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The issue can be reproduced by running JMH code below with different JDK versions

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
similar performance for recent JDK versions
ACTUAL -
JDK 17.0.12, Java HotSpot(TM) 64-Bit Server VM, 17.0.12+8-LTS-286:
Benchmark  Mode  Cnt  Score   Error  Units
Sum.add    avgt   15  9.661 ± 0.081  ns/op

JDK 21.0.6, Java HotSpot(TM) 64-Bit Server VM, 21.0.6+8-LTS-188:
Benchmark  Mode  Cnt    Score   Error  Units
Sum.add    avgt   15  102.754 ± 0.862  ns/op

JDK 23.0.2, Java HotSpot(TM) 64-Bit Server VM, 23.0.2+7-58:
Benchmark  Mode  Cnt   Score   Error  Units
Sum.add    avgt   15  13.110 ± 0.102  ns/op


---------- BEGIN SOURCE ----------
# Sum.java
```java
package org.sample;

import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;

@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(3)
public class Sum {
    private static double sum = 1.0;
    private static double comp = 0.1;

    static double twoSumLow(double a, double b, double sum) {
        final double bVirtual = sum - a;
        return (a - (sum - bVirtual)) + (b - bVirtual);
    }

    @Benchmark
    public void add() {
        final double newSum = (sum % comp);
        comp += twoSumLow(0.1, comp, newSum);
        sum += comp;
    }
}
```
---------- END SOURCE ----------
Comments
Fix has been backported to Oracle JDK 21.0.8
18-03-2025

This is basically a duplicate of JDK-8312188 which was closed as a duplicate of JDK-8314056 which is fixed in JDK 22. So what we need is a backport of JDK-8314056 to 21. Which by the way was handled as a compiler issue not runtime. Closing as duplicate.
14-03-2025

ILW = MMM = P3
11-02-2025

I can also reproduce this with -Xint, supporting the assumption that this is a regression of JDK-8302191. Moving to hotspot/runtime.
10-02-2025

Regression is introduced in jdk21 b16 onwards. jdk21 b15 == real 0m0.830s user 0m0.802s sys 0m0.041s == jdk21 b16 == real 0m1.288s user 0m1.260s sys 0m0.045s I am suspecting, it is most likely JDK-8302191
07-02-2025

I tried to replicate this issue on my Zen 3 linux-x64 machine but both 17 and 21 had the same level of performance, while 22 and 23 is ~30% faster on my machine. Looking at the assembly it's basically unchanged between the versions, but the hottest region is the drem operation. Maybe JDK-8302191 (released in 21) and JDK-8308966 (released in 22) are related?
06-02-2025