What is the default maximum heap size for Sun's JVM from Java SE 6?

JavaJvmMemory Management

Java Problem Overview


What is the default maximum heap size for Sun's JVM from Java SE 6 (i.e. equivalent to setting -Xmx)?

Looks like for Java SE 5 with a server-class machine, it's

>Smaller of 1/4th of the physical memory or 1GB.

Bonus question: Looks like for IBM's JVM you can ask it

java -verbose:sizes -version

Can you similarly ask Sun's JVM?

Edit:

I used Runtime.getRuntime().maxMemory to confirm min(physical memory/4, 1G), referenced in Sun documentation.

Java Solutions


Solution 1 - Java

java 1.6.0_21 or later, or so...

$ java -XX:+PrintFlagsFinal -version 2>&1 | grep MaxHeapSize
uintx MaxHeapSize                         := 12660904960      {product}

It looks like the min(1G) has been removed.

Or on Windows using findstr

C:\>java -XX:+PrintFlagsFinal -version 2>&1 | findstr MaxHeapSize

Solution 2 - Java

One can ask with some Java code:

long maxBytes = Runtime.getRuntime().maxMemory();
System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");

See javadoc.

Solution 3 - Java

With JDK, You can also use jinfo to connect to the JVM for the <PROCESS_ID> in question and get the value for MaxHeapSize:

jinfo -flag MaxHeapSize <PROCESS_ID>

Solution 4 - Java

As of JDK6U18 following are configurations for the Heap Size.

> In the Client JVM, the default Java heap configuration has been > modified to improve the performance of today's rich client > applications. Initial and maximum heap sizes are larger and settings > related to generational garbage collection are better tuned. > >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. > This amount is at least 8 megabytes and otherwise 1/64 of physical > memory up to a physical memory size of 1 gigabyte.

Source : http://www.oracle.com/technetwork/java/javase/6u18-142093.html

Solution 5 - Java

one way is if you have a jdk installed , in bin folder there is a utility called jconsole(even visualvm can be used). Launch it and connect to the relevant java process and you can see what are the heap size settings set and many other details

When running headless or cli only, jConsole can be used over lan, if you specify a port to connect on when starting the service in question.

Solution 6 - Java

To answer this question it's critical whether the Java VM is in CLIENT or SERVER mode. You can specify "-client" or "-server" options. Otherwise java uses internal rules; basically win32 is always client and Linux is always server, but see the table here:

http://docs.oracle.com/javase/6/docs/technotes/guides/vm/server-class.html

Sun/Oracle jre6u18 doc says re client: the VM gets 1/2 of physical memory if machine has <= 192MB; 1/4 of memory if machine has <= 1Gb; max 256Mb. In my test on a 32bit WindowsXP system with 2Gb phys mem, Java allocated 256Mb, which agrees with the doc.

Sun/Oracle jre6u18 doc says re server: same as client, then adds confusing language: for 32bit JVM the default max is 1Gb, and for 64 bit JVM the default is 32Gb. In my test on a 64bit linux machine with 8Gb physical, Java allocates 2Gb, which is 1/4 of physical; on a 64bit linux machine with 128Gb physical Java allocates 32Gb, again 1/4 of physical.

Thanks to this SO post for guiding me:

https://stackoverflow.com/questions/7992916/definition-of-server-class-machine-changed-recently

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondfrankowView Question on Stackoverflow
Solution 1 - JavaqmcView Answer on Stackoverflow
Solution 2 - JavadfrankowView Answer on Stackoverflow
Solution 3 - Javauser1754962View Answer on Stackoverflow
Solution 4 - JavaJabirView Answer on Stackoverflow
Solution 5 - JavaInv3r53View Answer on Stackoverflow
Solution 6 - JavachrisinmtownView Answer on Stackoverflow