Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/HotspotClassLoadingMBean/GetInitializedClassCount.java
38840 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 485852226* @summary Basic unit test of HotspotClassLoadingMBean.getInitializedClassCount()27* @author Steve Bohne28* @run main/othervm -XX:+UsePerfData GetInitializedClassCount29*/3031/*32* This test is just a sanity check and does not check for the correct value.33*/3435import sun.management.*;3637public class GetInitializedClassCount {3839private static HotspotClassLoadingMBean mbean =40(HotspotClassLoadingMBean)ManagementFactoryHelper.getHotspotClassLoadingMBean();4142// Careful with these values.43private static final long MIN_VALUE_FOR_PASS = 1;44private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE;4546private static boolean trace = false;4748public static void main(String args[]) throws Exception {49if (args.length > 0 && args[0].equals("trace")) {50trace = true;51}5253long value = mbean.getInitializedClassCount();5455if (trace) {56System.out.println("Initialized class count: " + value);57}5859if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) {60throw new RuntimeException("Initialized class count " +61"illegal value: " + value + " " +62"(MIN = " + MIN_VALUE_FOR_PASS + "; " +63"MAX = " + MAX_VALUE_FOR_PASS + ")");64}6566// Initialize a class67Class.forName("ClassToInitialize0");6869long value2 = mbean.getInitializedClassCount();7071if (trace) {72System.out.println("Initialized class count2: " + value2);73}7475// If new count does not reflect that at least one class has76// been initialized, throw an exception. We don't check that77// _exactly_ one class has been initialized because another78// thread may (rarely) have also done some class initialization.79if (value2 < value + 1) {80throw new RuntimeException("Initialized class count " +81"did not increase " +82"(value = " + value + "; " +83"value2 = " + value2 + ")");84}8586System.out.println("Test passed.");87}88}8990class ClassToInitialize0 {91static int i = 0;92static {93i = 1;94}95}969798