Default parameters of XMS and XMX in JVM

+11 votes

Can someone explain the purpose of xms and xmx parameters? Also, what are the default values these parameters during JVM startup?

Announcement! Career Guide 2019 is out now. Explore careers to become a Big Data Developer or Architect!

Jun 1, 2018 in Java by 93.lynn
• 1,600 points
402,972 views
what are the default values these parameters during JVM startup?

hi 

the flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool. 

Heap tuning guidelines

Your total heap size must not exceed the amount of physical RAM available. You must leave some physical RAM for other applications to run on your machine. You should set Xms and Xmx to the same value for best performance. These options determine your total heap size

13 answers to this question.

+2 votes

-xmx and -xms are the parameters used to adjust the heap size.

-Xms: It is used for setting the initial and minimum heap size. It is recommended to set the minimum heap size equivalent to the maximum heap size in order to minimize the garbage collection.

-Xmx: It is used for setting the maximum heap size. The performance will decrease if the max heap value is set lower than the amount of live data. It will force frequent garbage collections in order to free up space.

So, you can say that the JVM will start working with 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 means, 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 set for xms, and for xmx its 256MB. You can specify it in multiple formats like kilobytes, megabytes, etc.

-Xmx1024k 

-Xmx512m 

-Xmx8g

answered Jun 1, 2018 by v.liyyah
• 1,300 points
+3 votes

Run this code to see all the options:

java -X

answered Nov 13, 2018 by anonymous
+2 votes
You can go through this blog to better understand XMS and XMX in jvm
answered Nov 13, 2018 by Nabarupa
Thanks for share
+2 votes

The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool.

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.

answered Nov 13, 2018 by Jino
• 5,820 points
+2 votes

You use these Java command-line parameters to help control the RAM use of application:

  •  -Xmx to specify the maximum heap size
  •  -Xms to specify the initial Java heap size
answered Nov 13, 2018 by Murali
0 votes
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
answered Nov 14, 2018 by Maverick
• 10,840 points
0 votes
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 multiple sizes, such as kilobytes, megabytes, and so on.

-Xmx1024k
-Xmx512m
-Xmx8g
answered Nov 14, 2018 by Hannah
• 18,520 points
0 votes
The -xms option is used to set the initial and minimum heap size in Java.

The -xmx option is used to set the final and maximum heap size in Java.
answered Nov 27, 2018 by Shuvodip Ghosh
0 votes

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

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

answered Nov 27, 2018 by Stiphany
0 votes

You can see all the options by running java -X command:

C:\Users\omkar>java -X

    -Xbatch           disable background compilation
    -Xbootclasspath/a:<directories and zip/jar files separated by ;>
                      append to end of bootstrap class path
    -Xcheck:jni       perform additional checks for JNI functions
    -Xcomp            forces compilation of methods on first invocation
    -Xdebug           provided for backward compatibility
    -Xdiag            show additional diagnostic messages
    -Xfuture          enable strictest checks, anticipating future default
    -Xint             interpreted mode execution only
    -Xinternalversion
                      displays more detailed JVM version information than the
                      -version option
    -Xloggc:<file>    log GC status to a file with time stamps
    -Xmixed           mixed mode execution (default)
    -Xmn<size>        sets the initial and maximum size (in bytes) of the heap
                      for the young generation (nursery)
    -Xms<size>        set initial Java heap size
    -Xmx<size>        set maximum Java heap size
    -Xnoclassgc       disable class garbage collection
    -Xrs              reduce use of OS signals by Java/VM (see documentation)
    -Xshare:auto      use shared class data if possible (default)
    -Xshare:off       do not attempt to use shared class data
    -Xshare:on        require using shared class data, otherwise fail.
    -XshowSettings    show all settings and continue
    -XshowSettings:all
                      show all settings and continue
    -XshowSettings:locale
                      show all locale related settings and continue
    -XshowSettings:properties
                      show all property settings and continue
    -XshowSettings:vm show all vm related settings and continue
    -Xss<size>        set java thread stack size
    -Xverify          sets the mode of the bytecode verifier
    --add-reads <module>=<target-module>(,<target-module>)*
                      updates <module> to read <target-module>, regardless
                      of module declaration.
                      <target-module> can be ALL-UNNAMED to read all unnamed
                      modules.
    --add-exports <module>/<package>=<target-module>(,<target-module>)*
                      updates <module> to export <package> to <target-module>,
                      regardless of module declaration.
                      <target-module> can be ALL-UNNAMED to export to all
                      unnamed modules.
    --add-opens <module>/<package>=<target-module>(,<target-module>)*
                      updates <module> to open <package> to
                      <target-module>, regardless of module declaration.
    --illegal-access=<value>
                      permit or deny access to members of types in named modules
                      by code in unnamed modules.
                      <value> is one of "deny", "permit", "warn", or "debug"
                      This option will be removed in a future release.
    --limit-modules <module name>[,<module name>...]
                      limit the universe of observable modules
    --patch-module <module>=<file>(;<file>)*
                      override or augment a module with classes and resources
                      in JAR files or directories.
    --disable-@files  disable further argument file expansion

These extra options are subject to change without notice.
answered Nov 27, 2018 by Omkar
• 69,220 points
0 votes
Hi I cannot connect why?
answered Mar 23, 2019 by anonymous
Can you please tell something more about the error you are facing? Explain the error that you are getting, so that we can help you with a solution.
0 votes
The default value is chosen at runtime based on system configuration. For more information, see HotSpot Ergonomics.
answered Feb 21, 2020 by akshay
0 votes
Hi, @All,

On Windows, you can use the following command to find out the defaults on the system where your applications run.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.
answered Dec 10, 2020 by Gitika
• 65,770 points

Related Questions In Java

0 votes
1 answer

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

The XMX parameter helps in signifying and ...READ MORE

answered Feb 8, 2022 in Java by Soham
• 9,710 points
9,807 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
4,132 views
0 votes
1 answer

Why there is the need of getters and setters in java

In Java getters and setters are completely ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
1,985 views
+1 vote
1 answer

What are the types of memory in JVM?

The different types of Memory in JVM ...READ MORE

answered Mar 7, 2019 in Java by Priyaj
• 58,020 points
3,080 views
0 votes
1 answer

how to compare two words in java?

hey,  I think in your code the function ...READ MORE

answered Aug 8, 2019 in Java by sampriti
• 1,120 points

edited Aug 8, 2019 by Kalgi 2,301 views
0 votes
1 answer

How to add items in list at a time?

Hi Priyanka , I think this code snippet ...READ MORE

answered Aug 9, 2019 in Java by sampriti
• 1,120 points
2,401 views
0 votes
1 answer

What is $stateProvider in AngularJs?

Routing is just another way of fixing some content ...READ MORE

answered Feb 11, 2020 in Angular by Niroj
• 82,840 points
2,778 views
0 votes
3 answers

Does Java support Default Parameters?

You can try this with method overloading. void ...READ MORE

answered Sep 21, 2018 in Java by Sushmita
• 6,920 points
6,970 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
3,619 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,220 points
2,966 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP