Which arguments stand for what in JVM memory options?
Asked Answered
C

4

26

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.

Craiova answered 8/11, 2013 at 16:45 Comment(2)
You can start looking at oracle.com/technetwork/java/javase/tech/… and docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/…. Then, do some research to get results like avricot.com/blog/?post/2010/05/03/…Benildas
Some more useful links at https://mcmap.net/q/36746/-print-all-jvm-flagsLobell
H
53

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

Hulk answered 8/11, 2013 at 16:57 Comment(1)
The Permgen space can be deallocated if you no longer have a reference to classes that have been loaded previously. Enabling PermgenSweep is a VM option. As a clarification, the nursery is used for short-lived object storage.Vlaminck
D
12

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.

Demetria answered 13/11, 2014 at 12:57 Comment(0)
V
1

-Xss: Stack size.

Used to set the size of your stack. Stack values only exist within the scope of the function they are created in. Once the function returns, they are discarded.

The easiest way to run out of stack space is to recurse too deep.

-Xms, -Xmx: Min and max heap size.

Used to set the size of your heap. The heap is where you allocate objects. Objects persist until they are garbage collected.

The easiest way to run out of heap space is to allocate something massive.

-XX:MaxPermSize: Permanent generation.

The permanent generation is special because it holds data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation.

You usually run out of permgen space if you are somehow leaking references to classes you load dynamically. This plagues some web containers in particular.

Vlaminck answered 8/11, 2013 at 16:56 Comment(1)
Xms is for min heap size not stack size.Hulk
P
1

Read JVM options explained. Here're excerpts from it:

  • If you are frequently recieving java.lang.OutOfMemoryError: Java heap space errors you should increase -Xmx value.
  • Normally -XX:PermSize and -XX:MaxPermSize do not need to be adjusted but if you are seeing java.lang.OutOfMemoryError: PermGen space events often you can increase these values.
  • -XX:MaxJavaStackTraceDepth - This specifies how many entries a stack trace for a thrown error or exception can have before a StackOverflowError is thrown. So if you are dealing with huge stack traces you can use this option to increase the allowed entriers before overflow.
Prescience answered 27/10, 2016 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.