-
Bug
-
Resolution: Unresolved
-
P3
-
18, 21, 25
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
# Java version
java 23.0.2 2025-01-21
java 21.0.6 2025-01-21 LTS
# 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 for Arrays.fill() in 23.0.2 and 21.0.6 compared to 17.0.12.
REGRESSION : Last worked in version 17.0.14
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following steps shows how to reproduce the issue on a Ubuntu Linux
environment and the corresponding results.
```
# set corresponding JAVA_HOME before running the commands
17.0.12-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 0.81s user 0.01s system 100% cpu 0.822 total
java -XX:TieredStopAtLevel=4 ByteMatrix 1.47s user 0.00s system 100% cpu 1.461 total
21.0.6-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 0.82s user 0.01s system 100% cpu 0.836 total
java -XX:TieredStopAtLevel=4 ByteMatrix 4.22s user 0.01s system 100% cpu 4.214 total
23.0.2-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 0.84s user 0.01s system 100% cpu 0.844 total
java -XX:TieredStopAtLevel=4 ByteMatrix 4.17s user 0.01s system 100% cpu 4.167 total
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The performance of Arrays.fill() should be similar in newer versions.
ACTUAL -
As shown above. There is potential performance issue in C2 JIT compiler.
Besides, this issue only happens when `height` is small. If we change
`ByteMatrix bM = new ByteMatrix(90, 1);` to `ByteMatrix bM = new ByteMatrix(90,20);`,
results look like this:
```
17.0.12-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 5.97s user 0.01s system 100% cpu 5.976 total
java -XX:TieredStopAtLevel=4 ByteMatrix 2.56s user 0.01s system 100% cpu 2.563 total
21.0.6-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 6.11s user 0.02s system 100% cpu 6.126 total
java -XX:TieredStopAtLevel=4 ByteMatrix 2.22s user 0.02s system 83% cpu 2.677 total
23.0.2-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 9.54s user 0.01s system 87% cpu 10.913 total
java -XX:TieredStopAtLevel=4 ByteMatrix 2.26s user 0.02s system 99% cpu 2.290 total
```
It is interesting the program runs faster with larger values.
---------- BEGIN SOURCE ----------
# ByteMatrix.java
```java
import java.util.Arrays;
public final class ByteMatrix {
private final byte[][] bytes;
public ByteMatrix(int width, int height) {
bytes = new byte[(int) width][(int) height];
}
public void clear(byte value) {
for (byte[] aByte : bytes) {
Arrays.fill(aByte, value);
}
}
public static void main(String[] args) {
ByteMatrix bM = new ByteMatrix(90, 1);
int N = 10000000;
for (int i = 0; i < N; ++i) {
bM.clear((byte) (i % 256));
}
}
}
```
---------- END SOURCE ----------
FREQUENCY : always
# Java version
java 23.0.2 2025-01-21
java 21.0.6 2025-01-21 LTS
# 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 for Arrays.fill() in 23.0.2 and 21.0.6 compared to 17.0.12.
REGRESSION : Last worked in version 17.0.14
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following steps shows how to reproduce the issue on a Ubuntu Linux
environment and the corresponding results.
```
# set corresponding JAVA_HOME before running the commands
17.0.12-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 0.81s user 0.01s system 100% cpu 0.822 total
java -XX:TieredStopAtLevel=4 ByteMatrix 1.47s user 0.00s system 100% cpu 1.461 total
21.0.6-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 0.82s user 0.01s system 100% cpu 0.836 total
java -XX:TieredStopAtLevel=4 ByteMatrix 4.22s user 0.01s system 100% cpu 4.214 total
23.0.2-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 0.84s user 0.01s system 100% cpu 0.844 total
java -XX:TieredStopAtLevel=4 ByteMatrix 4.17s user 0.01s system 100% cpu 4.167 total
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The performance of Arrays.fill() should be similar in newer versions.
ACTUAL -
As shown above. There is potential performance issue in C2 JIT compiler.
Besides, this issue only happens when `height` is small. If we change
`ByteMatrix bM = new ByteMatrix(90, 1);` to `ByteMatrix bM = new ByteMatrix(90,20);`,
results look like this:
```
17.0.12-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 5.97s user 0.01s system 100% cpu 5.976 total
java -XX:TieredStopAtLevel=4 ByteMatrix 2.56s user 0.01s system 100% cpu 2.563 total
21.0.6-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 6.11s user 0.02s system 100% cpu 6.126 total
java -XX:TieredStopAtLevel=4 ByteMatrix 2.22s user 0.02s system 83% cpu 2.677 total
23.0.2-oracle:
java -XX:TieredStopAtLevel=1 ByteMatrix 9.54s user 0.01s system 87% cpu 10.913 total
java -XX:TieredStopAtLevel=4 ByteMatrix 2.26s user 0.02s system 99% cpu 2.290 total
```
It is interesting the program runs faster with larger values.
---------- BEGIN SOURCE ----------
# ByteMatrix.java
```java
import java.util.Arrays;
public final class ByteMatrix {
private final byte[][] bytes;
public ByteMatrix(int width, int height) {
bytes = new byte[(int) width][(int) height];
}
public void clear(byte value) {
for (byte[] aByte : bytes) {
Arrays.fill(aByte, value);
}
}
public static void main(String[] args) {
ByteMatrix bM = new ByteMatrix(90, 1);
int N = 10000000;
for (int i = 0; i < N; ++i) {
bM.clear((byte) (i % 256));
}
}
}
```
---------- END SOURCE ----------
FREQUENCY : always
- caused by
-
JDK-8275047 Optimize existing fill stubs for AVX-512 target
-
- Resolved
-