1 /*
   2  * Copyright (c) 2017, 2018, 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.valuetypes;
  25 
  26 import compiler.whitebox.CompilerWhiteBoxTest;
  27 import jdk.test.lib.Asserts;
  28 import jdk.test.lib.management.InputArguments;
  29 import jdk.test.lib.Platform;
  30 import jdk.test.lib.process.ProcessTools;
  31 import jdk.test.lib.process.OutputAnalyzer;
  32 import jdk.test.lib.Utils;
  33 import sun.hotspot.WhiteBox;
  34 
  35 import java.lang.annotation.Retention;
  36 import java.lang.annotation.RetentionPolicy;
  37 import java.lang.annotation.Repeatable;
  38 import java.lang.invoke.*;
  39 import java.lang.reflect.Method;
  40 import java.util.ArrayList;
  41 import java.util.Arrays;
  42 import java.util.Hashtable;
  43 import java.util.LinkedHashMap;
  44 import java.util.List;
  45 import java.util.Map;
  46 import java.util.regex.Matcher;
  47 import java.util.regex.Pattern;
  48 import java.util.TreeMap;
  49 
  50 // Mark method as test
  51 @Retention(RetentionPolicy.RUNTIME)
  52 @Repeatable(Tests.class)
  53 @interface Test {
  54     // Regular expression used to match forbidden IR nodes
  55     // in the C2 IR emitted for this test.
  56     String failOn() default "";
  57     // Regular expressions used to match and count IR nodes.
  58     String[] match() default { };
  59     int[] matchCount() default { };
  60     int valid() default ValueTypeTest.AllFlags;
  61 }
  62 
  63 @Retention(RetentionPolicy.RUNTIME)
  64 @interface Tests {
  65     Test[] value();
  66 }
  67 
  68 // Force method inlining during compilation
  69 @Retention(RetentionPolicy.RUNTIME)
  70 @interface ForceInline { }
  71 
  72 // Prevent method inlining during compilation
  73 @Retention(RetentionPolicy.RUNTIME)
  74 @interface DontInline { }
  75 
  76 // Prevent method compilation
  77 @Retention(RetentionPolicy.RUNTIME)
  78 @interface DontCompile { }
  79 
  80 // Number of warmup iterations
  81 @Retention(RetentionPolicy.RUNTIME)
  82 @interface Warmup {
  83     int value();
  84 }
  85 
  86 public abstract class ValueTypeTest {
  87     // Random test values
  88     public static final int  rI = Utils.getRandomInstance().nextInt() % 1000;
  89     public static final long rL = Utils.getRandomInstance().nextLong() % 1000;
  90 
  91     // User defined settings
  92     private static final boolean PRINT_GRAPH = true;
  93     private static final boolean PRINT_TIMES = Boolean.parseBoolean(System.getProperty("PrintTimes", "false"));
  94     private static       boolean VERIFY_IR = Boolean.parseBoolean(System.getProperty("VerifyIR", "true"));
  95     private static final boolean VERIFY_VM = Boolean.parseBoolean(System.getProperty("VerifyVM", "false"));
  96     private static final String SCENARIOS = System.getProperty("Scenarios", "");
  97     private static final String TESTLIST = System.getProperty("Testlist", "");
  98     private static final String EXCLUDELIST = System.getProperty("Exclude", "");
  99     private static final int WARMUP = Integer.parseInt(System.getProperty("Warmup", "251"));
 100     private static final boolean DUMP_REPLAY = Boolean.parseBoolean(System.getProperty("DumpReplay", "false"));
 101 
 102     // Pre-defined settings
 103     private static final List<String> defaultFlags = Arrays.asList(
 104         "-XX:-BackgroundCompilation", "-XX:CICompilerCount=1",
 105         "-XX:+PrintCompilation", "-XX:+PrintIdeal", "-XX:+PrintOptoAssembly",
 106         "-XX:CompileCommand=quiet",
 107         "-XX:CompileCommand=compileonly,java.lang.invoke.*::*",
 108         "-XX:CompileCommand=compileonly,java.lang.Long::sum",
 109         "-XX:CompileCommand=compileonly,java.lang.Object::<init>",
 110         "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.*::*");
 111     private static final List<String> verifyFlags = Arrays.asList(
 112         "-XX:+VerifyOops", "-XX:+VerifyStack", "-XX:+VerifyLastFrame", "-XX:+VerifyBeforeGC", "-XX:+VerifyAfterGC",
 113         "-XX:+VerifyDuringGC", "-XX:+VerifyAdapterSharing", "-XX:+StressValueTypeReturnedAsFields");
 114 
 115     protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
 116     protected static final int ValueTypePassFieldsAsArgsOn = 0x1;
 117     protected static final int ValueTypePassFieldsAsArgsOff = 0x2;
 118     protected static final int ValueTypeArrayFlattenOn = 0x4;
 119     protected static final int ValueTypeArrayFlattenOff = 0x8;
 120     protected static final int ValueTypeReturnedAsFieldsOn = 0x10;
 121     protected static final int ValueTypeReturnedAsFieldsOff = 0x20;
 122     static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff | ValueTypeReturnedAsFieldsOn;
 123     protected static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
 124     protected static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
 125     protected static final boolean ValueTypeReturnedAsFields = (Boolean)WHITE_BOX.getVMFlag("ValueTypeReturnedAsFields");
 126     protected static final boolean NullableValueTypes = (Boolean)WHITE_BOX.getVMFlag("NullableValueTypes");
 127     protected static final int COMP_LEVEL_ANY = -2;
 128     protected static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
 129     protected static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
 130     protected static final boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
 131     protected static final boolean PRINT_IDEAL  = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
 132     protected static final boolean XCOMP = Platform.isComp();
 133 
 134     // Regular expressions used to match nodes in the PrintIdeal output
 135     protected static final String START = "(\\d+\\t(.*";
 136     protected static final String MID = ".*)+\\t===.*";
 137     protected static final String END = ")|";
 138     protected static final String ALLOC  = "(.*precise klass compiler/valhalla/valuetypes/MyValue.*\\R(.*(nop|spill).*\\R)*.*_new_instance_Java" + END;
 139     protected static final String ALLOCA = "(.*precise klass \\[Lcompiler/valhalla/valuetypes/MyValue.*\\R(.*(nop|spill).*\\R)*.*_new_array_Java" + END;
 140     protected static final String LOAD   = START + "Load(B|S|I|L|F|D|P|N)" + MID + "@compiler/valhalla/valuetypes/MyValue.*" + END;
 141     protected static final String LOADK  = START + "LoadK" + MID + END;
 142     protected static final String STORE  = START + "Store(B|S|I|L|F|D|P|N)" + MID + "@compiler/valhalla/valuetypes/MyValue.*" + END;
 143     protected static final String LOOP   = START + "Loop" + MID + "" + END;
 144     protected static final String TRAP   = START + "CallStaticJava" + MID + "uncommon_trap.*(unstable_if|predicate)" + END;
 145     protected static final String RETURN = START + "Return" + MID + "returns" + END;
 146     protected static final String LINKTOSTATIC = START + "CallStaticJava" + MID + "linkToStatic" + END;
 147     protected static final String NPE = START + "CallStaticJava" + MID + "null_check" + END;
 148     protected static final String CALL = START + "CallStaticJava" + MID + END;
 149     protected static final String STOREVALUETYPEFIELDS = START + "CallStaticJava" + MID + "store_value_type_fields" + END;
 150     protected static final String SCOBJ = "(.*# ScObj.*" + END;
 151 
 152     public static String[] concat(String prefix[], String... extra) {
 153         ArrayList<String> list = new ArrayList<String>();
 154         if (prefix != null) {
 155             for (String s : prefix) {
 156                 list.add(s);
 157             }
 158         }
 159         if (extra != null) {
 160             for (String s : extra) {
 161                 list.add(s);
 162             }
 163         }
 164 
 165         return list.toArray(new String[list.size()]);
 166     }
 167 
 168     /**
 169      * Override getNumScenarios and getVMParameters if you want to run with more than
 170      * the 5 built-in scenarios
 171      */
 172     public int getNumScenarios() {
 173         return 5;
 174     }
 175 
 176     /**
 177      * VM paramaters for the 5 built-in test scenarios. If your test needs to append
 178      * extra parameters for (some of) these scenarios, override getExtraVMParameters().
 179      */
 180     public String[] getVMParameters(int scenario) {
 181         switch (scenario) {
 182         case 0: return new String[] {
 183                 "-XX:+AlwaysIncrementalInline",
 184                 "-XX:ValueArrayElemMaxFlatOops=-1",
 185                 "-XX:ValueArrayElemMaxFlatSize=-1",
 186                 "-XX:+ValueArrayFlatten",
 187                 "-XX:ValueFieldMaxFlatSize=-1",
 188                 "-XX:+ValueTypePassFieldsAsArgs",
 189                 "-XX:+ValueTypeReturnedAsFields"};
 190         case 1: return new String[] {
 191                 "-XX:-UseCompressedOops",
 192                 "-XX:ValueArrayElemMaxFlatOops=-1",
 193                 "-XX:ValueArrayElemMaxFlatSize=-1",
 194                 "-XX:+ValueArrayFlatten",
 195                 "-XX:ValueFieldMaxFlatSize=-1",
 196                 "-XX:-ValueTypePassFieldsAsArgs",
 197                 "-XX:-ValueTypeReturnedAsFields"};
 198         case 2: return new String[] {
 199                 "-DVerifyIR=false",
 200                 "-XX:-UseCompressedOops",
 201                 "-XX:ValueArrayElemMaxFlatOops=0",
 202                 "-XX:ValueArrayElemMaxFlatSize=0",
 203                 "-XX:-ValueArrayFlatten",
 204                 "-XX:ValueFieldMaxFlatSize=0",
 205                 "-XX:+ValueTypePassFieldsAsArgs",
 206                 "-XX:+ValueTypeReturnedAsFields"};
 207         case 3: return new String[] {
 208                 "-DVerifyIR=false",
 209                 "-XX:+AlwaysIncrementalInline",
 210                 "-XX:ValueArrayElemMaxFlatOops=0",
 211                 "-XX:ValueArrayElemMaxFlatSize=0",
 212                 "-XX:ValueFieldMaxFlatSize=0",
 213                 "-XX:-ValueTypePassFieldsAsArgs",
 214                 "-XX:-ValueTypeReturnedAsFields"};
 215         case 4: return new String[] {
 216                 "-DVerifyIR=false",
 217                 "-XX:ValueArrayElemMaxFlatOops=-1",
 218                 "-XX:ValueArrayElemMaxFlatSize=-1",
 219                 "-XX:+ValueArrayFlatten",
 220                 "-XX:ValueFieldMaxFlatSize=0",
 221                 "-XX:+ValueTypePassFieldsAsArgs",
 222                 "-XX:-ValueTypeReturnedAsFields"};
 223         }
 224 
 225         return null;
 226     }
 227 
 228     /**
 229      * Override this method to provide extra parameters for selected scenarios
 230      */
 231     public String[] getExtraVMParameters(int scenario) {
 232         return null;
 233     }
 234 
 235     public static void main(String[] args) throws Throwable {
 236         if (args.length != 1) {
 237             throw new RuntimeException("Usage: @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea" +
 238                                        " -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions" +
 239                                        " -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla" +
 240                                        " compiler.valhalla.valuetypes.ValueTypeTest <YourTestMainClass>");
 241         }
 242         String testMainClassName = args[0];
 243         Class testMainClass = Class.forName(testMainClassName);
 244         ValueTypeTest test = (ValueTypeTest)testMainClass.newInstance();
 245         List<String> scenarios = null;
 246         if (!SCENARIOS.isEmpty()) {
 247            scenarios = Arrays.asList(SCENARIOS.split(","));
 248         }
 249         for (int i=0; i<test.getNumScenarios(); i++) {
 250             if (scenarios == null || scenarios.contains(Integer.toString(i))) {
 251                 System.out.println("Scenario #" + i + " -------- ");
 252                 String[] cmds = InputArguments.getVmInputArgs();
 253                 cmds = concat(cmds, test.getVMParameters(i));
 254                 cmds = concat(cmds, test.getExtraVMParameters(i));
 255                 cmds = concat(cmds, testMainClassName);
 256 
 257                 OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds);
 258                 String output = oa.getOutput();
 259                 oa.shouldHaveExitValue(0);
 260                 System.out.println(output);
 261             } else {
 262                 System.out.println("Scenario #" + i + " is skipped due to -Dscenarios=" + SCENARIOS);
 263             }
 264         }
 265     }
 266 
 267     protected ValueTypeTest() {
 268         List<String> list = null;
 269         List<String> exclude = null;
 270         if (!TESTLIST.isEmpty()) {
 271            list = Arrays.asList(TESTLIST.split(","));
 272         }
 273         if (!EXCLUDELIST.isEmpty()) {
 274            exclude = Arrays.asList(EXCLUDELIST.split(","));
 275         }
 276         // Gather all test methods and put them in Hashtable
 277         for (Method m : getClass().getDeclaredMethods()) {
 278             Test[] annos = m.getAnnotationsByType(Test.class);
 279             if (annos.length != 0 &&
 280                 ((list == null || list.contains(m.getName())) && (exclude == null || !exclude.contains(m.getName())))) {
 281                 tests.put(getClass().getSimpleName() + "::" + m.getName(), m);
 282             }
 283         }
 284     }
 285 
 286     protected void run(String[] args, Class<?>... classes) throws Throwable {
 287         if (args.length == 0) {
 288             // Spawn a new VM instance
 289             execute_vm();
 290         } else {
 291             // Execute tests
 292             run(classes);
 293         }
 294     }
 295 
 296     private void execute_vm() throws Throwable {
 297         Asserts.assertFalse(tests.isEmpty(), "no tests to execute");
 298         ArrayList<String> args = new ArrayList<String>(defaultFlags);
 299         String[] vmInputArgs = InputArguments.getVmInputArgs();
 300         if (VERIFY_IR) {
 301             for (String arg : vmInputArgs) {
 302                 if (arg.startsWith("-XX:CompileThreshold")) {
 303                     // Disable IR verification if
 304                     VERIFY_IR = false;
 305                 }
 306                 // Check if the JVM supports value type specific default arguments from the test's run commands
 307                 if (arg.startsWith("-XX:+ValueTypePassFieldsAsArgs") ||
 308                     arg.startsWith("-XX:+ValueTypeReturnedAsFields")) {
 309                     Boolean value = (Boolean)WHITE_BOX.getVMFlag(arg.substring(5));
 310                     if (!value) {
 311                         System.out.println("WARNING: could not enable " + arg.substring(5) + ". Skipping IR verification.");
 312                         VERIFY_IR = false;
 313                     }
 314                 } else if (arg.startsWith("-XX:-ValueTypePassFieldsAsArgs") ||
 315                            arg.startsWith("-XX:-ValueTypeReturnedAsFields")) {
 316                     Boolean value = (Boolean)WHITE_BOX.getVMFlag(arg.substring(5));
 317                     if (value) {
 318                         System.out.println("WARNING: could not disable " + arg.substring(5) + ". Skipping IR verification.");
 319                         VERIFY_IR = false;
 320                     }
 321                 }
 322             }
 323             // Always trap for exception throwing to not confuse IR verification
 324             args.add("-XX:-OmitStackTraceInFastThrow");
 325         }
 326         if (VERIFY_VM) {
 327             args.addAll(verifyFlags);
 328         }
 329         // Run tests in own process and verify output
 330         args.add(getClass().getName());
 331         args.add("run");
 332         // Spawn process with default JVM options from the test's run command
 333         String[] cmds = Arrays.copyOf(vmInputArgs, vmInputArgs.length + args.size());
 334         System.arraycopy(args.toArray(), 0, cmds, vmInputArgs.length, args.size());
 335         OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds);
 336         // If ideal graph printing is enabled/supported, verify output
 337         String output = oa.getOutput();
 338         oa.shouldHaveExitValue(0);
 339         if (VERIFY_IR) {
 340             if (output.contains("PrintIdeal enabled")) {
 341                 parseOutput(output);
 342             } else {
 343                 System.out.println(output);
 344                 System.out.println("WARNING: IR verification failed! Running with -Xint, -Xcomp or release build?");
 345             }
 346         }
 347     }
 348 
 349     private void parseOutput(String output) throws Exception {
 350         Pattern comp_re = Pattern.compile("\\n\\s+\\d+\\s+\\d+\\s+(%| )(s| )(!| )b(n| )\\s+\\S+\\.(?<name>[^.]+::\\S+)\\s+(?<osr>@ \\d+\\s+)?[(]\\d+ bytes[)]\\n");
 351         Matcher m = comp_re.matcher(output);
 352         Map<String,String> compilations = new LinkedHashMap<>();
 353         int prev = 0;
 354         String methodName = null;
 355         while (m.find()) {
 356             if (prev == 0) {
 357                 // Print header
 358                 System.out.print(output.substring(0, m.start()+1));
 359             } else if (methodName != null) {
 360                 compilations.put(methodName, output.substring(prev, m.start()+1));
 361             }
 362             if (m.group("osr") != null) {
 363                 methodName = null;
 364             } else {
 365                 methodName = m.group("name");
 366             }
 367             prev = m.end();
 368         }
 369         if (prev == 0) {
 370             // Print header
 371             System.out.print(output);
 372         } else if (methodName != null) {
 373             compilations.put(methodName, output.substring(prev));
 374         }
 375         // Iterate over compilation output
 376         for (String testName : compilations.keySet()) {
 377             Method test = tests.get(testName);
 378             if (test == null) {
 379                 // Skip helper methods
 380                 continue;
 381             }
 382             String graph = compilations.get(testName);
 383             if (PRINT_GRAPH) {
 384                 System.out.println("\nGraph for " + testName + "\n" + graph);
 385             }
 386             // Parse graph using regular expressions to determine if it contains forbidden nodes
 387             Test[] annos = test.getAnnotationsByType(Test.class);
 388             Test anno = null;
 389             for (Test a : annos) {
 390                 if ((a.valid() & ValueTypePassFieldsAsArgsOn) != 0 && ValueTypePassFieldsAsArgs) {
 391                     assert anno == null;
 392                     anno = a;
 393                 } else if ((a.valid() & ValueTypePassFieldsAsArgsOff) != 0 && !ValueTypePassFieldsAsArgs) {
 394                     assert anno == null;
 395                     anno = a;
 396                 } else if ((a.valid() & ValueTypeArrayFlattenOn) != 0 && ValueTypeArrayFlatten) {
 397                     assert anno == null;
 398                     anno = a;
 399                 } else if ((a.valid() & ValueTypeArrayFlattenOff) != 0 && !ValueTypeArrayFlatten) {
 400                     assert anno == null;
 401                     anno = a;
 402                 } else if ((a.valid() & ValueTypeReturnedAsFieldsOn) != 0 && ValueTypeReturnedAsFields) {
 403                     assert anno == null;
 404                     anno = a;
 405                 } else if ((a.valid() & ValueTypeReturnedAsFieldsOff) != 0 && !ValueTypeReturnedAsFields) {
 406                     assert anno == null;
 407                     anno = a;
 408                 }
 409             }
 410             assert anno != null;
 411             String regexFail = anno.failOn();
 412             if (!regexFail.isEmpty()) {
 413                 Pattern pattern = Pattern.compile(regexFail.substring(0, regexFail.length()-1));
 414                 Matcher matcher = pattern.matcher(graph);
 415                 boolean found = matcher.find();
 416                 Asserts.assertFalse(found, "Graph for '" + testName + "' contains forbidden node:\n" + (found ? matcher.group() : ""));
 417             }
 418             String[] regexMatch = anno.match();
 419             int[] matchCount = anno.matchCount();
 420             for (int i = 0; i < regexMatch.length; ++i) {
 421                 Pattern pattern = Pattern.compile(regexMatch[i].substring(0, regexMatch[i].length()-1));
 422                 Matcher matcher = pattern.matcher(graph);
 423                 int count = 0;
 424                 String nodes = "";
 425                 while (matcher.find()) {
 426                     count++;
 427                     nodes += matcher.group() + "\n";
 428                 }
 429                 if (matchCount[i] < 0) {
 430                     Asserts.assertLTE(Math.abs(matchCount[i]), count, "Graph for '" + testName + "' contains different number of match nodes:\n" + nodes);
 431                 } else {
 432                     Asserts.assertEQ(matchCount[i], count, "Graph for '" + testName + "' contains different number of match nodes:\n" + nodes);
 433                 }
 434             }
 435             tests.remove(testName);
 436             System.out.println(testName + " passed");
 437         }
 438         // Check if all tests were compiled
 439         if (tests.size() != 0) {
 440             for (String name : tests.keySet()) {
 441                 System.out.println("Test '" + name + "' not compiled!");
 442             }
 443             throw new RuntimeException("Not all tests were compiled");
 444         }
 445     }
 446 
 447     private void setup(Class<?> clazz) {
 448         if (XCOMP) {
 449             // Don't control compilation if -Xcomp is enabled
 450             return;
 451         }
 452         if (DUMP_REPLAY) {
 453             // Generate replay compilation files
 454             String directive = "[{ match: \"*.*\", DumpReplay: true }]";
 455             if (WHITE_BOX.addCompilerDirective(directive) != 1) {
 456                 throw new RuntimeException("Failed to add compiler directive");
 457             }
 458         }
 459 
 460         Method[] methods = clazz.getDeclaredMethods();
 461         for (Method m : methods) {
 462             if (m.isAnnotationPresent(Test.class)) {
 463                 // Don't inline tests
 464                 WHITE_BOX.testSetDontInlineMethod(m, true);
 465             }
 466             if (m.isAnnotationPresent(DontCompile.class)) {
 467                 WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_ANY, true);
 468                 WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_ANY, false);
 469                 WHITE_BOX.testSetDontInlineMethod(m, true);
 470             }
 471             if (m.isAnnotationPresent(ForceInline.class)) {
 472                 WHITE_BOX.testSetForceInlineMethod(m, true);
 473             } else if (m.isAnnotationPresent(DontInline.class)) {
 474                 WHITE_BOX.testSetDontInlineMethod(m, true);
 475             }
 476         }
 477 
 478         // Compile class initializers
 479         WHITE_BOX.enqueueInitializerForCompilation(clazz, COMP_LEVEL_FULL_OPTIMIZATION);
 480     }
 481 
 482     private void run(Class<?>... classes) throws Exception {
 483         if (USE_COMPILER && PRINT_IDEAL && !XCOMP) {
 484             System.out.println("PrintIdeal enabled");
 485         }
 486         System.out.format("rI = %d, rL = %d\n", rI, rL);
 487 
 488         setup(getClass());
 489         for (Class<?> clazz : classes) {
 490             setup(clazz);
 491         }
 492 
 493         // Execute tests
 494         TreeMap<Long, String> durations = PRINT_TIMES ? new TreeMap<Long, String>() : null;
 495         for (Method test : tests.values()) {
 496             long startTime = System.nanoTime();
 497             Method verifier = getClass().getMethod(test.getName() + "_verifier", boolean.class);
 498             // Warmup using verifier method
 499             Warmup anno = test.getAnnotation(Warmup.class);
 500             int warmup = anno == null ? WARMUP : anno.value();
 501             for (int i = 0; i < warmup; ++i) {
 502                 verifier.invoke(this, true);
 503             }
 504             // Trigger compilation
 505             WHITE_BOX.enqueueMethodForCompilation(test, COMP_LEVEL_FULL_OPTIMIZATION);
 506             Asserts.assertTrue(!USE_COMPILER || WHITE_BOX.isMethodCompiled(test, false), test + " not compiled");
 507             // Check result
 508             verifier.invoke(this, false);
 509             if (PRINT_TIMES) {
 510                 long endTime = System.nanoTime();
 511                 long duration = (endTime - startTime);
 512                 durations.put(duration, test.getName());
 513             }
 514         }
 515 
 516         // Print execution times
 517         if (PRINT_TIMES) {
 518           System.out.println("\n\nTest execution times:");
 519           for (Map.Entry<Long, String> entry : durations.entrySet()) {
 520               System.out.format("%-10s%15d ns\n", entry.getValue() + ":", entry.getKey());
 521           }
 522         }
 523     }
 524 }