< 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
rev 52889 : 8214023: Update Graal


  66 import org.graalvm.compiler.debug.DebugHandlersFactory;
  67 import org.graalvm.compiler.debug.GraalError;
  68 import org.graalvm.compiler.debug.TTY;
  69 import org.graalvm.compiler.graph.Node;
  70 import org.graalvm.compiler.graph.NodeClass;
  71 import org.graalvm.compiler.graph.NodeMap;
  72 import org.graalvm.compiler.java.BytecodeParser;
  73 import org.graalvm.compiler.java.ComputeLoopFrequenciesClosure;
  74 import org.graalvm.compiler.java.GraphBuilderPhase;
  75 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
  76 import org.graalvm.compiler.lir.phases.LIRSuites;
  77 import org.graalvm.compiler.nodeinfo.NodeInfo;
  78 import org.graalvm.compiler.nodeinfo.NodeSize;
  79 import org.graalvm.compiler.nodeinfo.Verbosity;
  80 import org.graalvm.compiler.nodes.BreakpointNode;
  81 import org.graalvm.compiler.nodes.Cancellable;
  82 import org.graalvm.compiler.nodes.ConstantNode;
  83 import org.graalvm.compiler.nodes.FixedWithNextNode;
  84 import org.graalvm.compiler.nodes.FrameState;
  85 import org.graalvm.compiler.nodes.FullInfopointNode;

  86 import org.graalvm.compiler.nodes.InvokeNode;
  87 import org.graalvm.compiler.nodes.InvokeWithExceptionNode;
  88 import org.graalvm.compiler.nodes.ParameterNode;
  89 import org.graalvm.compiler.nodes.ProxyNode;
  90 import org.graalvm.compiler.nodes.ReturnNode;
  91 import org.graalvm.compiler.nodes.StructuredGraph;
  92 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  93 import org.graalvm.compiler.nodes.StructuredGraph.Builder;
  94 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  95 import org.graalvm.compiler.nodes.ValueNode;
  96 import org.graalvm.compiler.nodes.cfg.Block;
  97 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  98 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  99 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
 100 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
 101 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
 102 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
 103 import org.graalvm.compiler.nodes.java.AccessFieldNode;
 104 import org.graalvm.compiler.nodes.spi.LoweringProvider;
 105 import org.graalvm.compiler.nodes.spi.Replacements;
 106 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
 107 import org.graalvm.compiler.options.OptionValues;
 108 import org.graalvm.compiler.phases.BasePhase;
 109 import org.graalvm.compiler.phases.OptimisticOptimizations;
 110 import org.graalvm.compiler.phases.Phase;
 111 import org.graalvm.compiler.phases.PhaseSuite;
 112 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 113 import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;



 114 import org.graalvm.compiler.phases.schedule.SchedulePhase;
 115 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
 116 import org.graalvm.compiler.phases.tiers.HighTierContext;
 117 import org.graalvm.compiler.phases.tiers.MidTierContext;
 118 import org.graalvm.compiler.phases.tiers.Suites;
 119 import org.graalvm.compiler.phases.tiers.TargetProvider;
 120 import org.graalvm.compiler.phases.util.Providers;
 121 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
 122 import org.graalvm.compiler.runtime.RuntimeProvider;
 123 import org.graalvm.compiler.test.AddExports;
 124 import org.graalvm.compiler.test.GraalTest;
 125 import org.graalvm.compiler.test.JLModule;
 126 import org.junit.After;
 127 import org.junit.Assert;
 128 import org.junit.Test;
 129 import org.junit.internal.AssumptionViolatedException;
 130 
 131 import jdk.vm.ci.code.Architecture;
 132 import jdk.vm.ci.code.BailoutException;
 133 import jdk.vm.ci.code.CodeCacheProvider;


 580             for (Block succ : block.getSuccessors()) {
 581                 result.append(succ).append(' ');
 582             }
 583             result.append('\n');
 584             for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
 585                 result.append(String.format("%1S\n", node));
 586             }
 587         }
 588         return result.toString();
 589     }
 590 
 591     protected Backend getBackend() {
 592         return backend;
 593     }
 594 
 595     protected final Providers getProviders() {
 596         return providers;
 597     }
 598 
 599     protected HighTierContext getDefaultHighTierContext() {
 600         return new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
 601     }
 602 
 603     protected MidTierContext getDefaultMidTierContext() {
 604         return new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, null);
 605     }
 606 
 607     protected SnippetReflectionProvider getSnippetReflection() {
 608         return Graal.getRequiredCapability(SnippetReflectionProvider.class);
 609     }
 610 
 611     protected TargetDescription getTarget() {
 612         return getTargetProvider().getTarget();
 613     }
 614 
 615     protected TargetProvider getTargetProvider() {
 616         return getBackend();
 617     }
 618 
 619     protected CodeCacheProvider getCodeCache() {
 620         return getProviders().getCodeCache();
 621     }
 622 
 623     protected ConstantReflectionProvider getConstantReflection() {
 624         return getProviders().getConstantReflection();
 625     }
 626 
 627     protected MetaAccessProvider getMetaAccess() {
 628         return getProviders().getMetaAccess();
 629     }
 630 
 631     protected LoweringProvider getLowerer() {
 632         return getProviders().getLowerer();
 633     }
 634 
























 635     protected CompilationIdentifier getCompilationId(ResolvedJavaMethod method) {
 636         return getBackend().getCompilationIdentifier(method);
 637     }
 638 
 639     protected CompilationIdentifier getOrCreateCompilationId(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
 640         if (graph != null) {
 641             return graph.compilationId();
 642         }
 643         return getCompilationId(installedCodeOwner);
 644     }
 645 
 646     protected void testN(int n, final String name, final Object... args) {
 647         final List<Throwable> errors = new ArrayList<>(n);
 648         Thread[] threads = new Thread[n];
 649         for (int i = 0; i < n; i++) {
 650             Thread t = new Thread(i + ":" + name) {
 651 
 652                 @Override
 653                 public void run() {
 654                     try {


1022      *            be obtained from {@code installedCodeOwner} via
1023      *            {@link #parseForCompile(ResolvedJavaMethod)}.
1024      */
1025     protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
1026         OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1027         CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
1028         return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1029     }
1030 
1031     protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationIdentifier compilationId) {
1032         OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1033         return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1034     }
1035 
1036     protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, OptionValues options) {
1037         assert graph == null || graph.getOptions() == options;
1038         CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
1039         return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1040     }
1041 




1042     /**
1043      * Compiles a given method.
1044      *
1045      * @param installedCodeOwner the method the compiled code will be associated with when installed
1046      * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
1047      *            be obtained from {@code installedCodeOwner} via
1048      *            {@link #parseForCompile(ResolvedJavaMethod)}.
1049      * @param compilationId
1050      */
1051     @SuppressWarnings("try")
1052     protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
1053         StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
1054         lastCompiledGraph = graphToCompile;
1055         DebugContext debug = graphToCompile.getDebug();
1056         try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
1057             assert options != null;
1058             Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL,
1059                             graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default, true);
1060             return GraalCompiler.compile(request);
1061         } catch (Throwable e) {
1062             throw debug.handle(e);
1063         }
1064     }
1065 
1066     protected StructuredGraph getFinalGraph(String method) {
1067         return getFinalGraph(getResolvedJavaMethod(method));
1068     }
1069 
1070     protected StructuredGraph getFinalGraph(ResolvedJavaMethod method) {
1071         StructuredGraph graph = parseForCompile(method);
1072         applyFrontEnd(graph);
1073         return graph;
1074     }
1075 
1076     protected void applyFrontEnd(StructuredGraph graph) {
1077         GraalCompiler.emitFrontEnd(getProviders(), getBackend(), graph, getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()));
1078     }
1079 
1080     protected StructuredGraph lastCompiledGraph;
1081 
1082     protected SpeculationLog getSpeculationLog() {
1083         return null;
1084     }
1085 
1086     protected InstalledCode addMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
1087         return backend.addInstalledCode(debug, method, null, compilationResult);
1088     }
1089 
1090     protected InstalledCode addDefaultMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
1091         return backend.createDefaultInstalledCode(debug, method, compilationResult);
1092     }
1093 
1094     private final Map<ResolvedJavaMethod, Executable> methodMap = new ConcurrentHashMap<>();
1095 
1096     /**
1097      * Converts a reflection {@link Method} to a {@link ResolvedJavaMethod}.




  66 import org.graalvm.compiler.debug.DebugHandlersFactory;
  67 import org.graalvm.compiler.debug.GraalError;
  68 import org.graalvm.compiler.debug.TTY;
  69 import org.graalvm.compiler.graph.Node;
  70 import org.graalvm.compiler.graph.NodeClass;
  71 import org.graalvm.compiler.graph.NodeMap;
  72 import org.graalvm.compiler.java.BytecodeParser;
  73 import org.graalvm.compiler.java.ComputeLoopFrequenciesClosure;
  74 import org.graalvm.compiler.java.GraphBuilderPhase;
  75 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
  76 import org.graalvm.compiler.lir.phases.LIRSuites;
  77 import org.graalvm.compiler.nodeinfo.NodeInfo;
  78 import org.graalvm.compiler.nodeinfo.NodeSize;
  79 import org.graalvm.compiler.nodeinfo.Verbosity;
  80 import org.graalvm.compiler.nodes.BreakpointNode;
  81 import org.graalvm.compiler.nodes.Cancellable;
  82 import org.graalvm.compiler.nodes.ConstantNode;
  83 import org.graalvm.compiler.nodes.FixedWithNextNode;
  84 import org.graalvm.compiler.nodes.FrameState;
  85 import org.graalvm.compiler.nodes.FullInfopointNode;
  86 import org.graalvm.compiler.nodes.Invoke;
  87 import org.graalvm.compiler.nodes.InvokeNode;
  88 import org.graalvm.compiler.nodes.InvokeWithExceptionNode;
  89 import org.graalvm.compiler.nodes.ParameterNode;
  90 import org.graalvm.compiler.nodes.ProxyNode;
  91 import org.graalvm.compiler.nodes.ReturnNode;
  92 import org.graalvm.compiler.nodes.StructuredGraph;
  93 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  94 import org.graalvm.compiler.nodes.StructuredGraph.Builder;
  95 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  96 import org.graalvm.compiler.nodes.ValueNode;
  97 import org.graalvm.compiler.nodes.cfg.Block;
  98 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  99 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
 100 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
 101 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
 102 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
 103 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
 104 import org.graalvm.compiler.nodes.java.AccessFieldNode;
 105 import org.graalvm.compiler.nodes.spi.LoweringProvider;
 106 import org.graalvm.compiler.nodes.spi.Replacements;
 107 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
 108 import org.graalvm.compiler.options.OptionValues;
 109 import org.graalvm.compiler.phases.BasePhase;
 110 import org.graalvm.compiler.phases.OptimisticOptimizations;
 111 import org.graalvm.compiler.phases.Phase;
 112 import org.graalvm.compiler.phases.PhaseSuite;
 113 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 114 import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;
 115 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
 116 import org.graalvm.compiler.phases.common.inlining.info.InlineInfo;
 117 import org.graalvm.compiler.phases.common.inlining.policy.GreedyInliningPolicy;
 118 import org.graalvm.compiler.phases.schedule.SchedulePhase;
 119 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
 120 import org.graalvm.compiler.phases.tiers.HighTierContext;
 121 import org.graalvm.compiler.phases.tiers.MidTierContext;
 122 import org.graalvm.compiler.phases.tiers.Suites;
 123 import org.graalvm.compiler.phases.tiers.TargetProvider;
 124 import org.graalvm.compiler.phases.util.Providers;
 125 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
 126 import org.graalvm.compiler.runtime.RuntimeProvider;
 127 import org.graalvm.compiler.test.AddExports;
 128 import org.graalvm.compiler.test.GraalTest;
 129 import org.graalvm.compiler.test.JLModule;
 130 import org.junit.After;
 131 import org.junit.Assert;
 132 import org.junit.Test;
 133 import org.junit.internal.AssumptionViolatedException;
 134 
 135 import jdk.vm.ci.code.Architecture;
 136 import jdk.vm.ci.code.BailoutException;
 137 import jdk.vm.ci.code.CodeCacheProvider;


 584             for (Block succ : block.getSuccessors()) {
 585                 result.append(succ).append(' ');
 586             }
 587             result.append('\n');
 588             for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
 589                 result.append(String.format("%1S\n", node));
 590             }
 591         }
 592         return result.toString();
 593     }
 594 
 595     protected Backend getBackend() {
 596         return backend;
 597     }
 598 
 599     protected final Providers getProviders() {
 600         return providers;
 601     }
 602 
 603     protected HighTierContext getDefaultHighTierContext() {
 604         return new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), getOptimisticOptimizations());
 605     }
 606 
 607     protected MidTierContext getDefaultMidTierContext() {
 608         return new MidTierContext(getProviders(), getTargetProvider(), getOptimisticOptimizations(), null);
 609     }
 610 
 611     protected SnippetReflectionProvider getSnippetReflection() {
 612         return Graal.getRequiredCapability(SnippetReflectionProvider.class);
 613     }
 614 
 615     protected TargetDescription getTarget() {
 616         return getTargetProvider().getTarget();
 617     }
 618 
 619     protected TargetProvider getTargetProvider() {
 620         return getBackend();
 621     }
 622 
 623     protected CodeCacheProvider getCodeCache() {
 624         return getProviders().getCodeCache();
 625     }
 626 
 627     protected ConstantReflectionProvider getConstantReflection() {
 628         return getProviders().getConstantReflection();
 629     }
 630 
 631     protected MetaAccessProvider getMetaAccess() {
 632         return getProviders().getMetaAccess();
 633     }
 634 
 635     protected LoweringProvider getLowerer() {
 636         return getProviders().getLowerer();
 637     }
 638 
 639     protected final BasePhase<HighTierContext> createInliningPhase() {
 640         return createInliningPhase(new CanonicalizerPhase());
 641     }
 642 
 643     protected BasePhase<HighTierContext> createInliningPhase(CanonicalizerPhase canonicalizer) {
 644         return createInliningPhase(null, canonicalizer);
 645     }
 646 
 647     static class GreedyTestInliningPolicy extends GreedyInliningPolicy {
 648         GreedyTestInliningPolicy(Map<Invoke, Double> hints) {
 649             super(hints);
 650         }
 651 
 652         @Override
 653         protected int previousLowLevelGraphSize(InlineInfo info) {
 654             // Ignore previous compiles for tests
 655             return 0;
 656         }
 657     }
 658 
 659     protected BasePhase<HighTierContext> createInliningPhase(Map<Invoke, Double> hints, CanonicalizerPhase canonicalizer) {
 660         return new InliningPhase(new GreedyTestInliningPolicy(hints), canonicalizer);
 661     }
 662 
 663     protected CompilationIdentifier getCompilationId(ResolvedJavaMethod method) {
 664         return getBackend().getCompilationIdentifier(method);
 665     }
 666 
 667     protected CompilationIdentifier getOrCreateCompilationId(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
 668         if (graph != null) {
 669             return graph.compilationId();
 670         }
 671         return getCompilationId(installedCodeOwner);
 672     }
 673 
 674     protected void testN(int n, final String name, final Object... args) {
 675         final List<Throwable> errors = new ArrayList<>(n);
 676         Thread[] threads = new Thread[n];
 677         for (int i = 0; i < n; i++) {
 678             Thread t = new Thread(i + ":" + name) {
 679 
 680                 @Override
 681                 public void run() {
 682                     try {


1050      *            be obtained from {@code installedCodeOwner} via
1051      *            {@link #parseForCompile(ResolvedJavaMethod)}.
1052      */
1053     protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
1054         OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1055         CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
1056         return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1057     }
1058 
1059     protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationIdentifier compilationId) {
1060         OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1061         return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1062     }
1063 
1064     protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, OptionValues options) {
1065         assert graph == null || graph.getOptions() == options;
1066         CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
1067         return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1068     }
1069 
1070     protected OptimisticOptimizations getOptimisticOptimizations() {
1071         return OptimisticOptimizations.ALL;
1072     }
1073 
1074     /**
1075      * Compiles a given method.
1076      *
1077      * @param installedCodeOwner the method the compiled code will be associated with when installed
1078      * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
1079      *            be obtained from {@code installedCodeOwner} via
1080      *            {@link #parseForCompile(ResolvedJavaMethod)}.
1081      * @param compilationId
1082      */
1083     @SuppressWarnings("try")
1084     protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
1085         StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
1086         lastCompiledGraph = graphToCompile;
1087         DebugContext debug = graphToCompile.getDebug();
1088         try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
1089             assert options != null;
1090             Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), getOptimisticOptimizations(),
1091                             graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default, true);
1092             return GraalCompiler.compile(request);
1093         } catch (Throwable e) {
1094             throw debug.handle(e);
1095         }
1096     }
1097 
1098     protected StructuredGraph getFinalGraph(String method) {
1099         return getFinalGraph(getResolvedJavaMethod(method));
1100     }
1101 
1102     protected StructuredGraph getFinalGraph(ResolvedJavaMethod method) {
1103         StructuredGraph graph = parseForCompile(method);
1104         applyFrontEnd(graph);
1105         return graph;
1106     }
1107 
1108     protected void applyFrontEnd(StructuredGraph graph) {
1109         GraalCompiler.emitFrontEnd(getProviders(), getBackend(), graph, getDefaultGraphBuilderSuite(), getOptimisticOptimizations(), graph.getProfilingInfo(), createSuites(graph.getOptions()));
1110     }
1111 
1112     protected StructuredGraph lastCompiledGraph;
1113 
1114     protected SpeculationLog getSpeculationLog() {
1115         return null;
1116     }
1117 
1118     protected InstalledCode addMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
1119         return backend.addInstalledCode(debug, method, null, compilationResult);
1120     }
1121 
1122     protected InstalledCode addDefaultMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
1123         return backend.createDefaultInstalledCode(debug, method, compilationResult);
1124     }
1125 
1126     private final Map<ResolvedJavaMethod, Executable> methodMap = new ConcurrentHashMap<>();
1127 
1128     /**
1129      * Converts a reflection {@link Method} to a {@link ResolvedJavaMethod}.


< prev index next >