垃圾收集器参数测试(JVM)

4 篇文章 0 订阅

java -version

java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

测试程序

import java.lang.management.CompilationMXBean;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;

public class ManagementFactoryTest {
	
	public final static void printGarbageCollectorMXBeansInfo(){
		List<GarbageCollectorMXBean> GarbageCollectorMXBeanList=ManagementFactory.getGarbageCollectorMXBeans();
		System.out.println("GarbageCollectorMXBeanList.size():"+GarbageCollectorMXBeanList.size());
		for(GarbageCollectorMXBean gcMXBean:GarbageCollectorMXBeanList){
			long collectionCount=gcMXBean.getCollectionCount();
			long collectionTime=gcMXBean.getCollectionTime();
			String[] memoryPoolNames=gcMXBean.getMemoryPoolNames();
			String name=gcMXBean.getName();
			String objectName=gcMXBean.getObjectName().toString();
			boolean isValid=gcMXBean.isValid();
			StringBuilder sb=new StringBuilder();
			sb.append("collectionCount:").append(collectionCount).append("\n")
			.append("collectionTime:").append(collectionTime).append("\n")
			.append("GarbageCollectorName:").append(name).append("\n")
			.append("objectName:").append(objectName).append("\n")
			.append("isValid:").append(isValid).append("\n")
			.append("memoryPoolNames:\n");
			for(int i=0;i<memoryPoolNames.length;i++){
				sb.append("\tmemoryPoolName_").append(i).append(":").append(memoryPoolNames[i]).append("\n");
			}
			System.out.println(sb.toString());
		}
	}
	
	public static void main(String[] args) {
		printGarbageCollectorMXBeansInfo();
	}
}

测试结果vm参数及结果:

1、-XX:+UseParNewGC  -XX:+PrintVMOptions

    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:ParNew
    objectName:java.lang:type=GarbageCollector,name=ParNew
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:Par Eden Space
        memoryPoolName_1:Par Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:MarkSweepCompact
    objectName:java.lang:type=GarbageCollector,name=MarkSweepCompact
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:Par Eden Space
        memoryPoolName_1:Par Survivor Space
        memoryPoolName_2:Tenured Gen

    VM option '+UseParNewGC'
    VM option '+PrintVMOptions'


2、-XX:+UseConcMarkSweepGC  -XX:+PrintVMOptions
  

    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:ParNew
    objectName:java.lang:type=GarbageCollector,name=ParNew
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:Par Eden Space
        memoryPoolName_1:Par Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:ConcurrentMarkSweep
    objectName:java.lang:type=GarbageCollector,name=ConcurrentMarkSweep
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:Par Eden Space
        memoryPoolName_1:Par Survivor Space
        memoryPoolName_2:CMS Old Gen

    VM option '+UseConcMarkSweepGC'
    VM option '+PrintVMOptions'


3、-XX:+UseG1GC  -XX:+PrintVMOptions


    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:G1 Young Generation
    objectName:java.lang:type=GarbageCollector,name=G1 Young Generation
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:G1 Eden Space
        memoryPoolName_1:G1 Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:G1 Old Generation
    objectName:java.lang:type=GarbageCollector,name=G1 Old Generation
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:G1 Eden Space
        memoryPoolName_1:G1 Survivor Space
        memoryPoolName_2:G1 Old Gen

    VM option '+UseG1GC'
    VM option '+PrintVMOptions'


4、-XX:+UseAdaptiveSizePolicyWithSystemGC  -XX:+PrintVMOptions


    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS Scavenge
    objectName:java.lang:type=GarbageCollector,name=PS Scavenge
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS MarkSweep
    objectName:java.lang:type=GarbageCollector,name=PS MarkSweep
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space
        memoryPoolName_2:PS Old Gen

    VM option '+UseAdaptiveSizePolicyWithSystemGC'
    VM option '+PrintVMOptions'


5、-XX:+UseMaximumCompactionOnSystemGC  -XX:+PrintVMOptions


    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS Scavenge
    objectName:java.lang:type=GarbageCollector,name=PS Scavenge
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS MarkSweep
    objectName:java.lang:type=GarbageCollector,name=PS MarkSweep
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space
        memoryPoolName_2:PS Old Gen

    VM option '+UseMaximumCompactionOnSystemGC'
    VM option '+PrintVMOptions'


6、-XX:+UseParallelGC  -XX:+PrintVMOptions


    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS Scavenge
    objectName:java.lang:type=GarbageCollector,name=PS Scavenge
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS MarkSweep
    objectName:java.lang:type=GarbageCollector,name=PS MarkSweep
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space
        memoryPoolName_2:PS Old Gen

    VM option '+UseParallelGC'
    VM option '+PrintVMOptions'


7、-XX:+UseParallelOldGC  -XX:+PrintVMOptions


    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS Scavenge
    objectName:java.lang:type=GarbageCollector,name=PS Scavenge
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:PS MarkSweep
    objectName:java.lang:type=GarbageCollector,name=PS MarkSweep
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:PS Eden Space
        memoryPoolName_1:PS Survivor Space
        memoryPoolName_2:PS Old Gen

    VM option '+UseParallelOldGC'
    VM option '+PrintVMOptions'


8、-XX:+UseSerialGC  -XX:+PrintVMOptions


    GarbageCollectorMXBeanList.size():2
    collectionCount:0
    collectionTime:0
    GarbageCollectorName:Copy
    objectName:java.lang:type=GarbageCollector,name=Copy
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:Eden Space
        memoryPoolName_1:Survivor Space

    collectionCount:0
    collectionTime:0
    GarbageCollectorName:MarkSweepCompact
    objectName:java.lang:type=GarbageCollector,name=MarkSweepCompact
    isValid:true
    memoryPoolNames:
        memoryPoolName_0:Eden Space
        memoryPoolName_1:Survivor Space
        memoryPoolName_2:Tenured Gen

    VM option '+UseSerialGC'
    VM option '+PrintVMOptions'


9、-XX:+UseShenandoahGC  -XX:+PrintVMOptions


    VM option '+UseShenandoahGC'
    VM option '+PrintVMOptions'
    Unrecognized VM option 'UseShenandoahGC'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值