According to GC ergonomics the default maximum heap size should be "Smaller of 1/4th of the physical memory or 1GB".
Reading that I would expect a jvm on a server-class machine with 96GB ram to have a default maximum heap size of 1GB
(the smaller of 96GB/4 = 24GB or 1GB).
However when I compile and run the following code it writes out 21463
(i.e. about 21GB
).
public class Main{
public static void main(String[] args) {
System.out.println(Runtime.getRuntime().maxMemory() / 1024 / 1024);
}
}
In case it matters: java -version
produces
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
So to summarize, if I read the documentation correctly the default maximum heap size should be no larger than 1GB, but in practice it's about 1/4 of server memory. How come?