ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

JVM默认堆内存大小

2022-06-29 09:02:45  阅读:223  来源: 互联网

标签:JVM maximum 默认 内存大小 GB heap memory size


这里直接贴上官网jdk1.8的链接https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#default_heap_size

翻译如下:

默认堆大小

除非在命令行上指定了初始堆大小和最大堆大小,否则它们将根据计算机上的内存量进行计算。

  • 最大物理内存大小不超过192兆字节(MB)时默认最大堆大小是物理内存的一半,否则占用物理内存的四分之一
  • 在32位JVM上,如果有4 GB或更多的物理内存,则默认的最大堆大小最多可以为1 GB。
  • 在64位JVM上,如果有128GB或更多的物理内存,则默认的最大堆大小最大为32 GB。
  • 在JVM初始化期间分配了一个较小的值,称为初始堆大小。此数量至少为8 MB,否则为物理内存的1/64,最大为1 GB。
  • 分配给年轻代的最大空间量是堆总大小的三分之一,即年轻代和老年代默认的比例是1:2
  • 您可以使用-Xms(初始堆大小)和-Xmx(最大堆大小)来指定初始堆大小和最大堆大小。如果你知道你的应用程序有多少堆需要工作做好,你可以设置-Xms和-Xmx相同的值。否则,JVM将使用初始堆大小开始,然后将增大Java堆,直到找到堆使用率和性能之间的平衡为止。

以上就是在jdk1.8中的说明,但是在不同jdk版本和使用不同的垃圾收集器后或许会有调整

Default Heap Size

Unless the initial and maximum heap sizes are specified on the command line, they are calculated based on the amount of memory on the machine.

Client JVM Default Initial and Maximum Heap Sizes

The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes (MB) and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte (GB).

For example, if your computer has 128 MB of physical memory, then the maximum heap size is 64 MB, and greater than or equal to 1 GB of physical memory results in a maximum heap size of 256 MB.

The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, called the initial heap size, is allocated during JVM initialization. This amount is at least 8 MB and otherwise 1/64th of physical memory up to a physical memory size of 1 GB.

The maximum amount of space allocated to the young generation is one third of the total heap size.

Server JVM Default Initial and Maximum Heap Sizes

The default initial and maximum heap sizes work similarly on the server JVM as it does on the client JVM, except that the default values can go higher. On 32-bit JVMs, the default maximum heap size can be up to 1 GB if there is 4 GB or more of physical memory. On 64-bit JVMs, the default maximum heap size can be up to 32 GB if there is 128 GB or more of physical memory. You can always set a higher or lower initial and maximum heap by specifying those values directly; see the next section.

Specifying Initial and Maximum Heap Sizes

You can specify the initial and maximum heap sizes using the flags -Xms (initial heap size) and -Xmx (maximum heap size). If you know how much heap your application needs to work well, you can set -Xms and -Xmx to the same value. If not, the JVM will start by using the initial heap size and will then grow the Java heap until it finds a balance between heap usage and performance.

Other parameters and options can affect these defaults. To verify your default values, use the -XX:+PrintFlagsFinal option and look for MaxHeapSize in the output. For example, on Linux or Solaris, you can run the following:

java -XX:+PrintFlagsFinal -version | grep MaxHeapSize

Excessive GC Time and OutOfMemoryError

The parallel collector throws an OutOfMemoryError if too much time is being spent in garbage collection (GC): If more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, then an OutOfMemoryError is thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line.

Measurements

The verbose garbage collector output from the parallel collector is essentially the same as that from the serial collector.

标签:JVM,maximum,默认,内存大小,GB,heap,memory,size
来源: https://www.cnblogs.com/hwp0710/p/16421941.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有