Mercurial > hg > truffle
comparison graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java @ 12362:f53dc8bbb88c
refactored isReexecutable(), getKilledLocations() and canDeoptimize() out of MetaAccessProvider into ForeignCallsProvider (GRAAL-511)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 12 Oct 2013 00:31:37 +0200 |
parents | bba234a1670e |
children | f87c68d79f07 |
comparison
equal
deleted
inserted
replaced
12361:ec57cc36371e | 12362:f53dc8bbb88c |
---|---|
75 * <p> | 75 * <p> |
76 * These tests will be run by the {@code mx unittest} command. | 76 * These tests will be run by the {@code mx unittest} command. |
77 */ | 77 */ |
78 public abstract class GraalCompilerTest extends GraalTest { | 78 public abstract class GraalCompilerTest extends GraalTest { |
79 | 79 |
80 private final CodeCacheProvider codeCache; | 80 private final Providers providers; |
81 private final MetaAccessProvider metaAccess; | |
82 private final ConstantReflectionProvider constantReflection; | |
83 private final LoweringProvider lowerer; | |
84 private final Replacements replacements; | |
85 protected final Backend backend; | 81 protected final Backend backend; |
86 protected final Suites suites; | 82 protected final Suites suites; |
87 | 83 |
88 public GraalCompilerTest() { | 84 public GraalCompilerTest() { |
89 this.replacements = Graal.getRequiredCapability(Replacements.class); | 85 this.providers = GraalCompiler.getGraalProviders(); |
90 this.metaAccess = Graal.getRequiredCapability(MetaAccessProvider.class); | |
91 this.constantReflection = Graal.getRequiredCapability(ConstantReflectionProvider.class); | |
92 this.codeCache = Graal.getRequiredCapability(CodeCacheProvider.class); | |
93 this.lowerer = Graal.getRequiredCapability(LoweringProvider.class); | |
94 this.backend = Graal.getRequiredCapability(Backend.class); | 86 this.backend = Graal.getRequiredCapability(Backend.class); |
95 this.suites = Graal.getRequiredCapability(SuitesProvider.class).createSuites(); | 87 this.suites = Graal.getRequiredCapability(SuitesProvider.class).createSuites(); |
96 } | 88 } |
97 | 89 |
98 @BeforeClass | 90 @BeforeClass |
164 } | 156 } |
165 return result.toString(); | 157 return result.toString(); |
166 } | 158 } |
167 | 159 |
168 protected Providers getProviders() { | 160 protected Providers getProviders() { |
169 return new Providers(metaAccess, codeCache, constantReflection, lowerer, getReplacements()); | 161 return providers; |
170 } | 162 } |
171 | 163 |
172 protected CodeCacheProvider getCodeCache() { | 164 protected CodeCacheProvider getCodeCache() { |
173 return codeCache; | 165 return getProviders().getCodeCache(); |
174 } | 166 } |
175 | 167 |
176 protected ConstantReflectionProvider getConstantReflection() { | 168 protected ConstantReflectionProvider getConstantReflection() { |
177 return constantReflection; | 169 return getProviders().getConstantReflection(); |
170 } | |
171 | |
172 protected ForeignCallsProvider getForeignCalls() { | |
173 return getProviders().getForeignCalls(); | |
178 } | 174 } |
179 | 175 |
180 protected MetaAccessProvider getMetaAccess() { | 176 protected MetaAccessProvider getMetaAccess() { |
181 return metaAccess; | 177 return getProviders().getMetaAccess(); |
182 } | 178 } |
183 | 179 |
184 protected LoweringProvider getLowerer() { | 180 protected LoweringProvider getLowerer() { |
185 return lowerer; | 181 return getProviders().getLowerer(); |
186 } | 182 } |
187 | 183 |
188 /** | 184 /** |
189 * Parses a Java method to produce a graph. | 185 * Parses a Java method to produce a graph. |
190 * | 186 * |
345 | 341 |
346 protected Result executeActual(Method method, Object receiver, Object... args) { | 342 protected Result executeActual(Method method, Object receiver, Object... args) { |
347 before(method); | 343 before(method); |
348 Object[] executeArgs = argsWithReceiver(receiver, args); | 344 Object[] executeArgs = argsWithReceiver(receiver, args); |
349 | 345 |
350 ResolvedJavaMethod javaMethod = metaAccess.lookupJavaMethod(method); | 346 ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method); |
351 checkArgs(javaMethod, executeArgs); | 347 checkArgs(javaMethod, executeArgs); |
352 | 348 |
353 InstalledCode compiledMethod = getCode(javaMethod, parse(method)); | 349 InstalledCode compiledMethod = getCode(javaMethod, parse(method)); |
354 try { | 350 try { |
355 return new Result(compiledMethod.executeVarargs(executeArgs), null); | 351 return new Result(compiledMethod.executeVarargs(executeArgs), null); |
368 Kind kind = javaType.getKind(); | 364 Kind kind = javaType.getKind(); |
369 Object arg = args[i]; | 365 Object arg = args[i]; |
370 if (kind == Kind.Object) { | 366 if (kind == Kind.Object) { |
371 if (arg != null && javaType instanceof ResolvedJavaType) { | 367 if (arg != null && javaType instanceof ResolvedJavaType) { |
372 ResolvedJavaType resolvedJavaType = (ResolvedJavaType) javaType; | 368 ResolvedJavaType resolvedJavaType = (ResolvedJavaType) javaType; |
373 Assert.assertTrue(resolvedJavaType + " from " + metaAccess.lookupJavaType(arg.getClass()), resolvedJavaType.isAssignableFrom(metaAccess.lookupJavaType(arg.getClass()))); | 369 Assert.assertTrue(resolvedJavaType + " from " + getMetaAccess().lookupJavaType(arg.getClass()), resolvedJavaType.isAssignableFrom(getMetaAccess().lookupJavaType(arg.getClass()))); |
374 } | 370 } |
375 } else { | 371 } else { |
376 Assert.assertNotNull(arg); | 372 Assert.assertNotNull(arg); |
377 Assert.assertEquals(kind.toBoxedJavaClass(), arg.getClass()); | 373 Assert.assertEquals(kind.toBoxedJavaClass(), arg.getClass()); |
378 } | 374 } |
417 testAgainstExpected(method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args); | 413 testAgainstExpected(method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args); |
418 } | 414 } |
419 | 415 |
420 protected Result executeActualCheckDeopt(Method method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) { | 416 protected Result executeActualCheckDeopt(Method method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) { |
421 Map<DeoptimizationReason, Integer> deoptCounts = new EnumMap<>(DeoptimizationReason.class); | 417 Map<DeoptimizationReason, Integer> deoptCounts = new EnumMap<>(DeoptimizationReason.class); |
422 ResolvedJavaMethod javaMethod = metaAccess.lookupJavaMethod(method); | 418 ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method); |
423 ProfilingInfo profile = javaMethod.getProfilingInfo(); | 419 ProfilingInfo profile = javaMethod.getProfilingInfo(); |
424 for (DeoptimizationReason reason : shouldNotDeopt) { | 420 for (DeoptimizationReason reason : shouldNotDeopt) { |
425 deoptCounts.put(reason, profile.getDeoptimizationCount(reason)); | 421 deoptCounts.put(reason, profile.getDeoptimizationCount(reason)); |
426 } | 422 } |
427 Result actual = executeActual(method, receiver, args); | 423 Result actual = executeActual(method, receiver, args); |
486 if (printCompilation) { | 482 if (printCompilation) { |
487 TTY.println(String.format("@%-6d Graal %-70s %-45s %-50s ...", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature())); | 483 TTY.println(String.format("@%-6d Graal %-70s %-45s %-50s ...", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature())); |
488 } | 484 } |
489 long start = System.currentTimeMillis(); | 485 long start = System.currentTimeMillis(); |
490 PhasePlan phasePlan = new PhasePlan(); | 486 PhasePlan phasePlan = new PhasePlan(); |
491 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(metaAccess, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL); | 487 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(getMetaAccess(), getForeignCalls(), GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL); |
492 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); | 488 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); |
493 CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); | 489 CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); |
494 final CompilationResult compResult = GraalCompiler.compileGraph(graph, cc, method, getProviders(), backend, getCodeCache().getTarget(), null, phasePlan, | 490 final CompilationResult compResult = GraalCompiler.compileGraph(graph, cc, method, getProviders(), backend, getCodeCache().getTarget(), null, phasePlan, OptimisticOptimizations.ALL, |
495 OptimisticOptimizations.ALL, new SpeculationLog(), suites, new CompilationResult()); | 491 new SpeculationLog(), suites, new CompilationResult()); |
496 if (printCompilation) { | 492 if (printCompilation) { |
497 TTY.println(String.format("@%-6d Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, compResult.getTargetCodeSize())); | 493 TTY.println(String.format("@%-6d Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, compResult.getTargetCodeSize())); |
498 } | 494 } |
499 return Debug.scope("CodeInstall", new Object[]{getCodeCache(), method}, new Callable<InstalledCode>() { | 495 return Debug.scope("CodeInstall", new Object[]{getCodeCache(), method}, new Callable<InstalledCode>() { |
500 | 496 |
565 return parse0(m, gbConf); | 561 return parse0(m, gbConf); |
566 } | 562 } |
567 | 563 |
568 private StructuredGraph parse0(Method m, GraphBuilderConfiguration conf) { | 564 private StructuredGraph parse0(Method m, GraphBuilderConfiguration conf) { |
569 assert m.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + m; | 565 assert m.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + m; |
570 ResolvedJavaMethod javaMethod = metaAccess.lookupJavaMethod(m); | 566 ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(m); |
571 StructuredGraph graph = new StructuredGraph(javaMethod); | 567 StructuredGraph graph = new StructuredGraph(javaMethod); |
572 new GraphBuilderPhase(metaAccess, conf, OptimisticOptimizations.ALL).apply(graph); | 568 new GraphBuilderPhase(getMetaAccess(), getForeignCalls(), conf, OptimisticOptimizations.ALL).apply(graph); |
573 return graph; | 569 return graph; |
574 } | 570 } |
575 | 571 |
576 protected PhasePlan getDefaultPhasePlan() { | 572 protected PhasePlan getDefaultPhasePlan() { |
577 return getDefaultPhasePlan(false); | 573 return getDefaultPhasePlan(false); |
579 | 575 |
580 protected PhasePlan getDefaultPhasePlan(boolean eagerInfopointMode) { | 576 protected PhasePlan getDefaultPhasePlan(boolean eagerInfopointMode) { |
581 PhasePlan plan = new PhasePlan(); | 577 PhasePlan plan = new PhasePlan(); |
582 GraphBuilderConfiguration gbConf = GraphBuilderConfiguration.getEagerDefault(); | 578 GraphBuilderConfiguration gbConf = GraphBuilderConfiguration.getEagerDefault(); |
583 gbConf.setEagerInfopointMode(eagerInfopointMode); | 579 gbConf.setEagerInfopointMode(eagerInfopointMode); |
584 plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(metaAccess, gbConf, OptimisticOptimizations.ALL)); | 580 plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(getMetaAccess(), getForeignCalls(), gbConf, OptimisticOptimizations.ALL)); |
585 return plan; | 581 return plan; |
586 } | 582 } |
587 | 583 |
588 protected Replacements getReplacements() { | 584 protected Replacements getReplacements() { |
589 return replacements; | 585 return getProviders().getReplacements(); |
590 } | 586 } |
591 } | 587 } |