< 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         }
270         TestFormat.throwIfAnyFailures();
271         declaredTests.clear();
272         testMethodMap.clear();
273     }
274 

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

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

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

 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         }
274         TestFormat.throwIfAnyFailures();
275         declaredTests.clear();
276         testMethodMap.clear();
277     }
278 

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 (isStableDeopt(m, CompLevel.C1_SIMPLE)) {
899             TestRun.check(compiledByC1(m) != TriState.Yes, m + " should have been deoptimized by C1");

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

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

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