-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
17.0.6
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
java -version
java version "17.0.6" 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)
OS: Win11
A DESCRIPTION OF THE PROBLEM :
When using ZGC, I have noticed that it can throw an OOM error, whereas G1 and Parallel do not seem to have this issue. May I know why this issue is occurring, please? I will provide the test program and reproduce method in the following text.
Program file: Test.java
public class Test {
public static void main(String[] var0) {
Object[][][] arr = new Object[1024][1024][128];
throw new NullPointerException("NPE!");
}
}
Command: java -Xms1024m -Xmx1024m -XX:+UseZGC Test
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at Test.main(Test.java:5)
I attempted to calculate the memory space occupied by this array. Given that an Object takes up 8 bytes and the length of this array is 1024*1024*128, it requires at least 1024*1024*1024Byte=1024MB of space. Since JVM needs to occupy some memory space at runtime, the program needs more memory during its execution. However, I limited the JVM's memory size to 1024MB using the parameter -Xms1024m -Xmx1024m. Therefore, encountering OOM when allocating the array is normal. I'm curious as to why G1 and Parallel did not throw an OOM. Maybe there's something wrong with the G1 and Parallel.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Step1. Create Test.java
public class Test {
public static void main(String[] var0) {
Object[][][] arr = new Object[1024][1024][128];
throw new NullPointerException("NPE!");
}
}
Step2. compile and run it with JDK17
Run: java -Xms1024m -Xmx1024m -XX:+UseZGC Test
Result: OOM
Run: java -Xms1024m -Xmx1024m -XX:+UseG1GC Test
Result: NPE
ACTUAL -
Exception in thread "main" java.lang.NullPointerException: NPE!
at Test.main(Test.java:6)
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] var0) {
Object[][][] arr = new Object[1024][1024][128];
throw new NullPointerException("NPE!");
}
}
---------- END SOURCE ----------
java -version
java version "17.0.6" 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)
OS: Win11
A DESCRIPTION OF THE PROBLEM :
When using ZGC, I have noticed that it can throw an OOM error, whereas G1 and Parallel do not seem to have this issue. May I know why this issue is occurring, please? I will provide the test program and reproduce method in the following text.
Program file: Test.java
public class Test {
public static void main(String[] var0) {
Object[][][] arr = new Object[1024][1024][128];
throw new NullPointerException("NPE!");
}
}
Command: java -Xms1024m -Xmx1024m -XX:+UseZGC Test
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at Test.main(Test.java:5)
I attempted to calculate the memory space occupied by this array. Given that an Object takes up 8 bytes and the length of this array is 1024*1024*128, it requires at least 1024*1024*1024Byte=1024MB of space. Since JVM needs to occupy some memory space at runtime, the program needs more memory during its execution. However, I limited the JVM's memory size to 1024MB using the parameter -Xms1024m -Xmx1024m. Therefore, encountering OOM when allocating the array is normal. I'm curious as to why G1 and Parallel did not throw an OOM. Maybe there's something wrong with the G1 and Parallel.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Step1. Create Test.java
public class Test {
public static void main(String[] var0) {
Object[][][] arr = new Object[1024][1024][128];
throw new NullPointerException("NPE!");
}
}
Step2. compile and run it with JDK17
Run: java -Xms1024m -Xmx1024m -XX:+UseZGC Test
Result: OOM
Run: java -Xms1024m -Xmx1024m -XX:+UseG1GC Test
Result: NPE
ACTUAL -
Exception in thread "main" java.lang.NullPointerException: NPE!
at Test.main(Test.java:6)
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] var0) {
Object[][][] arr = new Object[1024][1024][128];
throw new NullPointerException("NPE!");
}
}
---------- END SOURCE ----------