What is the default maximum heap size for Sun's JVM from Java SE 6?

前端 未结 6 1058
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 18:38

What is the default maximum heap size for Sun\'s JVM from Java SE 6 (i.e. equivalent to setting -Xmx)?

Looks like for Java SE 5 with a server-class machine, it\'s

相关标签:
6条回答
  • 2020-11-29 18:46

    As of JDK6U18 following are configurations for the Heap Size.

    In the Client JVM, the default Java heap configuration has been modified to improve the performance of today's rich client applications. Initial and maximum heap sizes are larger and settings related to generational garbage collection are better tuned.

    The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte. For example, if your machine has 128 megabytes of physical memory, then the maximum heap size is 64 megabytes, and greater than or equal to 1 gigabyte of physical memory results in a maximum heap size of 256 megabytes. The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, termed the initial heap size, is allocated during JVM initialization. This amount is at least 8 megabytes and otherwise 1/64 of physical memory up to a physical memory size of 1 gigabyte.

    Source : http://www.oracle.com/technetwork/java/javase/6u18-142093.html

    0 讨论(0)
  • 2020-11-29 18:50

    One can ask with some Java code:

    long maxBytes = Runtime.getRuntime().maxMemory();
    System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");
    

    See javadoc.

    0 讨论(0)
  • 2020-11-29 18:52

    one way is if you have a jdk installed , in bin folder there is a utility called jconsole(even visualvm can be used). Launch it and connect to the relevant java process and you can see what are the heap size settings set and many other details

    When running headless or cli only, jConsole can be used over lan, if you specify a port to connect on when starting the service in question.

    0 讨论(0)
  • 2020-11-29 18:55

    With JDK, You can also use jinfo to connect to the JVM for the <PROCESS_ID> in question and get the value for MaxHeapSize:

    jinfo -flag MaxHeapSize <PROCESS_ID>
    
    0 讨论(0)
  • 2020-11-29 18:59

    java 1.6.0_21 or later, or so...

    $ java -XX:+PrintFlagsFinal -version 2>&1 | grep MaxHeapSize
    uintx MaxHeapSize                         := 12660904960      {product}
    

    It looks like the min(1G) has been removed.

    Or on Windows using findstr

    C:\>java -XX:+PrintFlagsFinal -version 2>&1 | findstr MaxHeapSize
    
    0 讨论(0)
  • 2020-11-29 18:59

    To answer this question it's critical whether the Java VM is in CLIENT or SERVER mode. You can specify "-client" or "-server" options. Otherwise java uses internal rules; basically win32 is always client and Linux is always server, but see the table here:

    http://docs.oracle.com/javase/6/docs/technotes/guides/vm/server-class.html

    Sun/Oracle jre6u18 doc says re client: the VM gets 1/2 of physical memory if machine has <= 192MB; 1/4 of memory if machine has <= 1Gb; max 256Mb. In my test on a 32bit WindowsXP system with 2Gb phys mem, Java allocated 256Mb, which agrees with the doc.

    Sun/Oracle jre6u18 doc says re server: same as client, then adds confusing language: for 32bit JVM the default max is 1Gb, and for 64 bit JVM the default is 32Gb. In my test on a 64bit linux machine with 8Gb physical, Java allocates 2Gb, which is 1/4 of physical; on a 64bit linux machine with 128Gb physical Java allocates 32Gb, again 1/4 of physical.

    Thanks to this SO post for guiding me:

    Definition of server-class machine changed recently?

    0 讨论(0)
提交回复
热议问题