313

java -Xmx1024m filename

what does -Xmx mean?

Peter Perháč
  • 20,434
  • 21
  • 120
  • 152
ravi
  • 3,177
  • 2
  • 15
  • 4
  • 16
    BTW: Options which start with `-X` are non standard across platforms and may be removed in the future. There is now a `-mx` which is standard, shorter and does the same thing however is poorly documented. :( Similarly there is `-mx` instead of `-Xms` – Peter Lawrey Mar 21 '11 at 07:40
  • 3
    Why "mx" though? How in the world did we end up with "m" for heap size and "x" for maximum? At least "s" for "starting" makes sense. – Patrick McElhaney Oct 04 '15 at 17:27
  • 4
    @PatrickMcElhaney Seems like a good bet that "m" is for "memory", and "x" is for "max" because you can't use "m" (it would be the same for both "max" and "min" -- using the last character lets "x" be "max" and "n" be "min"). – Jazz Oct 17 '16 at 20:24

5 Answers5

366

see here: Java Tool Doc, it says,

-Xmxn
Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. Examples:

           -Xmx83886080
           -Xmx81920k
           -Xmx80m

So, in simple words, you are setting Java heap memory to a maximum of 1024 MB from the available memory, not more.

Notice there is NO SPACE between -Xmx and 1024m

It does not matter if you use uppercase or lowercase. For example: "-Xmx10G" and "-Xmx10g" do the exact same thing.

Nishant
  • 54,584
  • 13
  • 112
  • 127
  • 32
    This is a little misleading. The values of Xmx and Xms are not the total size of the memory used by the JVM - only of the *heap*. See the answer by typo.pl – GreenGiant Jul 08 '14 at 22:00
  • 2
    I was hoping to find the meaning of X, as I'm looking for what -XX stands for. What the shortcut means.... – Sebastian Sep 29 '14 at 14:41
  • X commands are nonstandard commands, they may be system dependent, and can be changed. To learn about XX commands, please see this: http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionXX.html – Nishant Sep 30 '14 at 06:11
  • 18
    ..and add suffix "G" or "g" to indicate Gigabytes :) – Asa Nov 10 '14 at 04:25
  • @GreenGiant the max value of this parameter also depends on jvm. if jvm is 64 bit then you can set bigger value – overexchange Dec 27 '14 at 05:17
  • 2
    it's worth noting that if you want the -X args to be picked up globally by all java processes, you can set the JAVA_TOOL_OPTIONS env variable, e.g. export JAVA_TOOL_OPTIONS="-Xmx6g" [http://stackoverflow.com/questions/17781405/information-about-java-options] and [http://stackoverflow.com/questions/28327620/difference-between-java-options-java-tool-options-and-java-opts] – CCJ Nov 10 '16 at 23:31
  • 1
    Thanks! I was looking for the case (in)sensitivity of the units and got the exact answer – asgs Jun 22 '17 at 17:51
178
C:\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
    -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.

The -X options are non-standard and subject to change without notice.
typo.pl
  • 8,812
  • 2
  • 28
  • 29
  • 15
    people should really start reading the fine manuals ... thanks! – user1052080 Mar 07 '15 at 14:26
  • 22
    Yeah, those 1 line descriptions are absolutely thorough and cover everything. That's why no one needs StackOverflow. Might not be so bad if they let you do help on individual arguments and look at the implications of setting these in more detail, so manual pages for the arguments of a command, etc. – Craig Brett Feb 22 '18 at 08:51
20

The -Xmx option changes the maximum Heap Space for the VM. java -Xmx1024m means that the VM can allocate a maximum of 1024 MB. In layman terms this means that the application can use a maximum of 1024MB of memory.

Aleksander Blomskøld
  • 18,374
  • 9
  • 76
  • 82
  • thank you..but when i am running this command i am getting these errors... 1) Invalid maximum heap size: -Xmx and 2) Could not create the java virtual machine can u help me – ravi Mar 21 '11 at 06:30
  • 1
    You need to remove the space between -Xmx and the size (write this: java -Xmx1024m. NOT this: java -Xmx 1024m) – Aleksander Blomskøld Mar 21 '11 at 09:09
  • notice that your app might still use MORE memory because you need to include VM overhead, this is why it's tricky when you wish to pus java inside cgroup memory limit – Jakub Głazik Dec 08 '17 at 12:37
  • I disagree with this. -Xmx is the only heap size so technically java process can take more than -Xmx memory. We are not considering local stack and VM overhead. – Lokesh Sep 07 '21 at 03:44
  • Please go through below article. -Xmx setting is only for heap size not for entire java process. https://plumbr.io/blog/memory-leaks/why-does-my-java-process-consume-more-memory-than-xmx – Lokesh Sep 07 '21 at 03:57
14

Max heap Usage for the application is is 1024 MB

Kanagaraj M
  • 639
  • 5
  • 16
8

-Xmx sets the Maximum Heap size

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130