< prev index next >

test/hotspot/jtreg/compiler/lib/ir_framework/test/TestVM.java

Print this page

 84             level = CompLevel.C1_SIMPLE;
 85         }
 86         TIERED_COMPILATION_STOP_AT_LEVEL = level;
 87     }
 88     public static final boolean TEST_C1 = (TIERED_COMPILATION && TIERED_COMPILATION_STOP_AT_LEVEL.getValue() < CompLevel.C2.getValue()) || CLIENT_VM;
 89 
 90     static final boolean XCOMP = Platform.isComp();
 91     static final boolean VERBOSE = Boolean.getBoolean("Verbose");
 92     private static final boolean PRINT_TIMES = Boolean.getBoolean("PrintTimes");
 93     public static final boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
 94     static final boolean EXCLUDE_RANDOM = Boolean.getBoolean("ExcludeRandom");
 95     private static final String TESTLIST = System.getProperty("Test", "");
 96     private static final String EXCLUDELIST = System.getProperty("Exclude", "");
 97     private static final boolean DUMP_REPLAY = Boolean.getBoolean("DumpReplay");
 98     private static final boolean GC_AFTER = Boolean.getBoolean("GCAfter");
 99     private static final boolean SHUFFLE_TESTS = Boolean.parseBoolean(System.getProperty("ShuffleTests", "true"));
100     // Use separate flag as VERIFY_IR could have been set by user but due to other flags it was disabled by flag VM.
101     private static final boolean PRINT_VALID_IR_RULES = Boolean.getBoolean("ShouldDoIRVerification");
102     protected static final long PER_METHOD_TRAP_LIMIT = (Long)WHITE_BOX.getVMFlag("PerMethodTrapLimit");
103     protected static final boolean PROFILE_INTERPRETER = (Boolean)WHITE_BOX.getVMFlag("ProfileInterpreter");

104     private static final boolean FLIP_C1_C2 = Boolean.getBoolean("FlipC1C2");
105     private static final boolean IGNORE_COMPILER_CONTROLS = Boolean.getBoolean("IgnoreCompilerControls");
106 
107     private final HashMap<Method, DeclaredTest> declaredTests = new HashMap<>();
108     private final List<AbstractTest> allTests = new ArrayList<>();
109     private final HashMap<String, Method> testMethodMap = new HashMap<>();
110     private final List<String> excludeList;
111     private final List<String> testList;
112     private Set<Class<?>> helperClasses = null; // Helper classes that contain framework annotations to be processed.
113     private final IREncodingPrinter irMatchRulePrinter;
114     private final Class<?> testClass;
115     private final Map<Executable, CompLevel> forceCompileMap = new HashMap<>();
116 
117     private TestVM(Class<?> testClass) {
118         TestRun.check(testClass != null, "Test class cannot be null");
119         this.testClass = testClass;
120         this.testList = createTestFilterList(TESTLIST, testClass);
121         this.excludeList = createTestFilterList(EXCLUDELIST, testClass);
122 
123         if (PRINT_VALID_IR_RULES) {

233      */
234     private static void runTestsOnSameVM(Class<?> testClass) {
235         if (testClass == null) {
236             StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
237             testClass = walker.getCallerClass();
238         }
239         TestVM framework = new TestVM(testClass);
240         framework.start();
241     }
242 
243     /**
244      * Once everything is initialized and set up, start collecting tests and executing them afterwards.
245      */
246     private void start() {
247         setupTests();
248         checkForcedCompilationsCompleted();
249         runTests();
250     }
251 
252     private void setupTests() {
253         for (Class<?> clazz : testClass.getDeclaredClasses()) {
254             checkAnnotationsInClass(clazz, "inner");



255         }
256         if (DUMP_REPLAY) {
257             addReplay();
258         }
259         // Make sure to first setup test methods and make them non-inlineable and only then process compile commands.
260         setupDeclaredTests();
261         processControlAnnotations(testClass);
262         processHelperClasses();
263         setupCheckedAndCustomRunTests();
264 
265         // All remaining tests are simple base tests without check or specific way to run them.
266         addBaseTests();
267         if (PRINT_VALID_IR_RULES) {
268             irMatchRulePrinter.emit();
269             VMInfoPrinter.emit();
270         }
271         TestFormat.throwIfAnyFailures();
272         declaredTests.clear();
273         testMethodMap.clear();
274     }

878         WHITE_BOX.deoptimizeMethod(m);
879     }
880 
881     public static boolean isCompiled(Method m) {
882         return compiledAtLevel(m, CompLevel.ANY) == TriState.Yes;
883     }
884 
885     public static boolean isC1Compiled(Method m) {
886         return compiledByC1(m) == TriState.Yes;
887     }
888 
889     public static boolean isC2Compiled(Method m) {
890         return compiledByC2(m) == TriState.Yes;
891     }
892 
893     public static boolean isCompiledAtLevel(Method m, CompLevel compLevel) {
894         return compiledAtLevel(m, compLevel) == TriState.Yes;
895     }
896 
897     public static void assertDeoptimizedByC1(Method m) {
898         if (notUnstableDeoptAssertion(m, CompLevel.C1_SIMPLE)) {
899             TestRun.check(compiledByC1(m) != TriState.Yes || PER_METHOD_TRAP_LIMIT == 0 || !PROFILE_INTERPRETER,
900                           m + " should have been deoptimized by C1");
901         }
902     }
903 
904     public static void assertDeoptimizedByC2(Method m) {
905         if (notUnstableDeoptAssertion(m, CompLevel.C2)) {
906             TestRun.check(compiledByC2(m) != TriState.Yes || PER_METHOD_TRAP_LIMIT == 0 || !PROFILE_INTERPRETER,
907                           m + " should have been deoptimized by C2");
908         }
909     }
910 
911     /**
912      * Some VM flags could make the deopt assertions unstable.
913      */
914     private static boolean notUnstableDeoptAssertion(Method m, CompLevel level) {
915         return (USE_COMPILER && !XCOMP && !IGNORE_COMPILER_CONTROLS && !TEST_C1 &&

916                 (!EXCLUDE_RANDOM || WHITE_BOX.isMethodCompilable(m, level.getValue(), false)));
917     }
918 
919     public static void assertCompiledByC1(Method m) {
920         TestRun.check(compiledByC1(m) != TriState.No, m + " should have been C1 compiled");
921     }
922 
923     public static void assertCompiledByC2(Method m) {
924         TestRun.check(compiledByC2(m) != TriState.No, m + " should have been C2 compiled");
925     }
926 
927     public static void assertCompiledAtLevel(Method m, CompLevel level) {
928         TestRun.check(compiledAtLevel(m, level) != TriState.No, m + " should have been compiled at level " + level.name());
929     }
930 
931     public static void assertNotCompiled(Method m) {
932         TestRun.check(!isC1Compiled(m), m + " should not have been compiled by C1");
933         TestRun.check(!isC2Compiled(m), m + " should not have been compiled by C2");
934     }
935 

951     }
952 
953     private static TriState compiledByC2(Method m) {
954         return compiledAtLevel(m, CompLevel.C2);
955     }
956 
957     private static TriState compiledAtLevel(Method m, CompLevel level) {
958         if (WHITE_BOX.isMethodCompiled(m, false)) {
959             switch (level) {
960                 case C1_SIMPLE, C1_LIMITED_PROFILE, C1_FULL_PROFILE, C2 -> {
961                     if (WHITE_BOX.getMethodCompilationLevel(m, false) == level.getValue()) {
962                         return TriState.Yes;
963                     }
964                 }
965                 case ANY -> {
966                     return TriState.Yes;
967                 }
968                 default -> throw new TestRunException("compiledAtLevel() should not be called with " + level);
969             }
970         }
971         if (!USE_COMPILER || XCOMP || TEST_C1 || IGNORE_COMPILER_CONTROLS || FLIP_C1_C2 ||
972             (EXCLUDE_RANDOM && !WHITE_BOX.isMethodCompilable(m, level.getValue(), false))) {
973             return TriState.Maybe;
974         }
975         return TriState.No;
976     }
977 }

 84             level = CompLevel.C1_SIMPLE;
 85         }
 86         TIERED_COMPILATION_STOP_AT_LEVEL = level;
 87     }
 88     public static final boolean TEST_C1 = (TIERED_COMPILATION && TIERED_COMPILATION_STOP_AT_LEVEL.getValue() < CompLevel.C2.getValue()) || CLIENT_VM;
 89 
 90     static final boolean XCOMP = Platform.isComp();
 91     static final boolean VERBOSE = Boolean.getBoolean("Verbose");
 92     private static final boolean PRINT_TIMES = Boolean.getBoolean("PrintTimes");
 93     public static final boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
 94     static final boolean EXCLUDE_RANDOM = Boolean.getBoolean("ExcludeRandom");
 95     private static final String TESTLIST = System.getProperty("Test", "");
 96     private static final String EXCLUDELIST = System.getProperty("Exclude", "");
 97     private static final boolean DUMP_REPLAY = Boolean.getBoolean("DumpReplay");
 98     private static final boolean GC_AFTER = Boolean.getBoolean("GCAfter");
 99     private static final boolean SHUFFLE_TESTS = Boolean.parseBoolean(System.getProperty("ShuffleTests", "true"));
100     // Use separate flag as VERIFY_IR could have been set by user but due to other flags it was disabled by flag VM.
101     private static final boolean PRINT_VALID_IR_RULES = Boolean.getBoolean("ShouldDoIRVerification");
102     protected static final long PER_METHOD_TRAP_LIMIT = (Long)WHITE_BOX.getVMFlag("PerMethodTrapLimit");
103     protected static final boolean PROFILE_INTERPRETER = (Boolean)WHITE_BOX.getVMFlag("ProfileInterpreter");
104     protected static final boolean DEOPT_BARRIERS_ALOT = (Boolean)WHITE_BOX.getVMFlag("DeoptimizeNMethodBarriersALot");
105     private static final boolean FLIP_C1_C2 = Boolean.getBoolean("FlipC1C2");
106     private static final boolean IGNORE_COMPILER_CONTROLS = Boolean.getBoolean("IgnoreCompilerControls");
107 
108     private final HashMap<Method, DeclaredTest> declaredTests = new HashMap<>();
109     private final List<AbstractTest> allTests = new ArrayList<>();
110     private final HashMap<String, Method> testMethodMap = new HashMap<>();
111     private final List<String> excludeList;
112     private final List<String> testList;
113     private Set<Class<?>> helperClasses = null; // Helper classes that contain framework annotations to be processed.
114     private final IREncodingPrinter irMatchRulePrinter;
115     private final Class<?> testClass;
116     private final Map<Executable, CompLevel> forceCompileMap = new HashMap<>();
117 
118     private TestVM(Class<?> testClass) {
119         TestRun.check(testClass != null, "Test class cannot be null");
120         this.testClass = testClass;
121         this.testList = createTestFilterList(TESTLIST, testClass);
122         this.excludeList = createTestFilterList(EXCLUDELIST, testClass);
123 
124         if (PRINT_VALID_IR_RULES) {

234      */
235     private static void runTestsOnSameVM(Class<?> testClass) {
236         if (testClass == null) {
237             StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
238             testClass = walker.getCallerClass();
239         }
240         TestVM framework = new TestVM(testClass);
241         framework.start();
242     }
243 
244     /**
245      * Once everything is initialized and set up, start collecting tests and executing them afterwards.
246      */
247     private void start() {
248         setupTests();
249         checkForcedCompilationsCompleted();
250         runTests();
251     }
252 
253     private void setupTests() {
254         // TODO remove this once JDK-8273591 is fixed
255         if (!IGNORE_COMPILER_CONTROLS) {
256             for (Class<?> clazz : testClass.getDeclaredClasses()) {
257                 checkAnnotationsInClass(clazz, "inner");
258             }
259         }
260         if (DUMP_REPLAY) {
261             addReplay();
262         }
263         // Make sure to first setup test methods and make them non-inlineable and only then process compile commands.
264         setupDeclaredTests();
265         processControlAnnotations(testClass);
266         processHelperClasses();
267         setupCheckedAndCustomRunTests();
268 
269         // All remaining tests are simple base tests without check or specific way to run them.
270         addBaseTests();
271         if (PRINT_VALID_IR_RULES) {
272             irMatchRulePrinter.emit();
273             VMInfoPrinter.emit();
274         }
275         TestFormat.throwIfAnyFailures();
276         declaredTests.clear();
277         testMethodMap.clear();
278     }

882         WHITE_BOX.deoptimizeMethod(m);
883     }
884 
885     public static boolean isCompiled(Method m) {
886         return compiledAtLevel(m, CompLevel.ANY) == TriState.Yes;
887     }
888 
889     public static boolean isC1Compiled(Method m) {
890         return compiledByC1(m) == TriState.Yes;
891     }
892 
893     public static boolean isC2Compiled(Method m) {
894         return compiledByC2(m) == TriState.Yes;
895     }
896 
897     public static boolean isCompiledAtLevel(Method m, CompLevel compLevel) {
898         return compiledAtLevel(m, compLevel) == TriState.Yes;
899     }
900 
901     public static void assertDeoptimizedByC1(Method m) {
902         if (isStableDeopt(m, CompLevel.C1_SIMPLE)) {
903             TestRun.check(compiledByC1(m) != TriState.Yes, m + " should have been deoptimized by C1");

904         }
905     }
906 
907     public static void assertDeoptimizedByC2(Method m) {
908         if (isStableDeopt(m, CompLevel.C2)) {
909             TestRun.check(compiledByC2(m) != TriState.Yes, m + " should have been deoptimized by C2");

910         }
911     }
912 
913     /**
914      * Some VM flags could make the deopt assertions unstable.
915      */
916     public static boolean isStableDeopt(Method m, CompLevel level) {
917         return (USE_COMPILER && !XCOMP && !IGNORE_COMPILER_CONTROLS && !TEST_C1 &&
918                 PER_METHOD_TRAP_LIMIT != 0 && PROFILE_INTERPRETER && !DEOPT_BARRIERS_ALOT &&
919                 (!EXCLUDE_RANDOM || WHITE_BOX.isMethodCompilable(m, level.getValue(), false)));
920     }
921 
922     public static void assertCompiledByC1(Method m) {
923         TestRun.check(compiledByC1(m) != TriState.No, m + " should have been C1 compiled");
924     }
925 
926     public static void assertCompiledByC2(Method m) {
927         TestRun.check(compiledByC2(m) != TriState.No, m + " should have been C2 compiled");
928     }
929 
930     public static void assertCompiledAtLevel(Method m, CompLevel level) {
931         TestRun.check(compiledAtLevel(m, level) != TriState.No, m + " should have been compiled at level " + level.name());
932     }
933 
934     public static void assertNotCompiled(Method m) {
935         TestRun.check(!isC1Compiled(m), m + " should not have been compiled by C1");
936         TestRun.check(!isC2Compiled(m), m + " should not have been compiled by C2");
937     }
938 

954     }
955 
956     private static TriState compiledByC2(Method m) {
957         return compiledAtLevel(m, CompLevel.C2);
958     }
959 
960     private static TriState compiledAtLevel(Method m, CompLevel level) {
961         if (WHITE_BOX.isMethodCompiled(m, false)) {
962             switch (level) {
963                 case C1_SIMPLE, C1_LIMITED_PROFILE, C1_FULL_PROFILE, C2 -> {
964                     if (WHITE_BOX.getMethodCompilationLevel(m, false) == level.getValue()) {
965                         return TriState.Yes;
966                     }
967                 }
968                 case ANY -> {
969                     return TriState.Yes;
970                 }
971                 default -> throw new TestRunException("compiledAtLevel() should not be called with " + level);
972             }
973         }
974         if (!USE_COMPILER || XCOMP || TEST_C1 || IGNORE_COMPILER_CONTROLS || FLIP_C1_C2 || DEOPT_BARRIERS_ALOT ||
975             (EXCLUDE_RANDOM && !WHITE_BOX.isMethodCompilable(m, level.getValue(), false))) {
976             return TriState.Maybe;
977         }
978         return TriState.No;
979     }
980 }
< prev index next >