Understand ParallelGC log
Modern commercial JVMs all adopt generational garbage collection. The collector will divide heap memory into distinct areas(aka generation). And then different generation can use different algorithm. For example, the coping collection is used in new generation, whereas the old generation uses mark, sweep and compact in ParallelGC.
ParallelGC is the default GC collector in jdk8. Its full name is parallel scavenge. Parallel indicates that it can use multiple threads as an opposite to old serial collector. The default thread number is platform dependent. So are the heap size related parameters.
Code
Run below code with command:
java -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xms20M -Xmx20M -Xmn10M GC
public class GC {
public static void main(String ...args) {
int _1M = 1024*1024;
byte []alloc1 = new byte[_1M * 2];
byte []alloc2 = new byte[_1M * 2];
byte []alloc3 = new byte[_1M * 2];
byte []alloc4 = new byte[_1M * 4];
System.gc();
}
}
Above command sets the heap size to 20M and the new generation to 10M. The default survivor ratio is 8. So the eden space is 8M and other two survivors are both 1M.