Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which arguments stand for what in JVM memory options?

There a lot of JVM arguments that affect the JVM's memory usage like -Xms, -Xmx, -Xns, -XX:MaxPermSize...

  • What do they do?
  • Are there any more?
  • Which one do I have to increase when I get what error (e.g. OutOfMemoryError, StackOverflowError...)?

I cannot find a good cheat sheet for them - let's create one here.

like image 805
Francois Bourgeois Avatar asked Nov 08 '13 16:11

Francois Bourgeois


People also ask

What does JVM arguments mean?

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.

What are the JVM options?

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 .

What is Xms and XMX in JVM?

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.

What is Xms in JVM arguments?

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


2 Answers

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

like image 70
Trying Avatar answered Oct 17 '22 11:10

Trying


There are hundreds of JVM options available. Basically they are classified into three types:

  1. Standard Options,
  2. Non-standard X options,
  3. Non-standard XX options,

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.

like image 21
Karthik Bose Avatar answered Oct 17 '22 12:10

Karthik Bose