java虚拟机的堆内存配置

Posted 源码王

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于java虚拟机的堆内存配置的主要内容,如果未能解决你的问题,请参考以下文章

Java虚拟机(JVM)-- 堆内存调优

JAVA虚拟机内存分配与回收机制

GC(垃圾回收)

Android性能优化的一些方案

内存泄露

Java虚拟机的内存组成以及堆内存介绍