1 /*
  2  * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 package compiler.valhalla.inlinetypes;
 25 
 26 import jdk.test.lib.Utils;
 27 import compiler.lib.ir_framework.Scenario;
 28 import compiler.lib.ir_framework.TestFramework;
 29 
 30 public class InlineTypes {
 31     public static final int  rI = Utils.getRandomInstance().nextInt() % 1000;
 32     public static final long rL = Utils.getRandomInstance().nextLong() % 1000;
 33     public static final double rD = Utils.getRandomInstance().nextDouble() % 1000;
 34 
 35     public static final Scenario[] DEFAULT_SCENARIOS = {
 36             new Scenario(0,
 37                          "--add-exports", "java.base/jdk.internal.value=ALL-UNNAMED",
 38                          "-XX:+IgnoreUnrecognizedVMOptions",
 39                          "-XX:-UseACmpProfile",
 40                          "-XX:+AlwaysIncrementalInline",
 41                          "-XX:FlatArrayElementMaxOops=5",
 42                          "-XX:FlatArrayElementMaxSize=-1",
 43                          "-XX:-UseArrayLoadStoreProfile",
 44                          "-XX:InlineFieldMaxFlatSize=-1",
 45                          "-XX:+InlineTypePassFieldsAsArgs",
 46                          "-XX:+InlineTypeReturnedAsFields"
 47             ),
 48             new Scenario(1,
 49                          "--add-exports", "java.base/jdk.internal.value=ALL-UNNAMED",
 50                          "-XX:+IgnoreUnrecognizedVMOptions",
 51                          "-XX:-UseACmpProfile",
 52                          "-XX:-UseCompressedOops",
 53                          "-XX:FlatArrayElementMaxOops=5",
 54                          "-XX:FlatArrayElementMaxSize=-1",
 55                          "-XX:-UseArrayLoadStoreProfile",
 56                          "-XX:InlineFieldMaxFlatSize=-1",
 57                          "-XX:-InlineTypePassFieldsAsArgs",
 58                          "-XX:-InlineTypeReturnedAsFields"
 59             ),
 60             new Scenario(2,
 61                          "--add-exports", "java.base/jdk.internal.value=ALL-UNNAMED",
 62                          "-XX:+IgnoreUnrecognizedVMOptions",
 63                          "-XX:-UseACmpProfile",
 64                          "-XX:-UseCompressedOops",
 65                          "-XX:FlatArrayElementMaxOops=0",
 66                          "-XX:FlatArrayElementMaxSize=0",
 67                          "-XX:-UseArrayLoadStoreProfile",
 68                          "-XX:InlineFieldMaxFlatSize=-1",
 69                          "-XX:+InlineTypePassFieldsAsArgs",
 70                          "-XX:+InlineTypeReturnedAsFields",
 71                          "-XX:+StressInlineTypeReturnedAsFields"
 72             ),
 73             new Scenario(3,
 74                          "--add-exports", "java.base/jdk.internal.value=ALL-UNNAMED",
 75                          "-XX:+IgnoreUnrecognizedVMOptions",
 76                          "-DVerifyIR=false",
 77                          "-XX:+AlwaysIncrementalInline",
 78                          "-XX:FlatArrayElementMaxOops=0",
 79                          "-XX:FlatArrayElementMaxSize=0",
 80                          "-XX:InlineFieldMaxFlatSize=0",
 81                          "-XX:+InlineTypePassFieldsAsArgs",
 82                          "-XX:+InlineTypeReturnedAsFields"
 83             ),
 84             new Scenario(4,
 85                          "--add-exports", "java.base/jdk.internal.value=ALL-UNNAMED",
 86                          "-XX:+IgnoreUnrecognizedVMOptions",
 87                          "-DVerifyIR=false",
 88                          "-XX:FlatArrayElementMaxOops=-1",
 89                          "-XX:FlatArrayElementMaxSize=-1",
 90                          "-XX:InlineFieldMaxFlatSize=0",
 91                          "-XX:+InlineTypePassFieldsAsArgs",
 92                          "-XX:-InlineTypeReturnedAsFields",
 93                          "-XX:-ReduceInitialCardMarks"
 94             ),
 95             new Scenario(5,
 96                          "--add-exports", "java.base/jdk.internal.value=ALL-UNNAMED",
 97                          "-XX:+IgnoreUnrecognizedVMOptions",
 98                          "-XX:-UseACmpProfile",
 99                          "-XX:+AlwaysIncrementalInline",
100                          "-XX:FlatArrayElementMaxOops=5",
101                          "-XX:FlatArrayElementMaxSize=-1",
102                          "-XX:-UseArrayLoadStoreProfile",
103                          "-XX:InlineFieldMaxFlatSize=-1",
104                          "-XX:-InlineTypePassFieldsAsArgs",
105                          "-XX:-InlineTypeReturnedAsFields"
106             )
107     };
108 
109     public static TestFramework getFramework() {
110         StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
111         return new TestFramework(walker.getCallerClass()).setDefaultWarmup(251);
112     }
113 
114     static class IRNode {
115         // Regular expressions used to match nodes in the PrintIdeal output
116         protected static final String START = "(\\d+ (.*";
117         protected static final String MID = ".*)+ ===.*";
118         protected static final String END = ")";
119         // Generic allocation
120         protected static final String ALLOC_G  = "(.*call,static.*wrapper for: _new_instance_Java" + END;
121         protected static final String ALLOCA_G = "(.*call,static.*wrapper for: _new_array_Java" + END;
122         // Inline type allocation
123         protected static final String MYVALUE_ARRAY_KLASS = "\\[(precise )?compiler/valhalla/inlinetypes/MyValue";
124         protected static final String ALLOC  = "(.*precise compiler/valhalla/inlinetypes/MyValue.*\\R(.*(?i:mov|xorl|nop|spill).*\\R)*.*_new_instance_Java" + END;
125         protected static final String ALLOCA = "(.*" + MYVALUE_ARRAY_KLASS + ".*\\R(.*(?i:mov|xorl|nop|spill).*\\R)*.*_new_array_Java" + END;
126         protected static final String LOAD   = START + "Load(B|C|S|I|L|F|D|P|N)" + MID + "@compiler/valhalla/inlinetypes/.*" + END;
127         protected static final String LOADK  = START + "LoadK" + MID + END;
128         protected static final String STORE  = START + "Store(B|C|S|I|L|F|D|P|N)" + MID + "@compiler/valhalla/inlinetypes/.*" + END;
129         protected static final String LOOP   = START + "Loop" + MID + "" + END;
130         protected static final String COUNTEDLOOP = START + "CountedLoop\\b" + MID + "" + END;
131         protected static final String COUNTEDLOOP_MAIN = START + "CountedLoop\\b" + MID + "main" + END;
132         protected static final String TRAP   = START + "CallStaticJava" + MID + "uncommon_trap.*(unstable_if|predicate)" + END;
133         protected static final String LINKTOSTATIC = START + "CallStaticJava" + MID + "linkToStatic" + END;
134         protected static final String NPE = START + "CallStaticJava" + MID + "null_check" + END;
135         protected static final String CALL = START + "CallStaticJava" + MID + END;
136         protected static final String CALL_LEAF = "(CALL, runtime leaf|call_leaf,runtime)";
137         protected static final String CALL_LEAF_NOFP = "(CALL, runtime leaf nofp|call_leaf_nofp,runtime)";
138         protected static final String STORE_INLINE_FIELDS = START + "CallStaticJava" + MID + "store_inline_type_fields" + END;
139         protected static final String SCOBJ = "(.*# ScObj.*" + END;
140         protected static final String LOAD_UNKNOWN_INLINE = START + "CallStaticJava" + MID + "_load_unknown_inline" + END;
141         protected static final String STORE_UNKNOWN_INLINE = "(.*" + CALL_LEAF + ".*store_unknown_inline.*" + END;
142         protected static final String INLINE_ARRAY_NULL_GUARD = "(.*call,static.*wrapper for: uncommon_trap.*reason='null_check' action='none'.*" + END;
143         protected static final String INTRINSIC_SLOW_PATH = "(.*call,static.*wrapper for: uncommon_trap.*reason='intrinsic_or_type_checked_inlining'.*" + END;
144         protected static final String CLONE_INTRINSIC_SLOW_PATH = "(.*call,static.*java.lang.Object::clone.*" + END;
145         protected static final String CLASS_CHECK_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*class_check" + END;
146         protected static final String NULL_CHECK_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*null_check" + END;
147         protected static final String NULL_ASSERT_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*null_assert" + END;
148         protected static final String RANGE_CHECK_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*range_check" + END;
149         protected static final String UNHANDLED_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*unhandled" + END;
150         protected static final String PREDICATE_TRAP = START + "CallStaticJava" + MID + "uncommon_trap.*predicate" + END;
151         protected static final String MEMBAR = START + "MemBar" + MID + END;
152         protected static final String CHECKCAST_ARRAY = "(((?i:cmp|CLFI|CLR).*" + MYVALUE_ARRAY_KLASS + ".*:|.*(?i:mov|or).*" + MYVALUE_ARRAY_KLASS + ".*:.*\\R.*(cmp|CMP|CLR))" + END;
153         protected static final String CHECKCAST_ARRAYCOPY = "(.*" + CALL_LEAF_NOFP + ".*checkcast_arraycopy.*" + END;
154         protected static final String JLONG_ARRAYCOPY = "(.*" + CALL_LEAF_NOFP + ".*jlong_disjoint_arraycopy.*" + END;
155         protected static final String FIELD_ACCESS = "(.*Field: *" + END;
156         protected static final String SUBSTITUTABILITY_TEST = START + "CallStaticJava" + MID + "java.lang.runtime.PrimitiveObjectMethods::isSubstitutable" + END;
157         protected static final String CMPP = START + "(CmpP|CmpN)" + MID + "" + END;
158     }
159 }