Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/CompLevel.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.TestFrameworkException;26import compiler.lib.ir_framework.shared.TestRun;27import compiler.lib.ir_framework.shared.TestRunException;28import compiler.lib.ir_framework.test.TestVM;29import jdk.test.lib.Utils;3031import java.lang.reflect.Executable;32import java.util.HashMap;33import java.util.Map;3435/**36* Compilation levels used by the framework to initiate a compilation of a method. The compilation levels map to the used37* levels in HotSpot (apart from the framework specific values {@link #SKIP} and {@link #WAIT_FOR_COMPILATION} that cannot38* be found in HotSpot). The HotSpot specific levels must be in sync with hotspot/share/compiler/compilerDefinitions.hpp.39*40* <p>41* The compilation levels can be specified in the {@link Test}, {@link ForceCompile}, and42* {@link ForceCompileClassInitializer} annotation.43*44* @see Test45* @see ForceCompile46* @see ForceCompileClassInitializer47*/48public enum CompLevel {49/**50* Can only be used at {@link Test#compLevel()}. After the warm-up, the framework keeps invoking the test over a span51* of 10s (configurable by setting the property flag {@code -DWaitForCompilationTimeout}) until HotSpot compiles the52* {@link Test} method. If the method was not compiled after 10s, an exception is thrown. The framework does not wait53* for the compilation if the test VM is run with {@code -Xcomp}, {@code -XX:-UseCompiler}, or54* {@code -DExcludeRandom=true}.55*/56WAIT_FOR_COMPILATION(-4),57/**58* Can only be used at {@link Test#compLevel()}. Skip a compilation of the {@link Test @Test} method completely.59*/60SKIP(-3),61/**62* Use any compilation level depending on the usage:63* <ul>64* <li><p>{@link Test @Test}, {@link ForceCompile @ForceCompile}: Use the highest available compilation level65* which is usually C2.</li>66* <li><p>{@link DontCompile @DontCompile}: Prevents any compilation of the associated helper method.</li>67* </ul>68*/69ANY(-1),70/**71* Compilation level 1: C1 compilation without any profile information.72*/73C1_SIMPLE(1),74/**75* Compilation level 2: C1 compilation with limited profile information: Includes Invocation and backedge counters.76*/77C1_LIMITED_PROFILE(2),78/**79* Compilation level 3: C1 compilation with full profile information: Includes Invocation and backedge counters with MDO.80*/81C1_FULL_PROFILE(3),82/**83* Compilation level 4: C2 compilation with full optimizations.84*/85C2(4),8687;8889private static final Map<Integer, CompLevel> TYPES_BY_VALUE = new HashMap<>();90private final int value;9192static {93for (CompLevel level : CompLevel.values()) {94TYPES_BY_VALUE.put(level.value, level);95}96}9798CompLevel(int level) {99this.value = level;100}101102/**103* Get the compilation level as integer value. These will match the levels specified in HotSpot (if available).104*105* @return the compilation level as integer.106*/107public int getValue() {108return value;109}110111/**112* Get the compilation level enum from the specified integer.113*114* @param value the compilation level as integer.115* @throws TestRunException if {@code value} does not specify a valid compilation level.116* @return the compilation level enum for {@code value}.117*/118public static CompLevel forValue(int value) {119CompLevel level = TYPES_BY_VALUE.get(value);120TestRun.check(level != null, "Invalid compilation level " + value);121return level;122}123124/**125* Called by {@link TestFramework} to check if this compilation level is not part of the compiler.126*/127public boolean isNotCompilationLevelOfCompiler(Compiler c) {128return switch (c) {129case C1 -> !isC1();130case C2 -> this != C2;131default -> throw new TestFrameworkException("Should not be called with compiler " + c);132};133}134135/**136* Called by {@link TestFramework} to flip compilation levels.137*/138public CompLevel flipCompLevel() {139switch (this) {140case C1_SIMPLE, C1_LIMITED_PROFILE, C1_FULL_PROFILE -> {141return CompLevel.C2;142}143case C2 -> {144return CompLevel.C1_SIMPLE;145}146}147return this;148}149150/**151* Called by {@link TestFramework}. Return the compilation level when only allowing a compilation with the specified152* compiler.153*/154public CompLevel excludeCompilationRandomly(Executable ex) {155if (Utils.getRandomInstance().nextBoolean()) {156// No exclusion157return this;158}159Compiler compiler = TestVM.excludeRandomly(ex);160return switch (compiler) {161case ANY -> SKIP;162case C1 -> isC1() ? SKIP : this;163case C2 -> this == C2 ? SKIP : this;164};165}166167private boolean isC1() {168return this == C1_SIMPLE || this == C1_LIMITED_PROFILE || this == C1_FULL_PROFILE;169}170}171172173