java虚拟机的堆内存配置

官网文档地址:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html

接录如下:

-XX:MaxHeapSize=size

Sets the maximum size (in byes) of the memory allocation pool. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. For server deployments, -XX:InitialHeapSize and -XX:MaxHeapSize are often set to the same value. See the section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage Collection Tuning Guide at http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.

The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:

-XX:MaxHeapSize=83886080
-XX:MaxHeapSize=81920k
-XX:MaxHeapSize=80m

On Oracle Solaris 7 and Oracle Solaris 8 SPARC platforms, the upper limit for this value is approximately 4,000 MB minus overhead amounts. On Oracle Solaris 2.6 and x86 platforms, the upper limit is approximately 2,000 MB minus overhead amounts. On Linux platforms, the upper limit is approximately 2,000 MB minus overhead amounts.

The -XX:MaxHeapSize option is equivalent to -Xmx.


大致是这么几点:

  1. linux操作系统上堆内存最大的设置是2个G。
  2. -XX:MaxHeapSize 等价于 -Xmx
  3. 这个值必须是1024的倍数并且大于2 MB

不过以上似乎只是32位机器上的设置,在64位机器上堆内存将不受此限制,但在官网上没找到原话。

上一篇:DAY6 元组、字典与集合


下一篇:java-在JNLP中指定’package’属性有什么好处?