启动JVM时,Xms和Xmx参数是什么?

请解释在JVM中使用XmsXmx参数。 他们的默认值是什么?

标志Xmx指定Java虚拟机(JVM)的最大内存分配池,而Xms指定初始内存分配池。

这意味着您的JVM将以Xms内存量启动,并且将能够使用最大Xmx内存量。 例如,像下面这样启动一个JVM,将启动256MB的内存,并允许进程使用高达2048MB的内存:

 java -Xms256m -Xmx2048m 

内存标志也可以被指定为多种大小,如千字节,兆字节等等。

 -Xmx1024k -Xmx512m -Xmx8g 

Xms标志没有默认值, Xmx通常默认值为256MB。 这些标志的常见用法是遇到java.lang.OutOfMemoryError

在使用这些设置时,请记住,这些设置是针对JVM 堆的 ,而且JVM可以使用更多的内存,而不仅仅是分配给堆的大小。 从Oracle的文档 :

请注意,JVM使用的内存不仅仅是堆。 例如,Java方法,线程堆栈和本地句柄分配在独立于堆的内存中,以及JVM内部数据结构中。

只需运行命令java -X ,就会得到所有-X选项的列表:

 C:\Users\Admin>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 -Xdiag show additional diagnostic messages -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. -XshowSettings show all settings and continue -XshowSettings:all show all settings and continue -XshowSettings:vm show all vm related settings and continue -XshowSettings:properties show all property settings and continue -XshowSettings:locale show all locale related settings and continue 

-X选项是非标准的,如有更改,恕不另行通知。

我希望这能帮助你理解Xms,Xmx以及其他更重要的事情。 🙂

你可以在你的IDE中指定。 例如,在运行Configuration> Vm Arguments中input-Xmx800m -Xms500m

在这里输入图像描述

问题的主要部分已经在上面讨论过了。 只需添加部分默认值。

按照http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html

Xmx的默认值将取决于平台和系统中可用的内存量。