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