Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+13 votes
177 views
in Java by (1.4k points)

What is XMS and XMX in Java Virtual Machine? Initially, what is it’s value?

9 Answers

+20 votes
by (13.2k points)

XMS stands for eXtended Memory Specification.
It is a parameter in JVM which is used to set the minimum or initial Heap Size.
XMX  is a parameter in JVM which is used to set the maximum Heap Size.
You can specify it in your IDE.
Like -
-Xmx500m (will set maximum Heap size = 500m)
-Xms500m   (will set minimum Heap Size = 500m)

For minimum garbage collection,
minimum heap size (XMS) = maximum heap size (XMX)
 

Default parameters of XMS and XMX in JVM
Intellipaat-community
by (19.9k points)
Thank you for this easy to understand explanation.
by (47.2k points)
Run this code to see all the options:

java -X
+5 votes
by (32.3k points)
edited by

Xms and Xmx are used to control the amount of memory that your Java program uses.

Are you interested in learning Java from basics! Refer to this video on Java provided by Intellipaat:

In order to control the RAM use of the application, you take help of these Java command-line parameters:

  • To specify the maximum heap size use -Xmx

  • To specify the initial Java heap size use -Xms

  • To set the Java thread stack size use -Xss

To specify the amount of memory the JVM should use do:

-Xms64m or -Xms64M

-Xmx1g or -Xmx1G

For more details check this blog.

Default parameters of XMS and XMX in JVM
Intellipaat-community
by (29.5k points)
Thank you for the explanation and blog link , helped  me understand
by (106k points)
Understood the concept, thanks
+3 votes
by (44.4k points)
The above answers have provided a solution for what is XMS and XMX, but not what is the default value or how to use it in various scenarios. I have provided the answer to that.

The answer to Default sizes is made clear in this table (Check here for more info):

These are some examples of using Xms and Xmx:

-Xms50m

Heap start at 50 MB and can grow to default maximum.

-Xmx256m

Heap starts at the default value (8 MB) and can grow up to 256 MB.

-Xms4m -Xmx64m

Starts at 4 MB and grows up to 64 MB.

-Xms80m -Xmx80m

Heap will start at 80 MB and will never grow beyond that.
Default parameters of XMS and XMX in JVM
Intellipaat-community
by (62.9k points)
You explained the difference clearly. Thanks!
by (33.1k points)
Thanks for your answer!
It's really helpful.
+2 votes
by (107k points)
edited by

xmx and xms are the parameters utilized to adjust the heap size.

  • Xms: It is used for setting the first and minimum heap size. It is recommended to set the minimum heap size equivalent to the maximum heap size to minimize the garbage collection.
  • Xmx: It is applied for setting the maximum heap size. The performance will reduce if the max heap value is set lower than the amount of live data. It will force frequent garbage collections to free up space.

Looking for end to end material on Java for beginners! Here's the right video for you provided by Intellipaat:

So, you can say that the JVM will start working with -Xms amount of memory and further it will be able to use a maximum of -Xmx amount of memory. For example,

java -Xms256m -Xmx2048m

This indicates, JVM will startup with 256 MB of memory and will allow the process to use up to 2048 MB of memory.

By default, there is no value fixed for xms, and for xmx its 256MB. You can specify it in multiple formats like kilobytes, megabytes, etc.

-Xmx1024k 

-Xmx512m 

-Xmx8g

Default parameters of XMS and XMX in JVM
Intellipaat-community
by (62.9k points)
@vinita Very well explained. Thanks for the detailed explanation!
by (33.1k points)
So is it like when memory usage exceeds beyond Xmx we get JVM out of memory exception.
Well, Thanks for your answer!
by (41.4k points)
Yes, that's correct. When it tries to exceed that, although it may collect garbage to try to free up enough memory. If there still isn't enough memory to satisfy the request and the heap has already reached the maximum size, an OutOfMemoryError will occur
+2 votes
by (32.1k points)

Try running 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

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

I believe that this will help you understand Xms, Xmx as well as many other things that matter the most.

Default parameters of XMS and XMX in JVM
Intellipaat-community
by (29.5k points)
thanks this helped!!!
0 votes
by (29.3k points)

-Xmx and -Xms are used to limit the heap size in Java. 

The Java heap cannot grow larger than -Xmx. Also, the -Xms value can be used as a “minimum heap size” to set a fixed heap size by setting -Xms = -Xmx.

+1 vote
by (14.4k points)

While XMS (Extended Memory Specification) is a JVM parameter that is leveraged to set the minimum heap size, XMX is another parameter that is used to set the maximum heap size.

Both of these parameters can be specified in the IDE. This is how you can set both these parameters: 

-Xmx50m (This will set maximum Heap size = 50m)

-Xms5m   (This will set minimum Heap Size = 5m)

If you want minimum garbage collection, you need to ensure that minimum heap size equals to the maximum heap size. 

+1 vote
by (40.7k points)

For initial heap size:

Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before the J2SE 5.0 version, the default initial heap size was a reasonable minimum, which varies by platform. As per the need, you can override this default using the -Xms command-line option.

For maximum heap size:

Smaller of 1/4th of the physical memory or 1GB. Before the J2SE 5.0 version, the default maximum heap size was 64MB. As per the need, you can override this default using the -Xmx command-line option.

For more information you can refer to :

https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html

Usage:

If you are working on Windows, then you can try using the following command to find out the defaults on the system where your applications run:

java -XX:+PrintFlagsFinal -version | findstr HeapSize

You can use (-Xmx) command-line option for MaxHeapSize and (-Xms) for InitialHeapSize.

And if you are working on Unix/Linux system, then try using the below code:

java -XX:+PrintFlagsFinal -version | grep HeapSize

I hope this will help you :)

0 votes
by (106k points)

You can run the following command to see all the default parameters of XMS and XMX in JVM:-

java -X

Related questions

0 votes
2 answers
0 votes
1 answer
asked Mar 10, 2021 in Java by Jake (7k points)
0 votes
1 answer
asked Feb 25, 2021 in Java by Jake (7k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...