Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.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.driver.IRMatcher;26import compiler.lib.ir_framework.shared.*;27import jdk.test.lib.Platform;28import sun.hotspot.WhiteBox;2930import java.util.ArrayList;31import java.util.List;3233/**34* This class provides default regex strings that can be used in {@link IR @IR} annotations to specify IR constraints.35* <p>36* There are two types of default regexes:37* <ul>38* <li><p>Standalone regexes: Use them directly.</li>39* <li><p>Composite regexes: Their names contain "{@code _OF}" and expect another string in a list in40* {@link IR#failOn()} and {@link IR#counts()}. They cannot be use as standalone regex and will result in a41* {@link TestFormatException} when doing so.</li>42* </ul>43*44* @see IR45*/46public class IRNode {47private static final String START = "(\\d+(\\s){2}(";48private static final String MID = ".*)+(\\s){2}===.*";49private static final String END = ")";50private static final String COMPOSITE_PREFIX = "#PRE#"; // Prefix for regexes that require an additional user-defined string.51private static final String IS_REPLACED = "#IS_REPLACED#"; // Is replaced by an additional user-defined string.52private static final String STORE_OF_CLASS_POSTFIX = "(:|\\+)\\S* \\*" + END;53private static final String LOAD_OF_CLASS_POSTFIX = "(:|\\+)\\S* \\*" + END;5455public static final String ALLOC = "(.*precise klass .*\\R((.*(?i:mov|xorl|nop|spill).*|\\s*|.*LGHI.*)\\R)*.*(?i:call,static).*wrapper for: _new_instance_Java" + END;56public static final String ALLOC_OF = COMPOSITE_PREFIX + "(.*precise klass .*" + IS_REPLACED + ":.*\\R((.*(?i:mov|xorl|nop|spill).*|\\s*|.*LGHI.*)\\R)*.*(?i:call,static).*wrapper for: _new_instance_Java" + END;57public static final String ALLOC_ARRAY = "(.*precise klass \\[L.*\\R((.*(?i:mov|xor|nop|spill).*|\\s*|.*LGHI.*)\\R)*.*(?i:call,static).*wrapper for: _new_array_Java" + END;58public static final String ALLOC_ARRAY_OF = COMPOSITE_PREFIX + "(.*precise klass \\[L.*" + IS_REPLACED + ";:.*\\R((.*(?i:mov|xorl|nop|spill).*|\\s*|.*LGHI.*)\\R)*.*(?i:call,static).*wrapper for: _new_array_Java" + END;5960public static final String CHECKCAST_ARRAY = "(((?i:cmp|CLFI|CLR).*precise klass \\[.*;:|.*(?i:mov|or).*precise klass \\[.*;:.*\\R.*(cmp|CMP|CLR))" + END;61public static final String CHECKCAST_ARRAY_OF = COMPOSITE_PREFIX + "(((?i:cmp|CLFI|CLR).*precise klass \\[.*" + IS_REPLACED + ";:|.*(?i:mov|or).*precise klass \\[.*" + IS_REPLACED + ";:.*\\R.*(cmp|CMP|CLR))" + END;62// Does not work on s390 (a rule containing this regex will be skipped on s390).63public static final String CHECKCAST_ARRAYCOPY = "(.*((?i:call_leaf_nofp,runtime)|CALL,\\s?runtime leaf nofp|BCTRL.*.leaf call).*checkcast_arraycopy.*" + END;6465public static final String FIELD_ACCESS = "(.*Field: *" + END;6667public static final String STORE = START + "Store(B|C|S|I|L|F|D|P|N)" + MID + END;68public static final String STORE_B = START + "StoreB" + MID + END; // Store to boolean is also mapped to byte69public static final String STORE_C = START + "StoreC" + MID + END;70public static final String STORE_I = START + "StoreI" + MID + END; // Store to short is also mapped to int71public static final String STORE_L = START + "StoreL" + MID + END;72public static final String STORE_F = START + "StoreF" + MID + END;73public static final String STORE_D = START + "StoreD" + MID + END;74public static final String STORE_P = START + "StoreP" + MID + END;75public static final String STORE_N = START + "StoreN" + MID + END;76public static final String STORE_OF_CLASS = COMPOSITE_PREFIX + START + "Store(B|C|S|I|L|F|D|P|N)" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;77public static final String STORE_B_OF_CLASS = COMPOSITE_PREFIX + START + "StoreB" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;78public static final String STORE_C_OF_CLASS = COMPOSITE_PREFIX + START + "StoreC" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;79public static final String STORE_I_OF_CLASS = COMPOSITE_PREFIX + START + "StoreI" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;80public static final String STORE_L_OF_CLASS = COMPOSITE_PREFIX + START + "StoreL" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;81public static final String STORE_F_OF_CLASS = COMPOSITE_PREFIX + START + "StoreF" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;82public static final String STORE_D_OF_CLASS = COMPOSITE_PREFIX + START + "StoreD" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;83public static final String STORE_P_OF_CLASS = COMPOSITE_PREFIX + START + "StoreP" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;84public static final String STORE_N_OF_CLASS = COMPOSITE_PREFIX + START + "StoreN" + MID + "@\\S*" + IS_REPLACED + STORE_OF_CLASS_POSTFIX;85public static final String STORE_OF_FIELD = COMPOSITE_PREFIX + START + "Store(B|C|S|I|L|F|D|P|N)" + MID + "@.*name=" + IS_REPLACED + ",.*" + END;8687public static final String LOAD = START + "Load(B|UB|S|US|I|L|F|D|P|N)" + MID + END;88public static final String LOAD_B = START + "LoadB" + MID + END;89public static final String LOAD_UB = START + "LoadUB" + MID + END; // Load from boolean90public static final String LOAD_S = START + "LoadS" + MID + END;91public static final String LOAD_US = START + "LoadUS" + MID + END; // Load from char92public static final String LOAD_I = START + "LoadI" + MID + END;93public static final String LOAD_L = START + "LoadL" + MID + END;94public static final String LOAD_F = START + "LoadF" + MID + END;95public static final String LOAD_D = START + "LoadD" + MID + END;96public static final String LOAD_P = START + "LoadP" + MID + END;97public static final String LOAD_N = START + "LoadN" + MID + END;98public static final String LOAD_OF_CLASS = COMPOSITE_PREFIX + START + "Load(B|UB|S|US|I|L|F|D|P|N)" + MID + "@\\S*"+ IS_REPLACED + LOAD_OF_CLASS_POSTFIX;99public static final String LOAD_B_OF_CLASS = COMPOSITE_PREFIX + START + "LoadB" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;100public static final String LOAD_UB_OF_CLASS = COMPOSITE_PREFIX + START + "LoadUB" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;101public static final String LOAD_S_OF_CLASS = COMPOSITE_PREFIX + START + "LoadS" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;102public static final String LOAD_US_OF_CLASS = COMPOSITE_PREFIX + START + "LoadUS" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;103public static final String LOAD_I_OF_CLASS = COMPOSITE_PREFIX + START + "LoadI" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;104public static final String LOAD_L_OF_CLASS = COMPOSITE_PREFIX + START + "LoadL" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;105public static final String LOAD_F_OF_CLASS = COMPOSITE_PREFIX + START + "LoadF" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;106public static final String LOAD_D_OF_CLASS = COMPOSITE_PREFIX + START + "LoadD" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;107public static final String LOAD_P_OF_CLASS = COMPOSITE_PREFIX + START + "LoadP" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;108public static final String LOAD_N_OF_CLASS = COMPOSITE_PREFIX + START + "LoadN" + MID + "@\\S*" + IS_REPLACED + LOAD_OF_CLASS_POSTFIX;109public static final String LOAD_OF_FIELD = COMPOSITE_PREFIX + START + "Load(B|C|S|I|L|F|D|P|N)" + MID + "@.*name=" + IS_REPLACED + ",.*" + END;110public static final String LOAD_KLASS = START + "LoadK" + MID + END;111112public static final String LOOP = START + "Loop" + MID + END;113public static final String COUNTEDLOOP = START + "CountedLoop\\b" + MID + END;114public static final String COUNTEDLOOP_MAIN = START + "CountedLoop\\b" + MID + "main" + END;115public static final String OUTERSTRIPMINEDLOOP = START + "OuterStripMinedLoop\\b" + MID + END;116117public static final String CALL = START + "Call.*Java" + MID + END;118public static final String CALL_OF_METHOD = COMPOSITE_PREFIX + START + "Call.*Java" + MID + IS_REPLACED + " " + END;119public static final String DYNAMIC_CALL_OF_METHOD = COMPOSITE_PREFIX + START + "CallDynamicJava" + MID + IS_REPLACED + " " + END;120public static final String STATIC_CALL_OF_METHOD = COMPOSITE_PREFIX + START + "CallStaticJava" + MID + IS_REPLACED + " " + END;121public static final String TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*reason" + END;122public static final String PREDICATE_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*predicate" + END;123public static final String UNSTABLE_IF_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*unstable_if" + END;124public static final String CLASS_CHECK_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*class_check" + END;125public static final String NULL_CHECK_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*null_check" + END;126public static final String NULL_ASSERT_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*null_assert" + END;127public static final String RANGE_CHECK_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*range_check" + END;128public static final String UNHANDLED_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*unhandled" + END;129public static final String INTRINSIC_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*intrinsic" + END;130// Does not work for VM builds without JVMCI like x86_32 (a rule containing this regex will be skipped without having JVMCI built).131public static final String INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*intrinsic_or_type_checked_inlining" + END;132133public static final String SCOPE_OBJECT = "(.*# ScObj.*" + END;134public static final String MEMBAR = START + "MemBar" + MID + END;135public static final String MEMBAR_STORESTORE = START + "MemBarStoreStore" + MID + END;136public static final String SAFEPOINT = START + "SafePoint" + MID + END;137138public static final String MUL_L = START + "MulL" + MID + END;139public static final String POPCOUNT_L = START + "PopCountL" + MID + END;140141public static final String FAST_LOCK = START + "FastLock" + MID + END;142public static final String FAST_UNLOCK = START + "FastUnlock" + MID + END;143144/**145* Called by {@link IRMatcher} to merge special composite nodes together with additional user-defined input.146*/147public static List<String> mergeNodes(String[] nodes) {148List<String> mergedNodes = new ArrayList<>();149for (int i = 0; i < nodes.length; i += 2) {150String node = nodes[i];151if (node.startsWith(COMPOSITE_PREFIX)) {152if (i + 1 == nodes.length) {153reportMissingCompositeValue(node, i);154}155// Replace placeholder with user defined string.156node = node.substring(COMPOSITE_PREFIX.length()).replaceAll(IS_REPLACED, nodes[i + 1]);157} else {158i--; // No composite node, do not increment by 2.159}160mergedNodes.add(node);161}162return mergedNodes;163}164165/**166* Is default regex supported on current platform, used VM build, etc.?167* Throws a {@link CheckedTestFrameworkException} if the default regex is unsupported.168*/169public static void checkDefaultRegexSupported(String node) throws CheckedTestFrameworkException {170switch (node) {171case INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP -> {172if (!WhiteBox.getWhiteBox().isJVMCISupportedByGC()) {173throw new CheckedTestFrameworkException("INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP is unsupported in builds without JVMCI.");174}175}176case CHECKCAST_ARRAYCOPY -> {177if (Platform.isS390x()) {178throw new CheckedTestFrameworkException("CHECKCAST_ARRAYCOPY is unsupported on s390.");179}180}181// default: do nothing -> default regex is supported182}183}184185/**186* Mapping from string variable value to string variable name for better error reporting.187*/188private static void reportMissingCompositeValue(String node, int i) {189String varName = switch (node) {190case ALLOC_OF -> "ALLOC_OF";191case ALLOC_ARRAY_OF -> "ALLOC_ARRAY_OF";192case CHECKCAST_ARRAY_OF -> "CHECKCAST_ARRAY_OF";193case STORE_OF_CLASS -> "STORE_OF_CLASS";194case STORE_B_OF_CLASS -> "STORE_B_OF_CLASS";195case STORE_C_OF_CLASS -> "STORE_C_OF_CLASS";196case STORE_D_OF_CLASS -> "STORE_D_OF_CLASS";197case STORE_F_OF_CLASS -> "STORE_F_OF_CLASS";198case STORE_I_OF_CLASS -> "STORE_I_OF_CLASS";199case STORE_L_OF_CLASS -> "STORE_L_OF_CLASS";200case STORE_N_OF_CLASS -> "STORE_N_OF_CLASS";201case STORE_P_OF_CLASS -> "STORE_P_OF_CLASS";202case STORE_OF_FIELD -> "STORE_OF_FIELD";203case LOAD_OF_CLASS -> "LOAD_OF_CLASS";204case LOAD_B_OF_CLASS -> "LOAD_B_OF_CLASS";205case LOAD_UB_OF_CLASS -> "LOAD_UB_OF_CLASS";206case LOAD_D_OF_CLASS -> "LOAD_D_OF_CLASS";207case LOAD_F_OF_CLASS -> "LOAD_F_OF_CLASS";208case LOAD_I_OF_CLASS -> "LOAD_I_OF_CLASS";209case LOAD_L_OF_CLASS -> "LOAD_L_OF_CLASS";210case LOAD_N_OF_CLASS -> "LOAD_N_OF_CLASS";211case LOAD_P_OF_CLASS -> "LOAD_P_OF_CLASS";212case LOAD_S_OF_CLASS -> "LOAD_S_OF_CLASS";213case LOAD_US_OF_CLASS -> "LOAD_US_OF_CLASS";214case LOAD_OF_FIELD -> "LOAD_OF_FIELD";215default -> throw new TestFrameworkException("Missing variable mapping for " + node);216};217TestFormat.fail("Must provide additional value at index " + (i + 1) + " right after " + varName);218}219}220221222