Tuesday 24 April 2018

Reporting Java system properties default values

In many cases we might want to check what are the default value for a certain Java property.
This helps in tuning Java applications and also in predicting application behavior when based on those default values.

Java sets many properties by default unless you chose to provide other values.
To report all Java properties for a given JVM we use the below form:

java -XX:+PrintFlagsFinal -version

This will list all the applicable properties to that JVM.
To find a certain property on Windows, we can use the findstr command which works like grep:

C:\Users\sherif>java -XX:+PrintFlagsFinal -version|findstr /I heapsize
    uintx ErgoHeapSizeLimit                         = 0
          {product}
    uintx HeapSizePerGCThread                       = 87241520
          {product}
    uintx InitialHeapSize                          := 100663296
          {product}
    uintx LargePageHeapSizeThreshold                = 134217728
          {product}
    uintx MaxHeapSize                              := 1591738368
          {product}
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

C:\Users\sherif>


This shows that the default max heap size is set to be 1.5GB by default for the 64-bit JVM if we didn't specify a heap size.

Another useful option for Java is the showSettings:properties option, this will show system related settings like the OS type, CPU architecture, and boot class path.
The form looks like this:

java -XshowSettings:properties -version

The output is printed on Windows standard error thus normal piping wouldn't work with it.

No comments:

Post a Comment