简体   繁体   中英

Hotspot default max heap size

According to the following document http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#par_gc.ergonomics.default_size the default maximum heap size for Parallel GC is chosen using formula MIN(memory / 4, 1GB). It's obvious from the formula, but the document still notes that "that the default maximum heap size will not exceed 1GB, regardless of how much memory is installed on the machine." To verify that I wrote the following program

public class Allocate{

        public static void main(String[] args) throws Exception {
            long megabytes = Long.valueOf(args[0]);
            long bytes = megabytes * 1024 * 1024;
            int longs = (int) (bytes / 8);
            long[] arr = new long[longs];
            Thread.sleep(Long.MAX_VALUE);
            System.out.println(arr.length);
        }
    }

I executed this program on a box with 16Gb of RAM.

smeldris@us4nrsdn01 allocation]$ /usr/java/jdk1.6.0_26/bin/java Allocate 2048 &
    [1] 9291
    [smeldris@us4nrsdn01 allocation]$ /usr/java/jdk1.6.0_26/bin/jmap -heap 9291
    Attaching to process ID 9291, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 20.1-b02

    using thread-local object allocation.
    Parallel GC with 8 thread(s)

    Heap Configuration:
       MinHeapFreeRatio = 40
       MaxHeapFreeRatio = 70
       
       NewSize          = 1310720 (1.25MB)
       MaxNewSize       = 17592186044415 MB
       OldSize          = 5439488 (5.1875MB)
       NewRatio         = 2
       SurvivorRatio    = 8
       PermSize         = 21757952 (20.75MB)
       MaxPermSize      = 85983232 (82.0MB)

    Heap Usage:
    PS Young Generation
    Eden Space:
       capacity = 65798144 (62.75MB)
       used     = 1315976 (1.2550125122070312MB)
       free     = 64482168 (61.49498748779297MB)
       2.0000199397721614% used
    From Space:
       capacity = 10944512 (10.4375MB)
       used     = 0 (0.0MB)
       free     = 10944512 (10.4375MB)
       0.0% used
    To Space:
       capacity = 10944512 (10.4375MB)
       used     = 0 (0.0MB)
       free     = 10944512 (10.4375MB)
       0.0% used
    PS Old Generation
       capacity = 2322923520 (2215.3125MB)
       
       free     = 175439856 (167.31248474121094MB)
       92.44745449045176% used
    PS Perm Generation
       capacity = 21757952 (20.75MB)
       used     = 2606752 (2.485992431640625MB)
       free     = 19151200 (18.264007568359375MB)
       11.980686417545181% used
    [smeldris@us4nrsdn01 allocation]$

The 2GB array was allocated in the old generation. The MaxHeapSize is 4GB, which is 1/4 of system memory. Why did JVM reserve 4GB for the heap?

I posted this question to open jdk mailing list here http://mail.openjdk.java.net/pipermail/hotspot-gc-use/2011-August/000912.html .

The GC ergonomics was changed in the (1.6.0_18), but the documentation hasn't been updated yet.

The corresponding bug Id http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6887571 . Release notes http://www.oracle.com/technetwork/java/javase/6u18-142093.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM