运行JVM的GC参数是什么? [英] What GC parameters is a JVM running with?

查看:88
本文介绍了运行JVM的GC参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然在调查我使用GC调整的问题(请参阅

Sun Java5 + JVM尝试自动选择最佳的GC策略和参数,基于他们的环境非常棒,但我无法弄清楚如何查询正在运行的JVM以查明这些参数是什么。



理想情况下,我想请查看虚拟机自动选择的各种与GC相关的-XX选项的值。如果有的话,我可以开始调整基准。

class =h2_lin>解决方案

查看 HotSpotDiagnosticMBean



以下示例将输出选项的值以及值是DEFAULT还是VM_CREATION:

  import java.lang.management.ManagementFactory; 

import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;

public class HotSpotTest {

public static void main(String [] args)throws Exception {
printHotSpotOption(MaxHeapFreeRatio);
printHotSpotOption(SurvivorRatio);
printHotSpotOptions();
}

private static void printHotSpotOption(String option)throws Exception {
ObjectName name = new ObjectName(com.sun.management:type=HotSpotDiagnostic);
String operationName =getVMOption;
Object [] params = new Object [] {option};
String [] signature = new String [] {String.class.getName()};
Object result = ManagementFactory.getPlatformMBeanServer()。invoke(name,operationName,params,signature);
CompositeDataSupport data =(CompositeDataSupport)结果;

System.out.println(option);
System.out.println( - Value:+ data.get(value));
System.out.println( - Origin:+ data.get(origin));
}

private static void printHotSpotOptions()throws Exception {
ObjectName name = new ObjectName(com.sun.management:type = HotSpotDiagnostic);
String attributeName =DiagnosticOptions;
Object result = ManagementFactory.getPlatformMBeanServer()。getAttribute(name,attributeName);
CompositeData [] array =(CompositeData [])result;
for(CompositeData d:array){
System.out.println(d.get(name));
System.out.println( - Value:+ d.get(value));
System.out.println( - Origin:+ d.get(origin));
}
}
}


I'm still investigating issues I have with GC tuning (see prior question), which involves lots of reading and experimentation.

Sun Java5+ JVMs attempt to automatically select the optimal GC strategy and parameters based on their environment, which is great, but I can't figure out how to query the running JVM to find out what those parameters are.

Ideally, I'd like to see what values of the various GC-related -XX options are being used, as selected automatically by the VM. If I had that, I could have a baseline to begin tweaking.

Anyone know to recover these values from a running VM?

解决方案

Check out the HotSpotDiagnosticMBean

The following example will print out the value of an option as well as whether the value is DEFAULT or VM_CREATION:

import java.lang.management.ManagementFactory;

import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;

public class HotSpotTest {

    public static void main(String [] args) throws Exception {
        printHotSpotOption("MaxHeapFreeRatio");
        printHotSpotOption("SurvivorRatio");
        printHotSpotOptions();
    }

    private static void printHotSpotOption(String option) throws Exception {
        ObjectName name = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
        String operationName = "getVMOption";
        Object [] params = new Object [] {option};
        String [] signature = new String[] {String.class.getName()};
        Object result = ManagementFactory.getPlatformMBeanServer().invoke(name, operationName, params, signature);
        CompositeDataSupport data = (CompositeDataSupport) result;

        System.out.println(option);
        System.out.println("- Value: "+data.get("value"));
        System.out.println("- Origin: "+data.get("origin"));
    }

    private static void printHotSpotOptions() throws Exception {
        ObjectName name = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
        String attributeName = "DiagnosticOptions";
        Object result = ManagementFactory.getPlatformMBeanServer().getAttribute(name, attributeName);
        CompositeData [] array = (CompositeData[]) result;
        for (CompositeData d : array) {
            System.out.println(d.get("name"));
            System.out.println("- Value: "+d.get("value"));
            System.out.println("- Origin: "+d.get("origin"));
        }
    }
}

这篇关于运行JVM的GC参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆