324

java -Xmx1024m filename

what does -Xmx mean?

3
  • 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 Commented Mar 21, 2011 at 7: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. Commented Oct 4, 2015 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"). Commented Oct 17, 2016 at 20:24

5 Answers 5

373

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.

Sign up to request clarification or add additional context in comments.

7 Comments

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
I was hoping to find the meaning of X, as I'm looking for what -XX stands for. What the shortcut means....
..and add suffix "G" or "g" to indicate Gigabytes :)
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" [stackoverflow.com/questions/17781405/… and [stackoverflow.com/questions/28327620/…
Thanks! I was looking for the case (in)sensitivity of the units and got the exact answer
|
182
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.

3 Comments

people should really start reading the fine manuals ... thanks!
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.
Google java command line options or just run man java ... it's so hard ...
21

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.

5 Comments

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
You need to remove the space between -Xmx and the size (write this: java -Xmx1024m. NOT this: java -Xmx 1024m)
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
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.
Please go through below article. -Xmx setting is only for heap size not for entire java process. plumbr.io/blog/memory-leaks/…
15

Max heap Usage for the application is is 1024 MB

Comments

8

-Xmx sets the Maximum Heap size

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.