Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the -Xms and -Xmx parameters when starting JVM?

Please explain the use of the Xms and Xmx parameters in JVMs. What are the default values for them?

like image 480
Pankaj Avatar asked Feb 07 '13 23:02

Pankaj


People also ask

What are the JVM parameters?

JVM has four types of GC implementations: Serial Garbage Collector. Parallel Garbage Collector. CMS Garbage Collector.

Where are JVM parameters set?

You can change the parameters passed to the JVM in the Arguments tab in the VM Arguments box. That configuration can then be used as the default when running the project.

How do you find JVM parameters?

Double click [your application] (pid [n]). On the right side, there will be inspection contents in a tab for the application. In the middle of the Overview tab, you will see the JVM arguments for the application.

How do you launch a JVM?

The way to start a jvm is by invoking the main, either by invoking a jar using java -jar MyJar or by simply running main class from an IDE. Yes, Multiple jvm instances can be run on a single machine, they all will have their own memory allocated. There will be that many jvms as many main programs you run.


2 Answers

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. For example, starting a JVM like below will start it with 256 MB of memory and will allow the process to use up to 2048 MB of memory:

java -Xms256m -Xmx2048m 

The memory flag can also be specified in different sizes, such as kilobytes, megabytes, and so on.

-Xmx1024k -Xmx512m -Xmx8g 

The Xms flag has no default value, and Xmx typically has a default value of 256 MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError.

When using these settings, keep in mind that these settings are for the JVM's heap, and that the JVM can and will use more memory than just the size allocated to the heap. From Oracle's documentation:

Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.

like image 127
hexacyanide Avatar answered Sep 23 '22 02:09

hexacyanide


Run the command java -X and you will get a list of all -X options:

C:\Users\Admin>java -X -Xmixed           mixed mode execution (default) -Xint             interpreted mode execution only -Xbootclasspath:<directories and zip/jar files separated by ;>                       set search path for bootstrap classes and resources -Xbootclasspath/a:<directories and zip/jar files separated by ;>                       append to end of bootstrap class path -Xbootclasspath/p:<directories and zip/jar files separated by ;>                       prepend in front of bootstrap class path -Xdiag            show additional diagnostic messages -Xnoclassgc       disable class garbage collection -Xincgc           enable incremental garbage collection -Xloggc:<file>    log GC status to a file with time stamps -Xbatch           disable background compilation -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 -Xfuture          enable strictest checks, anticipating future default -Xrs              reduce use of OS signals by Java/VM (see documentation) -Xcheck:jni       perform additional checks for JNI functions -Xshare:off       do not attempt to use shared class data -Xshare:auto      use shared class data if possible (default) -Xshare:on        require using shared class data, otherwise fail. -XshowSettings    show all settings and continue -XshowSettings:all         show all settings and continue -XshowSettings:vm          show all vm related settings and continue -XshowSettings:properties  show all property settings and continue -XshowSettings:locale      show all locale related settings and continue 

The -X options are non-standard and subject to change without notice.

I hope this will help you understand Xms, Xmx as well as many other things that matters the most. :)

like image 44
Rupesh Yadav Avatar answered Sep 19 '22 02:09

Rupesh Yadav