Open In App

How is the default max Java Heap size determined?

Improve
Improve
Like Article
Like
Save
Share
Report

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.

Example:

If a 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. 

In the server JVM:

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.

The system configuration setting influence the default value i.e. machine’s physical memory and the version of Java.

The default max Java heap size is determined by using the following commands:

On windows, we can use either of the following commands:

  • java -XX:+PrintFlagsFinal -version | findstr HeapSize
  •  java -XX:+PrintFlagsFinal -version | findstr /i “HeapSize PermSize ThreadStackSize”
Max heap size Windows

Max heap size Windows

The following commands can be used On Linux/Unix:

  • java -XX:+PrintFlagsFinal -version | grep HeapSize
  • java -XX:+PrintFlagsFinal -version | grep -iE ‘HeapSize|PermSize|ThreadStackSize’
Max Heap size Linux

Max Heap size Linux

Related Articles:


Last Updated : 18 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads