Organizational Research By

Surprising Reserch Topic

how is the default java heap size determined


how is the default java heap size determined  using -'java,heap'

If I omit the -Xmxn option from the java command line a default value is used. According to
java documentation "the default value is chosen at runtime based on system configuration".

What system configuration settings influence the default value?
    

asked Oct 19, 2015 by abhimca2006
0 votes
2 views



Related Hot Questions

5 Answers

0 votes

You can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

answered Oct 19, 2015 by mtabakade
0 votes

According to Garbage Collector Ergonomics [Oracle]:

initial heap size:

Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before J2SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option.

maximum heap size:

Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.

UPDATE:

As pointed out by Tom Anderson in his comment, the above is for server-class machines. From Ergonomics in the 5.0 JavaTM Virtual Machine:

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with

  • 2 or more physical processors
  • 2 or more Gbytes of physical memory

with the exception of 32 bit platforms running a version of the Windows operating system. On all other platforms the default values are the same as the default values for version 1.4.2.

In the J2SE platform version 1.4.2 by default the following selections were made

  • initial heap size of 4 Mbyte
  • maximum heap size of 64 Mbyte
answered Oct 19, 2015 by amit.gupta
0 votes

This is changed with java 6 update 18. http://www.oracle.com/technetwork/java/javase/6u18-142093.html

Assuming that we have more than 1gb of physical memory(quite common these days), it's always 1/4th of your physical memory.

answered Oct 19, 2015 by rajesh
0 votes

Ernesto is right. According to the link he posted [1]:

"Updated Client JVM heap configuration In the Client JVM... The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte.

For example, if your machine has 128 megabytes of physical memory, then the maximum heap size is 64 megabytes, and greater than or equal to 1 gigabyte of physical memory results in a maximum heap size of 256 megabytes.

The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, termed the initial heap size, is allocated during JVM initialization.

...

Server JVM heap configuration ergonomics are now the same as the Client, except that the default maximum heap size for 32-bit JVMs is 1 gigabyte, corresponding to a physical memory size of 4 gigabytes, and for 64-bit JVMs is 32 gigabytes, corresponding to a physical memory size of 128 gigabytes."

[1] http://www.oracle.com/technetwork/java/javase/6u18-142093.html

answered Oct 19, 2015 by deepak07.s
0 votes

for IBM jvm the command is the following:

java -verbose:sizes -version

For more information about IBM SDK for Java 8 - http://www-01.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.lnx.80.doc/diag/appendixes/defaults.html?lang=en

answered Oct 19, 2015 by tseetha

...