< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java

Print this page




 372     @After
 373     public void afterTest() {
 374         if (invocationPluginExtensions != null) {
 375             synchronized (this) {
 376                 if (invocationPluginExtensions != null) {
 377                     extendedInvocationPlugins.removeTestPlugins(invocationPluginExtensions);
 378                     extendedInvocationPlugins = null;
 379                     invocationPluginExtensions = null;
 380                 }
 381             }
 382         }
 383         super.afterTest();
 384     }
 385 
 386     /**
 387      * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
 388      * none currently exists. Debug contexts created by this method will have their
 389      * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
 390      */
 391     protected DebugContext getDebugContext() {
 392         return getDebugContext(getInitialOptions());
 393     }
 394 
 395     @Override
 396     protected Collection<DebugHandlersFactory> getDebugHandlersFactories() {
 397         return Collections.singletonList(new GraalDebugHandlersFactory(getSnippetReflection()));
 398     }
 399 
 400     protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
 401         assertEquals(expected, graph, false, true);
 402     }
 403 
 404     protected int countUnusedConstants(StructuredGraph graph) {
 405         int total = 0;
 406         for (ConstantNode node : getConstantNodes(graph)) {
 407             if (node.hasNoUsages()) {
 408                 total++;
 409             }
 410         }
 411         return total;
 412     }


 845     }
 846 
 847     protected final void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Object receiver, Object... args) {
 848         testAgainstExpected(options, method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args);
 849     }
 850 
 851     protected void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
 852         Result actual = executeActualCheckDeopt(options, method, shouldNotDeopt, receiver, args);
 853         assertEquals(expect, actual);
 854     }
 855 
 856     protected Result executeActualCheckDeopt(OptionValues options, ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
 857         Map<DeoptimizationReason, Integer> deoptCounts = new EnumMap<>(DeoptimizationReason.class);
 858         ProfilingInfo profile = method.getProfilingInfo();
 859         for (DeoptimizationReason reason : shouldNotDeopt) {
 860             deoptCounts.put(reason, profile.getDeoptimizationCount(reason));
 861         }
 862         Result actual = executeActual(options, method, receiver, args);
 863         profile = method.getProfilingInfo(); // profile can change after execution
 864         for (DeoptimizationReason reason : shouldNotDeopt) {
 865             Assert.assertEquals((int) deoptCounts.get(reason), profile.getDeoptimizationCount(reason));
 866         }
 867         return actual;
 868     }
 869 
 870     protected void assertEquals(Result expect, Result actual) {
 871         if (expect.exception != null) {
 872             Assert.assertTrue("expected " + expect.exception, actual.exception != null);
 873             Assert.assertEquals("Exception class", expect.exception.getClass(), actual.exception.getClass());
 874             Assert.assertEquals("Exception message", expect.exception.getMessage(), actual.exception.getMessage());
 875         } else {
 876             if (actual.exception != null) {
 877                 throw new AssertionError("expected " + expect.returnValue + " but got an exception", actual.exception);
 878             }
 879             assertDeepEquals(expect.returnValue, actual.returnValue);
 880         }
 881     }
 882 
 883     private Map<ResolvedJavaMethod, InstalledCode> cache = new HashMap<>();
 884 
 885     /**


1199     /**
1200      * Parses a Java method with {@linkplain GraphBuilderConfiguration#withEagerResolving(boolean)}
1201      * set to true to produce a graph.
1202      *
1203      * @param method the method to be parsed
1204      * @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
1205      * @param compilationId the compilation identifier to be associated with the graph
1206      * @param options the option values to be used when compiling the graph
1207      */
1208     protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
1209         return parse(builder(method, allowAssumptions, compilationId, options), getEagerGraphBuilderSuite());
1210     }
1211 
1212     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, DebugContext debug) {
1213         OptionValues options = debug.getOptions();
1214         return new Builder(options, debug, allowAssumptions).method(method).compilationId(getCompilationId(method));
1215     }
1216 
1217     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
1218         OptionValues options = getInitialOptions();
1219         return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(getCompilationId(method));
1220     }
1221 
1222     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
1223         return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(compilationId);
1224     }
1225 
1226     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, OptionValues options) {
1227         return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(getCompilationId(method));
1228     }
1229 
1230     protected PhaseSuite<HighTierContext> getDebugGraphBuilderSuite() {
1231         return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
1232     }
1233 
1234     @SuppressWarnings("try")
1235     protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
1236         ResolvedJavaMethod javaMethod = builder.getMethod();

1237         if (builder.getCancellable() == null) {
1238             builder.cancellable(getCancellable(javaMethod));
1239         }
1240         assert javaMethod.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + javaMethod;
1241         StructuredGraph graph = builder.build();
1242         DebugContext debug = graph.getDebug();
1243         try (DebugContext.Scope ds = debug.scope("Parsing", javaMethod, graph)) {
1244             graphBuilderSuite.apply(graph, getDefaultHighTierContext());
1245             return graph;
1246         } catch (Throwable e) {
1247             throw debug.handle(e);
1248         }
1249     }
1250 
1251     protected PhaseSuite<HighTierContext> getEagerGraphBuilderSuite() {
1252         return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true));
1253     }
1254 
1255     /**
1256      * Gets the cancellable that should be associated with a graph being created by any of the




 372     @After
 373     public void afterTest() {
 374         if (invocationPluginExtensions != null) {
 375             synchronized (this) {
 376                 if (invocationPluginExtensions != null) {
 377                     extendedInvocationPlugins.removeTestPlugins(invocationPluginExtensions);
 378                     extendedInvocationPlugins = null;
 379                     invocationPluginExtensions = null;
 380                 }
 381             }
 382         }
 383         super.afterTest();
 384     }
 385 
 386     /**
 387      * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
 388      * none currently exists. Debug contexts created by this method will have their
 389      * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
 390      */
 391     protected DebugContext getDebugContext() {
 392         return getDebugContext(getInitialOptions(), null, null);
 393     }
 394 
 395     @Override
 396     protected Collection<DebugHandlersFactory> getDebugHandlersFactories() {
 397         return Collections.singletonList(new GraalDebugHandlersFactory(getSnippetReflection()));
 398     }
 399 
 400     protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
 401         assertEquals(expected, graph, false, true);
 402     }
 403 
 404     protected int countUnusedConstants(StructuredGraph graph) {
 405         int total = 0;
 406         for (ConstantNode node : getConstantNodes(graph)) {
 407             if (node.hasNoUsages()) {
 408                 total++;
 409             }
 410         }
 411         return total;
 412     }


 845     }
 846 
 847     protected final void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Object receiver, Object... args) {
 848         testAgainstExpected(options, method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args);
 849     }
 850 
 851     protected void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
 852         Result actual = executeActualCheckDeopt(options, method, shouldNotDeopt, receiver, args);
 853         assertEquals(expect, actual);
 854     }
 855 
 856     protected Result executeActualCheckDeopt(OptionValues options, ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
 857         Map<DeoptimizationReason, Integer> deoptCounts = new EnumMap<>(DeoptimizationReason.class);
 858         ProfilingInfo profile = method.getProfilingInfo();
 859         for (DeoptimizationReason reason : shouldNotDeopt) {
 860             deoptCounts.put(reason, profile.getDeoptimizationCount(reason));
 861         }
 862         Result actual = executeActual(options, method, receiver, args);
 863         profile = method.getProfilingInfo(); // profile can change after execution
 864         for (DeoptimizationReason reason : shouldNotDeopt) {
 865             Assert.assertEquals("wrong number of deopt counts for " + reason, (int) deoptCounts.get(reason), profile.getDeoptimizationCount(reason));
 866         }
 867         return actual;
 868     }
 869 
 870     protected void assertEquals(Result expect, Result actual) {
 871         if (expect.exception != null) {
 872             Assert.assertTrue("expected " + expect.exception, actual.exception != null);
 873             Assert.assertEquals("Exception class", expect.exception.getClass(), actual.exception.getClass());
 874             Assert.assertEquals("Exception message", expect.exception.getMessage(), actual.exception.getMessage());
 875         } else {
 876             if (actual.exception != null) {
 877                 throw new AssertionError("expected " + expect.returnValue + " but got an exception", actual.exception);
 878             }
 879             assertDeepEquals(expect.returnValue, actual.returnValue);
 880         }
 881     }
 882 
 883     private Map<ResolvedJavaMethod, InstalledCode> cache = new HashMap<>();
 884 
 885     /**


1199     /**
1200      * Parses a Java method with {@linkplain GraphBuilderConfiguration#withEagerResolving(boolean)}
1201      * set to true to produce a graph.
1202      *
1203      * @param method the method to be parsed
1204      * @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
1205      * @param compilationId the compilation identifier to be associated with the graph
1206      * @param options the option values to be used when compiling the graph
1207      */
1208     protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
1209         return parse(builder(method, allowAssumptions, compilationId, options), getEagerGraphBuilderSuite());
1210     }
1211 
1212     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, DebugContext debug) {
1213         OptionValues options = debug.getOptions();
1214         return new Builder(options, debug, allowAssumptions).method(method).compilationId(getCompilationId(method));
1215     }
1216 
1217     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
1218         OptionValues options = getInitialOptions();
1219         return new Builder(options, getDebugContext(options, null, method), allowAssumptions).method(method).compilationId(getCompilationId(method));
1220     }
1221 
1222     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
1223         return new Builder(options, getDebugContext(options, compilationId.toString(CompilationIdentifier.Verbosity.ID), method), allowAssumptions).method(method).compilationId(compilationId);
1224     }
1225 
1226     protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, OptionValues options) {
1227         return new Builder(options, getDebugContext(options, null, method), allowAssumptions).method(method).compilationId(getCompilationId(method));
1228     }
1229 
1230     protected PhaseSuite<HighTierContext> getDebugGraphBuilderSuite() {
1231         return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
1232     }
1233 
1234     @SuppressWarnings("try")
1235     protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
1236         ResolvedJavaMethod javaMethod = builder.getMethod();
1237         builder.speculationLog(getSpeculationLog());
1238         if (builder.getCancellable() == null) {
1239             builder.cancellable(getCancellable(javaMethod));
1240         }
1241         assert javaMethod.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + javaMethod;
1242         StructuredGraph graph = builder.build();
1243         DebugContext debug = graph.getDebug();
1244         try (DebugContext.Scope ds = debug.scope("Parsing", javaMethod, graph)) {
1245             graphBuilderSuite.apply(graph, getDefaultHighTierContext());
1246             return graph;
1247         } catch (Throwable e) {
1248             throw debug.handle(e);
1249         }
1250     }
1251 
1252     protected PhaseSuite<HighTierContext> getEagerGraphBuilderSuite() {
1253         return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true));
1254     }
1255 
1256     /**
1257      * Gets the cancellable that should be associated with a graph being created by any of the


< prev index next >