Simple program allocating 1 multi-dimentional array causes continous GCs (all garbage collectors) if heap is big enough to to create outermost array. It appears that GC is attempted many times. With product build and 6G heap, allocation takes 3 minutes. With fastdebug build, allocation takes more than 20 minutes.
Allocating 1-dimensional array which occupies same memory is fast.
public class D {
public static void main(String[] args) {
int a1 = 1;
long maxMemory = Runtime.getRuntime().maxMemory();
int s = (int) (Math.sqrt(Math.sqrt((double) maxMemory)));
System.out.println("s: " + s);
int[][][][] a2;
try {
a2 = new int [s][s][s][s];
a2 [s-1][s-1][s-1][s-1] = a1;
if ( a2 [s-1][s-1][s-1][s-1] != 1 ) {
throw new RuntimeException("Error: " + a2 [s-1][s-1][s-1][s-1]);
}
} catch (OutOfMemoryError e) {
System.out.println("Passed.");
}
}
}
Stack trace where the work happens:
ffffffff7edda5f4 lwp_cond_wait (10010d348, 10010d330, 0, 0)
ffffffff7e4e0ef8 void os::PlatformEvent::park() (10010d300, 99b88, 99800, 10010d330, ffffffff7e89c000, 10010d320) + 100
ffffffff7e4a61a8 void Monitor::ILock(Thread*) (10010abb0, 10010c000, ffffffff7e8ffb08, 0, 0, 1) + 120
ffffffff7e4a6fc4 void Monitor::lock_without_safepoint_check() (10010abb0, 7b000, ffffffff7f5, ffffffff7e89c000, 3f50a4, 10010c000) + 6c
ffffffff7de42698 void SafepointSynchronize::block(JavaThread*) (10010c000, 79258, ffffffff7e915258, 7, 0, ffffffff7e915258) + 1a0
ffffffff7e4a75a0 bool Monitor::wait(bool,long,bool) (10010acd0, 10010c000, 0, 7af98, ffffffff7cb00000, c00) + 198
ffffffff7de71d38 void VMThread::execute(VM_Operation*) (ffffffff7beff2f8, 93800, 10010c000, 1, 0, ffffffff7e89c000) + 1c0
ffffffff7e0e15dc HeapWord*GenCollectorPolicy::mem_allocate_work(unsigned long,bool,bool*) (100110000, 1dcd6502, 0, ffffffff7beff2f8, ffffffff7e89c000, ffffffff7e6a8d3c) + 384
ffffffff7de88e24 objArrayOopDesc*objArrayKlass::allocate(int,Thread*) (100239580, 10010c000, 82969e, 3b9aca00, 48, 1dcd6502) + 2ac
ffffffff7e4b9c4c oopDesc*objArrayKlass::multi_allocate(int,int*,Thread*) (ffffffff702d4ee8, 3, ffffffff7beff768, 100239578, 10010c000, 60058f58) + 84
ffffffff7e4b9d20 oopDesc*objArrayKlass::multi_allocate(int,int*,Thread*) (100239570, ffffffff7e915820, ffffffff7e4b9bc8, 100239560, 10010c000, ffffffff7e916188) + 158
ffffffff7e4b9d20 oopDesc*objArrayKlass::multi_allocate(int,int*,Thread*) (100239558, ffffffff7e915820, ffffffff7e4b9bc8, 100239548, 10010c000, ffffffff7e916188) + 158
ffffffff7de62bc8 void InterpreterRuntime::multianewarray(JavaThread*,int*) (10010cae0, 5, 10010c000, ffffffff7e4b9bc8, ffffffffffffffd8, ffffffff7beff8f8) + 410
ffffffff78019698 * Interpreter
ffffffff7800024c * StubRoutines (1)
ffffffff7dddbbfc void JavaCalls::call_helper(JavaValue*,methodHandle*,JavaCallArguments*,Thread*) (ffffffff7beffe28, 10010c000, ffffffff7beffd78, 1, ffffffff7e91ea80, ffffffff78
00be40) + 26c
ffffffff7dde852c void JavaCalls::call(JavaValue*,methodHandle,JavaCallArguments*,Thread*) (ffffffff7beffe28, 10010cac8, ffffffff7beffd78, 10010c000, ac0400, ab3b00) + 3c
ffffffff7de91484 jni_CallStaticVoidMethod (10010c1d0, ffffffff7beffd58, 100101c90, 10010c000, 13d, 10010ca98) + 400
ffffffff7f2020a0 JavaMain (10010d7c0, ffffffff7f319e1c, ffffffff7ddd4a90, 100101350, 10010d7b0, ffffffff7e90aac0) + 7a0
ffffffff7edd64b8 _lwp_start (0, 0, 0, 0, 0, 0)
Allocating 1-dimensional array which occupies same memory is fast.
public class D {
public static void main(String[] args) {
int a1 = 1;
long maxMemory = Runtime.getRuntime().maxMemory();
int s = (int) (Math.sqrt(Math.sqrt((double) maxMemory)));
System.out.println("s: " + s);
int[][][][] a2;
try {
a2 = new int [s][s][s][s];
a2 [s-1][s-1][s-1][s-1] = a1;
if ( a2 [s-1][s-1][s-1][s-1] != 1 ) {
throw new RuntimeException("Error: " + a2 [s-1][s-1][s-1][s-1]);
}
} catch (OutOfMemoryError e) {
System.out.println("Passed.");
}
}
}
Stack trace where the work happens:
ffffffff7edda5f4 lwp_cond_wait (10010d348, 10010d330, 0, 0)
ffffffff7e4e0ef8 void os::PlatformEvent::park() (10010d300, 99b88, 99800, 10010d330, ffffffff7e89c000, 10010d320) + 100
ffffffff7e4a61a8 void Monitor::ILock(Thread*) (10010abb0, 10010c000, ffffffff7e8ffb08, 0, 0, 1) + 120
ffffffff7e4a6fc4 void Monitor::lock_without_safepoint_check() (10010abb0, 7b000, ffffffff7f5, ffffffff7e89c000, 3f50a4, 10010c000) + 6c
ffffffff7de42698 void SafepointSynchronize::block(JavaThread*) (10010c000, 79258, ffffffff7e915258, 7, 0, ffffffff7e915258) + 1a0
ffffffff7e4a75a0 bool Monitor::wait(bool,long,bool) (10010acd0, 10010c000, 0, 7af98, ffffffff7cb00000, c00) + 198
ffffffff7de71d38 void VMThread::execute(VM_Operation*) (ffffffff7beff2f8, 93800, 10010c000, 1, 0, ffffffff7e89c000) + 1c0
ffffffff7e0e15dc HeapWord*GenCollectorPolicy::mem_allocate_work(unsigned long,bool,bool*) (100110000, 1dcd6502, 0, ffffffff7beff2f8, ffffffff7e89c000, ffffffff7e6a8d3c) + 384
ffffffff7de88e24 objArrayOopDesc*objArrayKlass::allocate(int,Thread*) (100239580, 10010c000, 82969e, 3b9aca00, 48, 1dcd6502) + 2ac
ffffffff7e4b9c4c oopDesc*objArrayKlass::multi_allocate(int,int*,Thread*) (ffffffff702d4ee8, 3, ffffffff7beff768, 100239578, 10010c000, 60058f58) + 84
ffffffff7e4b9d20 oopDesc*objArrayKlass::multi_allocate(int,int*,Thread*) (100239570, ffffffff7e915820, ffffffff7e4b9bc8, 100239560, 10010c000, ffffffff7e916188) + 158
ffffffff7e4b9d20 oopDesc*objArrayKlass::multi_allocate(int,int*,Thread*) (100239558, ffffffff7e915820, ffffffff7e4b9bc8, 100239548, 10010c000, ffffffff7e916188) + 158
ffffffff7de62bc8 void InterpreterRuntime::multianewarray(JavaThread*,int*) (10010cae0, 5, 10010c000, ffffffff7e4b9bc8, ffffffffffffffd8, ffffffff7beff8f8) + 410
ffffffff78019698 * Interpreter
ffffffff7800024c * StubRoutines (1)
ffffffff7dddbbfc void JavaCalls::call_helper(JavaValue*,methodHandle*,JavaCallArguments*,Thread*) (ffffffff7beffe28, 10010c000, ffffffff7beffd78, 1, ffffffff7e91ea80, ffffffff78
00be40) + 26c
ffffffff7dde852c void JavaCalls::call(JavaValue*,methodHandle,JavaCallArguments*,Thread*) (ffffffff7beffe28, 10010cac8, ffffffff7beffd78, 10010c000, ac0400, ab3b00) + 3c
ffffffff7de91484 jni_CallStaticVoidMethod (10010c1d0, ffffffff7beffd58, 100101c90, 10010c000, 13d, 10010ca98) + 400
ffffffff7f2020a0 JavaMain (10010d7c0, ffffffff7f319e1c, ffffffff7ddd4a90, 100101350, 10010d7b0, ffffffff7e90aac0) + 7a0
ffffffff7edd64b8 _lwp_start (0, 0, 0, 0, 0, 0)