JDK-8350494 : Missed dead code elimination in C2
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 23.0.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2025-02-18
  • Updated: 2025-02-24
  • Resolved: 2025-02-24
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
# Java version
java 23.0.2 2025-01-21
Java(TM) SE Runtime Environment (build 23.0.2+7-58)
Java HotSpot(TM) 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)

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)

# OS
Ubuntu 20.04.6 LTS

A DESCRIPTION OF THE PROBLEM :
Missed dead code elimination for Math.log leading to long execution time

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the code provided below and run it with different JVMs/options

ACTUAL -
```
# JDK 23.0.2 C1
time java -XX:TieredStopAtLevel=1 Test  3.93s user 0.02s system 100% cpu 3.942 total
# JDK 23.0.2 C2
time java Test  64.03s user 0.03s system 100% cpu 1:04.04 total
# GraalVM 23.0.2
time java Test  0.11s user 0.05s system 188% cpu 0.084 total
```

---------- BEGIN SOURCE ----------
# Test.java
```java
public class Test { 
    public static int m() {
        double a = -4.0;
        double b = 0.79;
        for (int i = 0; i < 100000; i++) {
            double d = Math.log(b);
            if (d != a) {
            }
        }
        return 1;
    }

    public static void main(String[] strArr) {
        int blackhole = 0;
        for (int i = 0; i < 100000; i++) {
            blackhole += m();
        }
        System.out.println("blackhole = " + blackhole);
    }
}
```
---------- END SOURCE ----------


Comments
This is a known limitation of C2 and tracked by JDK-8347901.
24-02-2025

Issue confirmed on macos 15.3 as well #java -version java version "23.0.2" 2025-01-21 Java(TM) SE Runtime Environment (build 23.0.2+7-58) Java HotSpot(TM) 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing) # time java -XX:TieredStopAtLevel=1 Test 3.17s user 0.08s system 96% cpu 3.382 total # time java Test 50.51s user 0.40s system 97% cpu 52.022 total
21-02-2025