以下代码显示相同的结果:
import javax.management.MBeanException;
import javax.management.ReflectionException;
import com.sun.management.DiagnosticCommandMBean;
import sun.management.ManagementFactoryHelper;
@SuppressWarnings("restriction")
public class ClassHistogram {
public static void main(String[] args) throws MBeanException, ReflectionException {
DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
String[] emptyStringArgs = {};
Object[] dcmdArgs = { emptyStringArgs };
String[] signature = { String[].class.getName() };
System.out.println(dcmd.invoke("gcClassHistogram", dcmdArgs, signature));
}
}
参考可用命令:
https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html