How is the default max Java heap size determined?

前端 未结 10 1897
旧巷少年郎
旧巷少年郎 2020-11-22 03:50

If I omit the -Xmxn option from the Java command line then a default value will be used. According to Java documentation

\"the default v

10条回答
  •  面向向阳花
    2020-11-22 04:15

    default value is chosen at runtime based on system configuration

    Have a look at the documentation page

    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.

    1. 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).

    2. Server JVM Default Initial and Maximum Heap Sizes:

      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

    What system configuration settings influence the default value?

    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

提交回复
热议问题