PretenureSizeThreshold

最近调整项目jvm参数,慢慢整理一些平时调参的一些笔记备忘吧

XX:PretenureSizeThreshold

XX:PretenureSizeThreshold超过这个值的时候,对象直接在old区分配内存

Frequently Asked Questions about Garbage Collection

There is a flag (available in 1.4.2 and later) l-XX:PretenureSizeThreshold= that can be set to limit the size of allocations in the young generation. Any allocation larger than this will not be attempted in the young generation and so will be allocated out of the old generation. The default size for PretenureSizeThreshold is 0 which says that any size can be allocated in the young generation

测试程序.

参考PretenureSizeThreshold 的默认值和作用

public class PretenureSizeThreshold
{
    /**
     * VM: Args: -Xms20m -Xmx30m -Xmn10m -XX:PretenureSizeThreshold=4m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal -XX:+PrintGCDetails -Xloggc:./gc.log 
     * @param args
     */
    public static void main(String[] args)
    {
        //byte[] array = new byte[9*1024*1024];
        byte[] array = new byte[6*1024*1024];
        //byte[] array1 = new byte[1*1024*1024];

        for(MemoryPoolMXBean memoryPoolMXBean: ManagementFactory.getMemoryPoolMXBeans()){
            System.out.println(memoryPoolMXBean.getName() 
                    + "   total:"+memoryPoolMXBean.getUsage().getCommitted()
                    +"   used:"+memoryPoolMXBean.getUsage().getUsed());
        }

        try {
            Thread.sleep(10000);
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

测试-1

-Xms20m -Xmx30m -Xmn10m 
-XX:+HeapDumpOnOutOfMemoryError
-XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal

从下面看.
(1)当byte[] array = new byte[910241024];

Code Cache   total:2555904   used:1221888
Metaspace   total:4980736   used:2877544
Compressed Class Space   total:524288   used:308512
Par Eden Space   total:8388608   used:1359440
Par Survivor Space   total:1048576   used:0
CMS Old Gen   total:10485760   used:9437200

Eden 为8M,两个Survivor分别为1M.
Old Gen为10M.
我们分配的对象为9M,大于Eden 所以直接分配在Old Gen,used:9437200.

(2) 当byte[] array = new byte[610241024];
全部分配在Eden.

Code Cache   total:2555904   used:1224064
Metaspace   total:4980736   used:2879976
Compressed Class Space   total:524288   used:309080
Par Eden Space   total:8388608   used:7650912
Par Survivor Space   total:1048576   used:0
CMS Old Gen   total:10485760   used:0

测试-2

当byte[] array = new byte[610241024];
这是VM参数:

-Xms20m -Xmx30m -Xmn10m -XX:PretenureSizeThreshold=4m 
-XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC
-XX:+PrintFlagsFinal -XX:+PrintGCDetails -Xloggc:./gc.log 

Eden 为8M,两个Survivor分别为1M.
Old Gen为10M.
这里可将设置 PretenureSizeThreshold=4M后,直接将对象内存分配在Old Gen

Code Cache   total:2555904   used:1229312
Metaspace   total:4980736   used:2881872
Compressed Class Space   total:524288   used:309080
Par Eden Space   total:8388608   used:1359440
Par Survivor Space   total:1048576   used:0
CMS Old Gen   total:10485760   used:6291472

设置打印GC log

 -XX:+PrintFlagsFinal -XX:+PrintGCDetails -Xloggc:./gc.log 

下载[gcviewer](https://sourceforge.net/projects/gcviewer/)查看gc日志,启动gcviewer

 java -jar gcviewer-1.36-SNAPSHOT.jar

打开gc log即可分析

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值