< 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 HashMap<String, Method> setupMethodMap = 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 

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



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

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

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

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

  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 HashMap<String, Method> setupMethodMap = new HashMap<>();
 112     private final List<String> excludeList;
 113     private final List<String> testList;
 114     private Set<Class<?>> helperClasses = null; // Helper classes that contain framework annotations to be processed.
 115     private final IREncodingPrinter irMatchRulePrinter;
 116     private final Class<?> testClass;
 117     private final Map<Executable, CompLevel> forceCompileMap = new HashMap<>();
 118 
 119     private TestVM(Class<?> testClass) {
 120         TestRun.check(testClass != null, "Test class cannot be null");
 121         this.testClass = testClass;
 122         this.testList = createTestFilterList(TESTLIST, testClass);
 123         this.excludeList = createTestFilterList(EXCLUDELIST, testClass);
 124 

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

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

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

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

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