热点默认最大堆大小

时间:2011-08-25 17:20:20

标签: java jvm memory-management jvm-hotspot

根据以下文档http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#par_gc.ergonomics.default_size,使用公式MIN(内存/ 4,1GB)选择并行GC的默认最大堆大小。从公式中可以明显看出,但文档仍然指出“无论机器上安装了多少内存,默认的最大堆大小都不会超过1GB。”验证我是否编写了以下程序


    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);
        }
    }

我在一个装有16Gb 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
       MaxHeapSize      = 4208984064 (4014.0MB)
       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)
       used     = 2147483664 (2048.000015258789MB)
       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]$ 

2GB阵列是在老一代中分配的。 MaxHeapSize是4GB,是系统内存的1/4。为什么JVM为堆保留了4GB?

1 个答案:

答案 0 :(得分:3)

我发布此问题是为了打开jdk邮件列表http://mail.openjdk.java.net/pipermail/hotspot-gc-use/2011-August/000912.html

GC(人机工程学)在(1.6.0_18)中已更改,但文档尚未更新。

相应的错误ID http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6887571。 发行说明http://www.oracle.com/technetwork/java/javase/6u18-142093.html