What are Xmx and Xms parameters in java

In this post, we will see about Xms and Xmx parameter in java.

-Xmx specifies maximum memory size for Java virtual machine (JVM), while -Xms specifies the initial memory size.

It means JVM will be started with Xms amount of memory and JVM will be able to use maximum of JVM amount of memory.

Let’s understand this with help of example.

java -Xms512m -Xmx1024m

So java process will start with 512 MB of memory heap and can use upto 1024 MB of memory heap.

-Xmx and -Xms can be defined in different size such as kilobytes, megabytes and gigabytes.


If Java process exceeds -Xmx memory size, then you will java.lang.OutOfMemoryError.

Default initial size is allocated on the based of ergonomics algorithm.

-Xms and -Xmx are the options for JVM’s heap and JVM can use more memory than size allocated to heap.

If you want to learn about all -X option, you can use java -X command.

Apples-MacBook-Pro-5:~ apple$ java -X-Xbatch
disable background compilation-Xbootclasspath/a:
append to end of bootstrap class path

perform additional checks for JNI functions

forces compilation of methods on first invocation

provided for backward compatibility

show additional diagnostic messages

enable strictest checks, anticipating future default

interpreted mode execution only

displays more detailed JVM version information than the
-version option

log GC status to a file with time stamps

mixed mode execution (default)

sets the initial and maximum size (in bytes) of the heap
for the young generation (nursery)

set initial Java heap size

set maximum Java heap size

disable class garbage collection

reduce use of OS signals by Java/VM (see documentation)

use shared class data if possible (default)

do not attempt to use shared class data

require using shared class data, otherwise fail.

show all settings and continue

show all settings and continue

show all locale related settings and continue

show all property settings and continue

show all vm related settings and continue

(Linux Only) show host system or container configuration and continue

set [java thread](https://java2blog.com/java-thread-example/ “java thread”) stack size

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

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

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.

[email protected]
disable further argument file expansion

–source <version>
set the version of the source in source-file mode.

These extra options are subject to change without notice.

The following options are Mac OS X specific:
run the main() method on the first (AppKit) thread

-Xdock:name=<application name>
override default application name displayed in dock

-Xdock:icon=<path to icon file>
override default icon displayed in dock

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

Please note that it is quite important to set -Xms and -Xmx parameters correctly. Java 13 has introduced a new feature in Z garbage collector where it will uncommit the memory to CPU but it won’t uncommit below -Xms parameter, so if you put -Xms and -Xmx as equal, it will basically disable this feature. This feature is quite useful where memory footprint is a concern.

That’s all about Java’s -Xmx and -Xms parameters.

Was this post helpful?

Related Posts

  • 30 December

    [Fixed] Initial heap size set to a larger value than the maximum heap size

    Learn about how to fix Initial heap size set to a larger value than the maximum heap size in java.

  • 16 July

    Garbage Collection in java

    Table of ContentsYoung GenerationOld generationWhy two survivor spaces?Garbage Collection Algorithmsserial collectorParallel collectorConcurrent collector In this post, we will see about Garbage Collection in java. I will try to explain with the help of diagrams and examples rather than theory. JVM Memory is divided into three parts Young generation Old generation Metaspace (Perm Gen) Young Generation […]

  • 19 August

    Java virtual Machine(JVM) and its architecture

    Table of ContentsJVM Architecture diagramClass LoaderLoadingLinkingInitializationRuntime data areas (memory)Execution engineInterpreterJIT compiler(just In time)Java Native InterfaceNative Method Libraries In this article, you will know about java virtual machine which made Java as more popular. We all know that Java applications can be write once and run many times anywhere. This is possible with only JVM. Because […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.