Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a default -Xmx setting for java 1.5?

Tags:

java

jvm

Out of interest - Does a default exist or is it different on each OS?

If it does, what are the defaults? Incredibly hard to find!

like image 991
JavaRocky Avatar asked Aug 06 '10 22:08

JavaRocky


People also ask

How do I change the default Java version in Eclipse?

Configure the default JRE Set it as the default in Eclipse by selecting Preferences -> Java -> Installed JREs. Add the installed JDK and select the checkbox, making it the default.


3 Answers

As Matt Solnit answered, the specifics for java 1.5 were 1GB or ¼ of physical memory, whichever is lower, for a server class machine and 64MB for other machines (from Java 5.0 Ergonomics documentation).

Unfortunately JVMs change over time and the most appropriate documentation gets more difficult to identify, so to find out the default heap (and PermGen heap) size for your specific JVM, the best way to find out is to get your JVM to tell you.


Somewhere between "1.6.0_06" and "1.6.0_21", the -XX:+PrintFlagsFinal option was added, and it appears to have first come to peoples attention at around "1.6.0_23". It provides a wealth of information about how the JVM is configured, but we will concentrate on heap and permgen sizes and limits.

Linux

On Linux you can use the command:

java -XX:+PrintFlagsFinal -version 2>&1 | grep -i -E 'heapsize|permsize|version'

Windows

Similarly on windows, you can use the command:

java -XX:+PrintFlagsFinal -version 2>&1 | findstr /I "heapsize permsize version"

Notes

  • Depending on your system, java may default to either -client or -server, so if you force your application to start with either of these, you can also do the same when you start these commands.

Examples

On my Linux system, I get:

$ java -XX:+PrintFlagsFinal -version 2>&1 | grep -i -E 'heapsize|permsize|version'
uintx AdaptivePermSizeWeight               = 20               {product}
uintx ErgoHeapSizeLimit                    = 0                {product}
uintx InitialHeapSize                     := 66328448         {product}
uintx LargePageHeapSizeThreshold           = 134217728        {product}
uintx MaxHeapSize                         := 1063256064       {product}
uintx MaxPermSize                          = 67108864         {pd product}
uintx PermSize                             = 16777216         {pd product}
java version "1.6.0_24"

and it defaults to -server, so with -client I get:

$ java -client -XX:+PrintFlagsFinal -version 2>&1 | grep -i -E 'heapsize|permsize|version'
uintx AdaptivePermSizeWeight               = 20               {product}
uintx ErgoHeapSizeLimit                    = 0                {product}
uintx InitialHeapSize                     := 16777216         {product}
uintx LargePageHeapSizeThreshold           = 134217728        {product}
uintx MaxHeapSize                         := 268435456        {product}
uintx MaxPermSize                          = 67108864         {pd product}
uintx PermSize                             = 12582912         {pd product}
java version "1.6.0_24"

On my Windows system, I get:

C:\>java -XX:+PrintFlagsFinal -version 2>&1 | findstr /I "heapsize permsize version"
uintx AdaptivePermSizeWeight               = 20               {product}
uintx ErgoHeapSizeLimit                    = 0                {product}
uintx InitialHeapSize                     := 16777216         {product}
uintx LargePageHeapSizeThreshold           = 134217728        {product}
uintx MaxHeapSize                         := 268435456        {product}
uintx MaxPermSize                          = 67108864         {pd product}
uintx PermSize                             = 12582912         {pd product}
java version "1.6.0_21"

which are the -client settings and there appears to be no -server option:

C:\>java -server -XX:+PrintFlagsFinal -version 2>&1 | findstr /I "heapsize permsize version"
C:\>java -server -XX:+PrintFlagsFinal -version
Error: no `server' JVM at `C:\jdk\jre\bin\server\jvm.dll'.

To summarise:

Parameter \ JVM             1.6.0_24                   
                            Lin/svr  Lin/cli  Windows  
InitialHeapSize               63MB     16MB     16MB   
LargePageHeapSizeThreshold   128MB    128MB    128MB   
MaxHeapSize                 1014MB    256MB    256MB   
MaxPermSize                   64MB     64MB     64MB   
PermSize                      16MB     12MB     12MB   
like image 56
Mark Booth Avatar answered Oct 09 '22 06:10

Mark Booth


You can find the details in the Java 5.0 Ergonomics documentation. Specifically:

  • For a "server class" machine (2+ processors, 2+ GB RAM), the default maximum heap size is ¼ of physical memory, up to 1Gbyte
  • For a "regular" machine, it's 64 MB.
like image 26
Matt Solnit Avatar answered Oct 09 '22 04:10

Matt Solnit


According to java documentation the default for the Sun/Oracle Windows and Solaris/Linux JVMs are 64MB. This could be different for different JVM vendors though. For example, the default -Xmx value for JRockit is the lesser of 75% of the total amount of memory or 1GB.

If you are curious about what maximum amount of memory you can use on your JVM, at runtime you can call:

System.out.println(Runtime.getRuntime().maxMemory());
like image 30
krock Avatar answered Oct 09 '22 06:10

krock