There a lot of JVM arguments that affect the JVM's memory usage like -Xms, -Xmx, -Xns, -XX:MaxPermSize...
OutOfMemoryError
, StackOverflowError
...)?I cannot find a good cheat sheet for them - let's create one here.
JVM arguments are flags that are passed to the Java Virtual Machine at the time the application is launched. On Linux or Mac machines, they can be provided through the JAVA_OPTS setting in the whd.conf file.
JVM Options Overview There are three types of options that you can add to your JVM, standard, non-standard and advanced options. If you apply an advanced option, you always precede the option with -XX: . Similarly if you're using a non-standard option, you'll use -X .
The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool. This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.
-Xms. The -Xms option sets the initial and minimum Java heap size. The Java heap (the “heap”) is the part of the memory where blocks of memory are allocated to objects and freed during garbage collection. Note: -Xms does not limit the total amount of memory that the JVM can use.
-Xms:
this option sets the initial and minimum Java heap size.
-Xmx:
This option sets the maximum Java heap size. The Java heap (the “heap”) is the part of the memory where blocks of memory are allocated to objects and freed during garbage collection.
-XX:PermSize:
-XX:MaxPermSize:
are used to set size for Permanent Generation. The permanent space is where are stored the class, methods, internalized strings, and similar objects used by the VM and never deallocated (hence the name).
-Xss:
sets the thread stack size. Thread stacks are memory areas allocated for each Java thread for their internal use. This is where the thread stores its local execution state.
-Xns:
sets the nursery size. the JRockit JVM uses a nursery when the generational garbage collection model is used, that is, when the dynamic garbage collector has determined that the generational garbage collection model should be used or when the static generational concurrent garbage collector ( -Xgc : gencon) has been selected. You can also use -Xns to set a static nursery size when running a dynamic garbage collector (-XgcPrio).
If you are getting java.lang.OutOfMemoryError: Java heap space
than change the value of -Xmx
and -Xms
.
if you are getting java.lang.OutOfMemoryError: PermGen space
than try increasing the - XX:MaxPermSize
value.
if you are getting java.lang.StackOverflowError
than try increasing the -Xss
value. It may be helpful by increasing the stack size but you should have a look at your code as well.
There are hundreds of JVM options available. Basically they are classified into three types:
List of few standard options: [To see complete list execute the command "java" without any option]
-client to select the "client" VM -server to select the "server" VM -cp <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> A ; separated list of directories, JAR archives, and ZIP archives to search for class files. -D<name>=<value> set a system property -version print product version and exit -showversion print product version and continue -X print help on non-standard options`
List of few non-standard X options: [To see complete list execute the command "java -X"]
-Xincgc enable incremental garbage collection -Xms<size> set initial Java heap size -Xmx<size> set maximum Java heap size -Xss<size> set java thread stack size -Xprof output cpu profiling data -Xmixed mixed mode execution (default) -Xint interpreted mode execution only
List of few non-standard XX options: [Complete list available here]
-XX:InitialHeapSize=<size> set initial Java heap size. Same as -Xms<size>. -XX:MaxHeapSize=<size> set maximum Java heap size. Same as -Xmx<size>. -XX:+PrintFlagsFinal prints all JVM options passed. -XX:+UnlockDiagnosticVMOptions opens up lot more VM options.
If you want to enhance your knowledge in JVM options, please refer this blog. The link is just part 1 out of 8. Find out and read other parts as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With