Mercurial > hg > graal-compiler
comparison test/compiler/whitebox/CompilerWhiteBoxTest.java @ 17616:d1760952ebdd
8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul
Reviewed-by: twisti
Contributed-by: anton.ivanov@oracle.com
author | iignatyev |
---|---|
date | Tue, 31 Dec 2013 19:26:57 +0400 |
parents | 600c83f8e6a5 |
children | bbfe3ac1471d 4ca6dc0799b6 d559dbbded7a |
comparison
equal
deleted
inserted
replaced
17615:6d2fe9c23878 | 17616:d1760952ebdd |
---|---|
29 import java.lang.reflect.Constructor; | 29 import java.lang.reflect.Constructor; |
30 import java.lang.reflect.Executable; | 30 import java.lang.reflect.Executable; |
31 import java.lang.reflect.Method; | 31 import java.lang.reflect.Method; |
32 import java.util.Objects; | 32 import java.util.Objects; |
33 import java.util.concurrent.Callable; | 33 import java.util.concurrent.Callable; |
34 import java.util.function.Function; | |
34 | 35 |
35 /** | 36 /** |
36 * Abstract class for WhiteBox testing of JIT. | 37 * Abstract class for WhiteBox testing of JIT. |
37 * | 38 * |
38 * @author igor.ignatyev@oracle.com | 39 * @author igor.ignatyev@oracle.com |
48 protected static int COMP_LEVEL_LIMITED_PROFILE = 2; | 49 protected static int COMP_LEVEL_LIMITED_PROFILE = 2; |
49 /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation & backedge counters + mdo */ | 50 /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation & backedge counters + mdo */ |
50 protected static int COMP_LEVEL_FULL_PROFILE = 3; | 51 protected static int COMP_LEVEL_FULL_PROFILE = 3; |
51 /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */ | 52 /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */ |
52 protected static int COMP_LEVEL_FULL_OPTIMIZATION = 4; | 53 protected static int COMP_LEVEL_FULL_OPTIMIZATION = 4; |
53 /** Maximal value for CompLeveL */ | 54 /** Maximal value for CompLevel */ |
54 protected static int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION; | 55 protected static int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION; |
55 | 56 |
56 /** Instance of WhiteBox */ | 57 /** Instance of WhiteBox */ |
57 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); | 58 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
58 /** Value of {@code -XX:CompileThreshold} */ | 59 /** Value of {@code -XX:CompileThreshold} */ |
73 /** count of invocation to triger compilation */ | 74 /** count of invocation to triger compilation */ |
74 protected static final int THRESHOLD; | 75 protected static final int THRESHOLD; |
75 /** count of invocation to triger OSR compilation */ | 76 /** count of invocation to triger OSR compilation */ |
76 protected static final long BACKEDGE_THRESHOLD; | 77 protected static final long BACKEDGE_THRESHOLD; |
77 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */ | 78 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */ |
78 protected static final String MODE | 79 protected static final String MODE = System.getProperty("java.vm.info"); |
79 = System.getProperty("java.vm.info"); | |
80 | 80 |
81 static { | 81 static { |
82 if (TIERED_COMPILATION) { | 82 if (TIERED_COMPILATION) { |
83 BACKEDGE_THRESHOLD = THRESHOLD = 150000; | 83 BACKEDGE_THRESHOLD = THRESHOLD = 150000; |
84 } else { | 84 } else { |
131 /** copy of is_c2_compile(int) from utilities/globalDefinitions.hpp */ | 131 /** copy of is_c2_compile(int) from utilities/globalDefinitions.hpp */ |
132 protected static boolean isC2Compile(int compLevel) { | 132 protected static boolean isC2Compile(int compLevel) { |
133 return compLevel == COMP_LEVEL_FULL_OPTIMIZATION; | 133 return compLevel == COMP_LEVEL_FULL_OPTIMIZATION; |
134 } | 134 } |
135 | 135 |
136 protected static void main( | |
137 Function<TestCase, CompilerWhiteBoxTest> constructor, | |
138 String[] args) { | |
139 if (args.length == 0) { | |
140 for (TestCase test : SimpleTestCase.values()) { | |
141 constructor.apply(test).runTest(); | |
142 } | |
143 } else { | |
144 for (String name : args) { | |
145 constructor.apply(SimpleTestCase.valueOf(name)).runTest(); | |
146 } | |
147 } | |
148 } | |
149 | |
136 /** tested method */ | 150 /** tested method */ |
137 protected final Executable method; | 151 protected final Executable method; |
138 protected final TestCase testCase; | 152 protected final TestCase testCase; |
139 | 153 |
140 /** | 154 /** |
143 * @param testCase object, that contains tested method and way to invoke it. | 157 * @param testCase object, that contains tested method and way to invoke it. |
144 */ | 158 */ |
145 protected CompilerWhiteBoxTest(TestCase testCase) { | 159 protected CompilerWhiteBoxTest(TestCase testCase) { |
146 Objects.requireNonNull(testCase); | 160 Objects.requireNonNull(testCase); |
147 System.out.println("TEST CASE:" + testCase.name()); | 161 System.out.println("TEST CASE:" + testCase.name()); |
148 method = testCase.executable; | 162 method = testCase.getExecutable(); |
149 this.testCase = testCase; | 163 this.testCase = testCase; |
150 } | 164 } |
151 | 165 |
152 /** | 166 /** |
153 * Template method for testing. Prints tested method's info before | 167 * Template method for testing. Prints tested method's info before |
202 throw new RuntimeException(method + " must be not osr_compiled"); | 216 throw new RuntimeException(method + " must be not osr_compiled"); |
203 } | 217 } |
204 if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) { | 218 if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) { |
205 throw new RuntimeException(method + " osr_comp_level must be == 0"); | 219 throw new RuntimeException(method + " osr_comp_level must be == 0"); |
206 } | 220 } |
207 } | 221 } |
208 | 222 |
209 /** | 223 /** |
210 * Checks, that {@linkplain #method} is compiled. | 224 * Checks, that {@linkplain #method} is compiled. |
211 * | 225 * |
212 * @throws RuntimeException if {@linkplain #method} isn't in compiler queue | 226 * @throws RuntimeException if {@linkplain #method} isn't in compiler queue |
219 if (WHITE_BOX.isMethodQueuedForCompilation(method)) { | 233 if (WHITE_BOX.isMethodQueuedForCompilation(method)) { |
220 System.err.printf("Warning: %s is still in queue after %dms%n", | 234 System.err.printf("Warning: %s is still in queue after %dms%n", |
221 method, System.currentTimeMillis() - start); | 235 method, System.currentTimeMillis() - start); |
222 return; | 236 return; |
223 } | 237 } |
224 if (!WHITE_BOX.isMethodCompiled(method, testCase.isOsr)) { | 238 if (!WHITE_BOX.isMethodCompiled(method, testCase.isOsr())) { |
225 throw new RuntimeException(method + " must be " | 239 throw new RuntimeException(method + " must be " |
226 + (testCase.isOsr ? "osr_" : "") + "compiled"); | 240 + (testCase.isOsr() ? "osr_" : "") + "compiled"); |
227 } | 241 } |
228 if (WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr) == 0) { | 242 if (WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr()) |
243 == 0) { | |
229 throw new RuntimeException(method | 244 throw new RuntimeException(method |
230 + (testCase.isOsr ? " osr_" : " ") | 245 + (testCase.isOsr() ? " osr_" : " ") |
231 + "comp_level must be != 0"); | 246 + "comp_level must be != 0"); |
232 } | 247 } |
233 } | 248 } |
234 | 249 |
235 protected final void deoptimize() { | 250 protected final void deoptimize() { |
236 WHITE_BOX.deoptimizeMethod(method, testCase.isOsr); | 251 WHITE_BOX.deoptimizeMethod(method, testCase.isOsr()); |
237 if (testCase.isOsr) { | 252 if (testCase.isOsr()) { |
238 WHITE_BOX.deoptimizeMethod(method, false); | 253 WHITE_BOX.deoptimizeMethod(method, false); |
239 } | 254 } |
240 } | 255 } |
241 | 256 |
242 protected final int getCompLevel() { | 257 protected final int getCompLevel() { |
243 return WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr); | 258 return WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr()); |
244 } | 259 } |
245 | 260 |
246 protected final boolean isCompilable() { | 261 protected final boolean isCompilable() { |
247 return WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, | 262 return WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, |
248 testCase.isOsr); | 263 testCase.isOsr()); |
249 } | 264 } |
250 | 265 |
251 protected final boolean isCompilable(int compLevel) { | 266 protected final boolean isCompilable(int compLevel) { |
252 return WHITE_BOX.isMethodCompilable(method, compLevel, testCase.isOsr); | 267 return WHITE_BOX |
268 .isMethodCompilable(method, compLevel, testCase.isOsr()); | |
253 } | 269 } |
254 | 270 |
255 protected final void makeNotCompilable() { | 271 protected final void makeNotCompilable() { |
256 WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY, | 272 WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY, |
257 testCase.isOsr); | 273 testCase.isOsr()); |
258 } | 274 } |
259 | 275 |
260 protected final void makeNotCompilable(int compLevel) { | 276 protected final void makeNotCompilable(int compLevel) { |
261 WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr); | 277 WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr()); |
262 } | 278 } |
263 | 279 |
264 /** | 280 /** |
265 * Waits for completion of background compilation of {@linkplain #method}. | 281 * Waits for completion of background compilation of {@linkplain #method}. |
266 */ | 282 */ |
296 WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, true)); | 312 WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, true)); |
297 System.out.printf("\tosr_compiled:\t%b%n", | 313 System.out.printf("\tosr_compiled:\t%b%n", |
298 WHITE_BOX.isMethodCompiled(method, true)); | 314 WHITE_BOX.isMethodCompiled(method, true)); |
299 System.out.printf("\tosr_comp_level:\t%d%n", | 315 System.out.printf("\tosr_comp_level:\t%d%n", |
300 WHITE_BOX.getMethodCompilationLevel(method, true)); | 316 WHITE_BOX.getMethodCompilationLevel(method, true)); |
301 System.out.printf("\tin_queue:\t%b%n", | 317 System.out.printf("\tin_queue:\t%b%n", |
302 WHITE_BOX.isMethodQueuedForCompilation(method)); | 318 WHITE_BOX.isMethodQueuedForCompilation(method)); |
303 System.out.printf("compile_queues_size:\t%d%n%n", | 319 System.out.printf("compile_queues_size:\t%d%n%n", |
304 WHITE_BOX.getCompileQueuesSize()); | 320 WHITE_BOX.getCompileQueuesSize()); |
305 } | 321 } |
306 | 322 |
309 */ | 325 */ |
310 protected abstract void test() throws Exception; | 326 protected abstract void test() throws Exception; |
311 | 327 |
312 /** | 328 /** |
313 * Tries to trigger compilation of {@linkplain #method} by call | 329 * Tries to trigger compilation of {@linkplain #method} by call |
314 * {@linkplain #testCase.callable} enough times. | 330 * {@linkplain TestCase#getCallable()} enough times. |
315 * | 331 * |
316 * @return accumulated result | 332 * @return accumulated result |
317 * @see #compile(int) | 333 * @see #compile(int) |
318 */ | 334 */ |
319 protected final int compile() { | 335 protected final int compile() { |
320 if (testCase.isOsr) { | 336 if (testCase.isOsr()) { |
321 return compile(1); | 337 return compile(1); |
322 } else { | 338 } else { |
323 return compile(THRESHOLD); | 339 return compile(THRESHOLD); |
324 } | 340 } |
325 } | 341 } |
326 | 342 |
327 /** | 343 /** |
328 * Tries to trigger compilation of {@linkplain #method} by call | 344 * Tries to trigger compilation of {@linkplain #method} by call |
329 * {@linkplain #testCase.callable} specified times. | 345 * {@linkplain TestCase#getCallable()} specified times. |
330 * | 346 * |
331 * @param count invocation count | 347 * @param count invocation count |
332 * @return accumulated result | 348 * @return accumulated result |
333 */ | 349 */ |
334 protected final int compile(int count) { | 350 protected final int compile(int count) { |
335 int result = 0; | 351 int result = 0; |
336 Integer tmp; | 352 Integer tmp; |
337 for (int i = 0; i < count; ++i) { | 353 for (int i = 0; i < count; ++i) { |
338 try { | 354 try { |
339 tmp = testCase.callable.call(); | 355 tmp = testCase.getCallable().call(); |
340 } catch (Exception e) { | 356 } catch (Exception e) { |
341 tmp = null; | 357 tmp = null; |
342 } | 358 } |
343 result += tmp == null ? 0 : tmp; | 359 result += tmp == null ? 0 : tmp; |
344 } | 360 } |
345 if (IS_VERBOSE) { | 361 if (IS_VERBOSE) { |
346 System.out.println("method was invoked " + count + " times"); | 362 System.out.println("method was invoked " + count + " times"); |
347 } | 363 } |
348 return result; | 364 return result; |
349 } | 365 } |
366 | |
367 /** | |
368 * Utility interface provides tested method and object to invoke it. | |
369 */ | |
370 public interface TestCase { | |
371 /** the name of test case */ | |
372 String name(); | |
373 | |
374 /** tested method */ | |
375 Executable getExecutable(); | |
376 | |
377 /** object to invoke {@linkplain #getExecutable()} */ | |
378 Callable<Integer> getCallable(); | |
379 | |
380 /** flag for OSR test case */ | |
381 boolean isOsr(); | |
382 } | |
350 } | 383 } |
351 | 384 |
352 /** | 385 enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase { |
353 * Utility structure containing tested method and object to invoke it. | |
354 */ | |
355 enum TestCase { | |
356 /** constructor test case */ | 386 /** constructor test case */ |
357 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false), | 387 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false), |
358 /** method test case */ | 388 /** method test case */ |
359 METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), | 389 METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), |
360 /** static method test case */ | 390 /** static method test case */ |
361 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false), | 391 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false), |
362 | |
363 /** OSR constructor test case */ | 392 /** OSR constructor test case */ |
364 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR, | 393 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR, |
365 Helper.OSR_CONSTRUCTOR_CALLABLE, true), | 394 Helper.OSR_CONSTRUCTOR_CALLABLE, true), |
366 /** OSR method test case */ | 395 /** OSR method test case */ |
367 OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), | 396 OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), |
368 /** OSR static method test case */ | 397 /** OSR static method test case */ |
369 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true); | 398 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true); |
370 | 399 |
371 /** tested method */ | 400 private final Executable executable; |
372 final Executable executable; | 401 private final Callable<Integer> callable; |
373 /** object to invoke {@linkplain #executable} */ | 402 private final boolean isOsr; |
374 final Callable<Integer> callable; | 403 |
375 /** flag for OSR test case */ | 404 private SimpleTestCase(Executable executable, Callable<Integer> callable, |
376 final boolean isOsr; | |
377 | |
378 private TestCase(Executable executable, Callable<Integer> callable, | |
379 boolean isOsr) { | 405 boolean isOsr) { |
380 this.executable = executable; | 406 this.executable = executable; |
381 this.callable = callable; | 407 this.callable = callable; |
382 this.isOsr = isOsr; | 408 this.isOsr = isOsr; |
409 } | |
410 | |
411 @Override | |
412 public Executable getExecutable() { | |
413 return executable; | |
414 } | |
415 | |
416 @Override | |
417 public Callable<Integer> getCallable() { | |
418 return callable; | |
419 } | |
420 | |
421 @Override | |
422 public boolean isOsr() { | |
423 return isOsr; | |
383 } | 424 } |
384 | 425 |
385 private static class Helper { | 426 private static class Helper { |
386 | 427 |
387 private static final Callable<Integer> CONSTRUCTOR_CALLABLE | 428 private static final Callable<Integer> CONSTRUCTOR_CALLABLE |
433 @Override | 474 @Override |
434 public Integer call() throws Exception { | 475 public Integer call() throws Exception { |
435 return osrStaticMethod(); | 476 return osrStaticMethod(); |
436 } | 477 } |
437 }; | 478 }; |
438 | |
439 | 479 |
440 private static final Constructor CONSTRUCTOR; | 480 private static final Constructor CONSTRUCTOR; |
441 private static final Constructor OSR_CONSTRUCTOR; | 481 private static final Constructor OSR_CONSTRUCTOR; |
442 private static final Method METHOD; | 482 private static final Method METHOD; |
443 private static final Method STATIC; | 483 private static final Method STATIC; |