热点默认最大堆大小

发布于 2024-12-01 13:38:51 字数 2614 浏览 0 评论 0原文

根据以下文档 http: //www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#par_gc.ergonomics.default_size 默认最大值并行 GC 的堆大小是使用公式 MIN(内存 / 4, 1GB) 选择的。从公式中可以明显看出,但文档仍然指出“默认最大堆大小不会超过 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?

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
       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]$ 

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月棠 2024-12-08 13:38:51

我在这里发布了这个问题来打开jdk邮件列表 http://mail.openjdk.java.net/pipermail/hotspot-gc-use/2011-August/000912.html

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

对应的bug Id https://bugs.java.com/bugdatabase/view_bug?bug_id= 6887571。
发行说明
http://www.oracle.com/technetwork/java/ javase/6u18-142093.html

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 https://bugs.java.com/bugdatabase/view_bug?bug_id=6887571.
Release notes http://www.oracle.com/technetwork/java/javase/6u18-142093.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文