< prev index next >

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

Print this page

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

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

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



 262         }
 263         if (DUMP_REPLAY) {
 264             addReplay();
 265         }
 266 
 267         // Collect the @Setup methods so we can reference them
 268         // from the test methods
 269         collectSetupMethods();
 270 
 271         // Make sure to first setup test methods and make them non-inlineable and only then process compile commands.
 272         setupDeclaredTests();
 273         processControlAnnotations(testClass);
 274         processHelperClasses();
 275         setupCheckedAndCustomRunTests();
 276 
 277         // All remaining tests are simple base tests without check or specific way to run them.
 278         addBaseTests();
 279         if (PRINT_VALID_IR_RULES) {
 280             irMatchRulePrinter.emit();
 281             VMInfoPrinter.emit();

 919         WHITE_BOX.deoptimizeMethod(m);
 920     }
 921 
 922     public static boolean isCompiled(Method m) {
 923         return compiledAtLevel(m, CompLevel.ANY) == TriState.Yes;
 924     }
 925 
 926     public static boolean isC1Compiled(Method m) {
 927         return compiledByC1(m) == TriState.Yes;
 928     }
 929 
 930     public static boolean isC2Compiled(Method m) {
 931         return compiledByC2(m) == TriState.Yes;
 932     }
 933 
 934     public static boolean isCompiledAtLevel(Method m, CompLevel compLevel) {
 935         return compiledAtLevel(m, compLevel) == TriState.Yes;
 936     }
 937 
 938     public static void assertDeoptimizedByC1(Method m) {
 939         if (notUnstableDeoptAssertion(m, CompLevel.C1_SIMPLE)) {
 940             TestRun.check(compiledByC1(m) != TriState.Yes || PER_METHOD_TRAP_LIMIT == 0 || !PROFILE_INTERPRETER,
 941                           m + " should have been deoptimized by C1");
 942         }
 943     }
 944 
 945     public static void assertDeoptimizedByC2(Method m) {
 946         if (notUnstableDeoptAssertion(m, CompLevel.C2)) {
 947             TestRun.check(compiledByC2(m) != TriState.Yes || PER_METHOD_TRAP_LIMIT == 0 || !PROFILE_INTERPRETER,
 948                           m + " should have been deoptimized by C2");
 949         }
 950     }
 951 
 952     /**
 953      * Some VM flags could make the deopt assertions unstable.
 954      */
 955     private static boolean notUnstableDeoptAssertion(Method m, CompLevel level) {
 956         return (USE_COMPILER && !XCOMP && !IGNORE_COMPILER_CONTROLS && !TEST_C1 &&

 957                 (!EXCLUDE_RANDOM || WHITE_BOX.isMethodCompilable(m, level.getValue(), false)));
 958     }
 959 
 960     public static void assertCompiledByC1(Method m) {
 961         TestRun.check(compiledByC1(m) != TriState.No, m + " should have been C1 compiled");
 962     }
 963 
 964     public static void assertCompiledByC2(Method m) {
 965         TestRun.check(compiledByC2(m) != TriState.No, m + " should have been C2 compiled");
 966     }
 967 
 968     public static void assertCompiledAtLevel(Method m, CompLevel level) {
 969         TestRun.check(compiledAtLevel(m, level) != TriState.No, m + " should have been compiled at level " + level.name());
 970     }
 971 
 972     public static void assertNotCompiled(Method m) {
 973         TestRun.check(!isC1Compiled(m), m + " should not have been compiled by C1");
 974         TestRun.check(!isC2Compiled(m), m + " should not have been compiled by C2");
 975     }
 976 

 992     }
 993 
 994     private static TriState compiledByC2(Method m) {
 995         return compiledAtLevel(m, CompLevel.C2);
 996     }
 997 
 998     private static TriState compiledAtLevel(Method m, CompLevel level) {
 999         if (WHITE_BOX.isMethodCompiled(m, false)) {
1000             switch (level) {
1001                 case C1_SIMPLE, C1_LIMITED_PROFILE, C1_FULL_PROFILE, C2 -> {
1002                     if (WHITE_BOX.getMethodCompilationLevel(m, false) == level.getValue()) {
1003                         return TriState.Yes;
1004                     }
1005                 }
1006                 case ANY -> {
1007                     return TriState.Yes;
1008                 }
1009                 default -> throw new TestRunException("compiledAtLevel() should not be called with " + level);
1010             }
1011         }
1012         if (!USE_COMPILER || XCOMP || TEST_C1 || IGNORE_COMPILER_CONTROLS || FLIP_C1_C2 ||
1013             (EXCLUDE_RANDOM && !WHITE_BOX.isMethodCompilable(m, level.getValue(), false))) {
1014             return TriState.Maybe;
1015         }
1016         return TriState.No;
1017     }
1018 }

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

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

 923         WHITE_BOX.deoptimizeMethod(m);
 924     }
 925 
 926     public static boolean isCompiled(Method m) {
 927         return compiledAtLevel(m, CompLevel.ANY) == TriState.Yes;
 928     }
 929 
 930     public static boolean isC1Compiled(Method m) {
 931         return compiledByC1(m) == TriState.Yes;
 932     }
 933 
 934     public static boolean isC2Compiled(Method m) {
 935         return compiledByC2(m) == TriState.Yes;
 936     }
 937 
 938     public static boolean isCompiledAtLevel(Method m, CompLevel compLevel) {
 939         return compiledAtLevel(m, compLevel) == TriState.Yes;
 940     }
 941 
 942     public static void assertDeoptimizedByC1(Method m) {
 943         if (isStableDeopt(m, CompLevel.C1_SIMPLE)) {
 944             TestRun.check(compiledByC1(m) != TriState.Yes, m + " should have been deoptimized by C1");

 945         }
 946     }
 947 
 948     public static void assertDeoptimizedByC2(Method m) {
 949         if (isStableDeopt(m, CompLevel.C2)) {
 950             TestRun.check(compiledByC2(m) != TriState.Yes, m + " should have been deoptimized by C2");

 951         }
 952     }
 953 
 954     /**
 955      * Some VM flags could make the deopt assertions unstable.
 956      */
 957     public static boolean isStableDeopt(Method m, CompLevel level) {
 958         return (USE_COMPILER && !XCOMP && !IGNORE_COMPILER_CONTROLS && !TEST_C1 &&
 959                 PER_METHOD_TRAP_LIMIT != 0 && PROFILE_INTERPRETER && !DEOPT_BARRIERS_ALOT &&
 960                 (!EXCLUDE_RANDOM || WHITE_BOX.isMethodCompilable(m, level.getValue(), false)));
 961     }
 962 
 963     public static void assertCompiledByC1(Method m) {
 964         TestRun.check(compiledByC1(m) != TriState.No, m + " should have been C1 compiled");
 965     }
 966 
 967     public static void assertCompiledByC2(Method m) {
 968         TestRun.check(compiledByC2(m) != TriState.No, m + " should have been C2 compiled");
 969     }
 970 
 971     public static void assertCompiledAtLevel(Method m, CompLevel level) {
 972         TestRun.check(compiledAtLevel(m, level) != TriState.No, m + " should have been compiled at level " + level.name());
 973     }
 974 
 975     public static void assertNotCompiled(Method m) {
 976         TestRun.check(!isC1Compiled(m), m + " should not have been compiled by C1");
 977         TestRun.check(!isC2Compiled(m), m + " should not have been compiled by C2");
 978     }
 979 

 995     }
 996 
 997     private static TriState compiledByC2(Method m) {
 998         return compiledAtLevel(m, CompLevel.C2);
 999     }
1000 
1001     private static TriState compiledAtLevel(Method m, CompLevel level) {
1002         if (WHITE_BOX.isMethodCompiled(m, false)) {
1003             switch (level) {
1004                 case C1_SIMPLE, C1_LIMITED_PROFILE, C1_FULL_PROFILE, C2 -> {
1005                     if (WHITE_BOX.getMethodCompilationLevel(m, false) == level.getValue()) {
1006                         return TriState.Yes;
1007                     }
1008                 }
1009                 case ANY -> {
1010                     return TriState.Yes;
1011                 }
1012                 default -> throw new TestRunException("compiledAtLevel() should not be called with " + level);
1013             }
1014         }
1015         if (!USE_COMPILER || XCOMP || TEST_C1 || IGNORE_COMPILER_CONTROLS || FLIP_C1_C2 || DEOPT_BARRIERS_ALOT ||
1016             (EXCLUDE_RANDOM && !WHITE_BOX.isMethodCompilable(m, level.getValue(), false))) {
1017             return TriState.Maybe;
1018         }
1019         return TriState.No;
1020     }
1021 }
< prev index next >