Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/check/ClassAssertion.java
41161 views
/*1* Copyright (c) 2014, 2018, 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*/22package gc.g1.unloading.check;2324import sun.hotspot.WhiteBox;2526/**27* This assertion checks that class is alive using WhiteBox isClassAlive method.28*/29public class ClassAssertion extends Assertion {3031private String className;3233private boolean shouldBeAlive;3435private static long counterOfCheckedUnloaded = 0;3637private static long counterOfCheckedAlive = 0;3839public static long getCounterOfCheckedUnloaded() {40return counterOfCheckedUnloaded;41}4243public static long getCounterOfCheckedAlive() {44return counterOfCheckedAlive;45}4647public ClassAssertion(String className, boolean shouldBeAlive) {48this.shouldBeAlive = shouldBeAlive;49this.className = className;50}5152@Override53public void check() {54boolean isAlive = WhiteBox.getWhiteBox().isClassAlive(className);55if (isAlive != shouldBeAlive) {56if (isAlive) {57throw new RuntimeException("Class " + className + " was not unloaded! Failing test.");58} else {59throw new RuntimeException("Class " + className + " must live! Failing test.");60}61} else {62System.out.println(" Check OK, class " + className + ", isAlive = " + isAlive + ", shouldBeAlive = " + shouldBeAlive);63if (isAlive) {64counterOfCheckedAlive++;65} else {66counterOfCheckedUnloaded++;67}68}69}7071private static long numberOfChecksLimit = -1;7273static {74String s;75if ((s = System.getProperty("NumberOfChecksLimit")) != null) {76numberOfChecksLimit = Long.valueOf(s);77}78}7980}818283