How is the default max Java heap size determined?

前端 未结 10 1706
旧巷少年郎
旧巷少年郎 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:19

    The Xms and Xmx are flag of Java virtual machine (JVM):

    • Xms: initial and minimum JVM heap size
      • Format: -Xms[g|G|m|M|k|K]
      • Default Size:
        • -server mode: 25% of free physical memory, >=8MB and <= 64MB
        • -client mode: 25% of free physical memory, >=8MB and <= 16MB
      • Typical Size:
        • -Xms128M
        • -Xms256M
        • -Xms512M
      • Function/Effect:
        • -> JVM start with allocate Xms size memory
    • Xmx: maximum JVM heap size
      • Format: -Xmx[g|G|m|M|k|K]
      • Default Size:
        • <= R27.2
          • Windows: 75% of total physical memory up to 1GB
          • Linux/Solaris: 50% of available physical memory up to 1GB
        • >= R27.3
          • Windows X64: 75% of total physical memory up to 2GB
          • Linux/Solaris X64: 50% of available physical memory up to 2GB
          • Windows x86: 75% of total physical memory up to 1GB
          • Linux/Solaris X86: 50% of available physical memory up to 1GB
      • Typical Size:
        • -Xmx1g
        • -Xmx2084M
        • -Xmx4g
        • -Xmx6g
        • -Xmx8g
      • Function/Effect:
        • -> JVM allow use maxium of Xmx size memory
          • when exceed Xmx, will java.lang.OutOfMemoryError
            • How to fix OutOfMemoryError ?
              • exceed Xmx value
                • eg: from -Xmx4g to -Xmx8g

    More detail

    see official doc: -X Command-line Options

提交回复
热议问题