Main Tutorials

Java – what is -Xms and -Xmx parameter?

In Java, -Xms set initial Java heap size, while -Xmx set the maximum Java heap size.

1. Some java -Xms -Xmx examples :


# Start with 128MB of memory, and allow the Java process to use up to 1024MB of memory. 
java -Xms128m -Xmx1024m

# Start with 256MB of memory, and allow the Java process to use up to 4G (4096MB) of memory.
java -Xms256m -Xmx4g

2. The default initial and maximum Java heap size is allocated based on this ergonomics algorithm , also read this article – Find out your Java heap memory size

3. If the Java process has exceeded the -Xmx maximum Java heap size, the popular java.lang.OutOfMemoryError will be thrown.

4. For other options, run this java -X


> 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
    -XshowSettings:system
                      (Linux Only) show host system or container
                      configuration and continue
    -Xss<size>        set java thread stack size
    -Xverify          sets the mode of the bytecode verifier

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Tymski
4 years ago

Invalid maximum heap size: -Xmx4g

Anon eMouse
4 years ago
Reply to  Tymski

32 bit?