ADDITIONAL SYSTEM INFORMATION :
18.04.1-Ubuntu
A DESCRIPTION OF THE PROBLEM :
When executing the following program, JDK 11 (JDK 11.0.25) and JDK 17 (JDK 17.0.13) exhibit significant performance differences. The program repeatedly allocates a large but unused array within a loop.
Both JVMs were run with their default configurations, including the G1GC garbage collector, with escape analysis and dead code elimination enabled.
Observing the optimization logs revealed that:
In JDK 17, the JIT compiler successfully recognized that array was unused and eliminated the memory allocations.
In JDK 11, despite reaching the C2 compilation level, the optimization did not take effect, and the array continued to be allocated on each loop iteration.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Since the allocated array is never used, the JIT compiler should optimize out these allocations through escape analysis and dead code elimination, ensuring efficient execution. The execution time should be similar across JDK versions.
ACTUAL -
JDK 17:
Execution Time: ~6 seconds
Heap Memory Behavior: Minimal memory allocation, very few garbage collection (GC) activities, indicating that dead code elimination successfully removed the unnecessary allocations.
JDK 11:
Execution Time: Exceeded 8 minutes (eventually timed out).
Heap Memory Behavior: Large arrays (Object[100000]) are allocated in every loop iteration, leading to frequent GC cycles and excessive heap memory usage.
---------- BEGIN SOURCE ----------
public class B61812 {
public static void main(String[] args) {
System.out.println("Testing potential memory issue...");
for (int i = 0; i < Integer.MAX_VALUE; i++) {
Object[] array = new Object[100000]; // 分配一个大型数组,但未使用
}
System.out.println("Test completed.");
}
}
---------- END SOURCE ----------
18.04.1-Ubuntu
A DESCRIPTION OF THE PROBLEM :
When executing the following program, JDK 11 (JDK 11.0.25) and JDK 17 (JDK 17.0.13) exhibit significant performance differences. The program repeatedly allocates a large but unused array within a loop.
Both JVMs were run with their default configurations, including the G1GC garbage collector, with escape analysis and dead code elimination enabled.
Observing the optimization logs revealed that:
In JDK 17, the JIT compiler successfully recognized that array was unused and eliminated the memory allocations.
In JDK 11, despite reaching the C2 compilation level, the optimization did not take effect, and the array continued to be allocated on each loop iteration.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Since the allocated array is never used, the JIT compiler should optimize out these allocations through escape analysis and dead code elimination, ensuring efficient execution. The execution time should be similar across JDK versions.
ACTUAL -
JDK 17:
Execution Time: ~6 seconds
Heap Memory Behavior: Minimal memory allocation, very few garbage collection (GC) activities, indicating that dead code elimination successfully removed the unnecessary allocations.
JDK 11:
Execution Time: Exceeded 8 minutes (eventually timed out).
Heap Memory Behavior: Large arrays (Object[100000]) are allocated in every loop iteration, leading to frequent GC cycles and excessive heap memory usage.
---------- BEGIN SOURCE ----------
public class B61812 {
public static void main(String[] args) {
System.out.println("Testing potential memory issue...");
for (int i = 0; i < Integer.MAX_VALUE; i++) {
Object[] array = new Object[100000]; // 分配一个大型数组,但未使用
}
System.out.println("Test completed.");
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8237581 Improve allocation expansion
-
- Resolved
-