-
Bug
-
Resolution: Unresolved
-
P4
-
23.0.1, 24, 25
-
x86_64
-
linux_ubuntu
ADDITIONAL SYSTEM INFORMATION :
# Java version
java 23.0.1 2024-10-15
java 21.0.5 2024-10-15 LTS
java 17.0.12 2024-07-16 LTS
openjdk 11.0.25 2024-10-15
# 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 :
C2 generated code is less optimized than C1. It is about 5 times slower. This issue can be reproduce on all recent major versions as listed above. It was not reproduced in GraalVM.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
It can be reproduced by following the script below:
```bash
#!/bin/bash
rm -f *.class
class=C
javac ${class}.java
echo "Stop at level 0"
time java -XX:TieredStopAtLevel=0 ${class}
echo
echo "Stop at level 1"
time java -XX:TieredStopAtLevel=1 ${class}
echo
echo "Stop at level 2"
time java -XX:TieredStopAtLevel=2 ${class}
echo
echo "Stop at level 3"
time java -XX:TieredStopAtLevel=3 ${class}
echo
echo "Default (Stop at level 4)"
time java ${class}
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
C2 generated code should not be much slower.
ACTUAL -
the result in for JDK 21.0.5:
Stop at level 0
real 0m3.624s
user 0m3.490s
sys 0m0.139s
Stop at level 1
real 0m2.154s
user 0m2.031s
sys 0m0.128s
Stop at level 2
real 0m2.427s
user 0m2.312s
sys 0m0.120s
Stop at level 3
real 0m2.211s
user 0m2.086s
sys 0m0.132s
Default (Stop at level 4)
real 0m26.055s
user 0m25.953s
sys 0m0.124s
---------- BEGIN SOURCE ----------
# C.java
```java
public class C {
final static int N = 5000000;
static int res[] = new int[N];
public static int square(int a) {
return Math.multiplyExact(a, a);
}
public static void main(String[] args) {
for (int i = 0; i < N; i++) {
try {
res[i] = square(i);
} catch (Throwable e) {
}
}
}
}
```
---------- END SOURCE ----------
FREQUENCY : always
# Java version
java 23.0.1 2024-10-15
java 21.0.5 2024-10-15 LTS
java 17.0.12 2024-07-16 LTS
openjdk 11.0.25 2024-10-15
# 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 :
C2 generated code is less optimized than C1. It is about 5 times slower. This issue can be reproduce on all recent major versions as listed above. It was not reproduced in GraalVM.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
It can be reproduced by following the script below:
```bash
#!/bin/bash
rm -f *.class
class=C
javac ${class}.java
echo "Stop at level 0"
time java -XX:TieredStopAtLevel=0 ${class}
echo
echo "Stop at level 1"
time java -XX:TieredStopAtLevel=1 ${class}
echo
echo "Stop at level 2"
time java -XX:TieredStopAtLevel=2 ${class}
echo
echo "Stop at level 3"
time java -XX:TieredStopAtLevel=3 ${class}
echo
echo "Default (Stop at level 4)"
time java ${class}
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
C2 generated code should not be much slower.
ACTUAL -
the result in for JDK 21.0.5:
Stop at level 0
real 0m3.624s
user 0m3.490s
sys 0m0.139s
Stop at level 1
real 0m2.154s
user 0m2.031s
sys 0m0.128s
Stop at level 2
real 0m2.427s
user 0m2.312s
sys 0m0.120s
Stop at level 3
real 0m2.211s
user 0m2.086s
sys 0m0.132s
Default (Stop at level 4)
real 0m26.055s
user 0m25.953s
sys 0m0.124s
---------- BEGIN SOURCE ----------
# C.java
```java
public class C {
final static int N = 5000000;
static int res[] = new int[N];
public static int square(int a) {
return Math.multiplyExact(a, a);
}
public static void main(String[] args) {
for (int i = 0; i < N; i++) {
try {
res[i] = square(i);
} catch (Throwable e) {
}
}
}
}
```
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8346177 C2 should optimize simple increment loops
- Open