|
Java example source code file (GcInfoCompositeType.java)
The GcInfoCompositeType.java Java example source code/* * Copyright (c) 2006, 2013 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6396794 * @summary Check that LastGcInfo contents are reasonable * @author Eamonn McManus * @run main/othervm -XX:-ExplicitGCInvokesConcurrent GcInfoCompositeType */ // Passing "-XX:-ExplicitGCInvokesConcurrent" to force System.gc() // run on foreground when CMS is used and prevent situations when "GcInfo" // is missing even though System.gc() was successfuly processed. import java.util.*; import java.lang.management.*; import java.lang.reflect.*; import javax.management.*; import javax.management.openmbean.*; import com.sun.management.GcInfo; public class GcInfoCompositeType { private static int tested = 0; public static void main(String[] args) throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName gcMXBeanPattern = new ObjectName("java.lang:type=GarbageCollector,*"); Set<ObjectName> names = mbs.queryNames(gcMXBeanPattern, null); if (names.isEmpty()) throw new Exception("Test incorrect: no GC MXBeans"); System.gc(); for (ObjectName n : names) tested += test(mbs, n); if (tested == 0) throw new Exception("No MXBeans were tested"); System.out.println("Test passed"); } private static int test(MBeanServer mbs, ObjectName n) throws Exception { System.out.println("Testing " + n); MBeanInfo mbi = mbs.getMBeanInfo(n); MBeanAttributeInfo lastGcAI = null; for (MBeanAttributeInfo mbai : mbi.getAttributes()) { if (mbai.getName().equals("LastGcInfo")) { lastGcAI = mbai; break; } } if (lastGcAI == null) throw new Exception("No LastGcInfo attribute"); CompositeType declaredType = (CompositeType) lastGcAI.getDescriptor().getFieldValue("openType"); checkType(declaredType); CompositeData cd = (CompositeData) mbs.getAttribute(n, "LastGcInfo"); if (cd == null) { System.out.println("Value of attribute null"); return 0; } else return checkType(cd.getCompositeType()); } private static int checkType(CompositeType ct) throws Exception { Method[] methods = GcInfo.class.getMethods(); Set<String> getters = new TreeSet Other Java examples (source code examples)Here is a short list of links related to this Java GcInfoCompositeType.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.