Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/AbstractInfo.java
64507 views
/*1* Copyright (c) 2021, 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*/2223package compiler.lib.ir_framework;2425import compiler.lib.ir_framework.shared.TestRunException;26import compiler.lib.ir_framework.test.TestVM;27import jdk.test.lib.Utils;2829import java.lang.reflect.Method;30import java.util.Arrays;31import java.util.Random;32import java.util.stream.Collectors;3334/**35* Base info class which provides some useful utility methods and information about a test.36* <p>37* <b>Base tests</b> and <b>checked tests</b> use {@link TestInfo} while <b>custom run tests</b> use {@link RunInfo}.38*39* @see Test40* @see Check41* @see Run42*/43abstract public class AbstractInfo {44private static final Random RANDOM = Utils.getRandomInstance();4546protected final Class<?> testClass;47private boolean onWarmUp = true;4849AbstractInfo(Class<?> testClass) {50this.testClass = testClass;51}5253/**54* Get the initialized {@link Random} object.55*56* @return the random object.57*/58public Random getRandom() {59return RANDOM;60}6162/**63* Returns a boolean indicating if the framework is currently warming up the associated test.64*65* @return the warm-up status of the associated test.66*67* @see Warmup68*/69public boolean isWarmUp() {70return onWarmUp;71}7273/**74* Get the method object of the method {@code name} of class {@code c} with arguments {@code args}.75*76* @param c the class containing the method.77* @param name the name of the method.78* @param args the arguments of the method, leave empty if no arguments.79*80* @return the method object of the requested method.81*/82public Method getMethod(Class<?> c, String name, Class<?>... args) {83try {84return c.getMethod(name, args);85} catch (NoSuchMethodException e) {86String parameters = args == null || args.length == 0 ? "" :87" with arguments [" + Arrays.stream(args).map(Class::getName).collect(Collectors.joining(",")) + "]";88throw new TestRunException("Could not find method " + name + " in " + c + parameters, e);89}90}9192/**93* Get the method object of the method {@code name} of the test class with arguments {@code args}.94*95* @param name the name of the method in the test class.96* @param args the arguments of the method, leave empty if no arguments.97*98* @return the method object of the requested method in the test class.99*/100public Method getTestClassMethod(String name, Class<?>... args) {101return getMethod(testClass, name, args);102}103104/**105* Returns a boolean indicating if the test VM runs with flags that allow C2 compilations.106*107* @return {@code true} if C2 compilations are allowed;108* {@code false} otherwise (run with {@code -XX:TieredStopAtLevel={1,2,3}, -XX:-UseCompiler}).109*/110public boolean isC2CompilationEnabled() {111return TestVM.USE_COMPILER && !TestVM.TEST_C1;112}113114/**115* Called by {@link TestFramework} when the warm-up is finished. Should not be called by user code.116*/117public void setWarmUpFinished() {118onWarmUp = false;119}120}121122123