94 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
95 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
96 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
97 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
98 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
99 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
100 import org.graalvm.compiler.nodes.java.AccessFieldNode;
101 import org.graalvm.compiler.nodes.spi.LoweringProvider;
102 import org.graalvm.compiler.nodes.spi.Replacements;
103 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
104 import org.graalvm.compiler.options.OptionValues;
105 import org.graalvm.compiler.phases.BasePhase;
106 import org.graalvm.compiler.phases.OptimisticOptimizations;
107 import org.graalvm.compiler.phases.Phase;
108 import org.graalvm.compiler.phases.PhaseSuite;
109 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
110 import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;
111 import org.graalvm.compiler.phases.schedule.SchedulePhase;
112 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
113 import org.graalvm.compiler.phases.tiers.HighTierContext;
114 import org.graalvm.compiler.phases.tiers.Suites;
115 import org.graalvm.compiler.phases.tiers.TargetProvider;
116 import org.graalvm.compiler.phases.util.Providers;
117 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
118 import org.graalvm.compiler.runtime.RuntimeProvider;
119 import org.graalvm.compiler.test.AddExports;
120 import org.graalvm.compiler.test.GraalTest;
121 import org.graalvm.compiler.test.JLModule;
122 import org.junit.After;
123 import org.junit.Assert;
124 import org.junit.Test;
125 import org.junit.internal.AssumptionViolatedException;
126
127 import jdk.vm.ci.code.Architecture;
128 import jdk.vm.ci.code.BailoutException;
129 import jdk.vm.ci.code.CodeCacheProvider;
130 import jdk.vm.ci.code.InstalledCode;
131 import jdk.vm.ci.code.TargetDescription;
132 import jdk.vm.ci.meta.Assumptions.Assumption;
133 import jdk.vm.ci.meta.ConstantReflectionProvider;
578 result.append('\n');
579 for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
580 result.append(String.format("%1S\n", node));
581 }
582 }
583 return result.toString();
584 }
585
586 protected Backend getBackend() {
587 return backend;
588 }
589
590 protected final Providers getProviders() {
591 return providers;
592 }
593
594 protected HighTierContext getDefaultHighTierContext() {
595 return new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
596 }
597
598 protected SnippetReflectionProvider getSnippetReflection() {
599 return Graal.getRequiredCapability(SnippetReflectionProvider.class);
600 }
601
602 protected TargetDescription getTarget() {
603 return getTargetProvider().getTarget();
604 }
605
606 protected TargetProvider getTargetProvider() {
607 return getBackend();
608 }
609
610 protected CodeCacheProvider getCodeCache() {
611 return getProviders().getCodeCache();
612 }
613
614 protected ConstantReflectionProvider getConstantReflection() {
615 return getProviders().getConstantReflection();
616 }
617
909 * @param forceCompile specifies whether to ignore any previous code cached for the (method,
910 * key) pair
911 */
912 protected final InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile) {
913 return getCode(installedCodeOwner, graph, forceCompile, false, graph == null ? getInitialOptions() : graph.getOptions());
914 }
915
916 /**
917 * Gets installed code for a given method and graph, compiling it first if necessary.
918 *
919 * @param installedCodeOwner the method the compiled code will be associated with when installed
920 * @param graph the graph to be compiled. If null, a graph will be obtained from
921 * {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}.
922 * @param forceCompile specifies whether to ignore any previous code cached for the (method,
923 * key) pair
924 * @param installAsDefault specifies whether to install as the default implementation
925 * @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)}
926 */
927 @SuppressWarnings("try")
928 protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
929 if (!forceCompile) {
930 InstalledCode cached = cache.get(installedCodeOwner);
931 if (cached != null) {
932 if (cached.isValid()) {
933 return cached;
934 }
935 }
936 }
937 // loop for retrying compilation
938 for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
939 final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
940
941 InstalledCode installedCode = null;
942 StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
943 DebugContext debug = graphToCompile.getDebug();
944 try (AllocSpy spy = AllocSpy.open(installedCodeOwner); DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
945 CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
946 CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(), id, options);
947 printer.finish(compResult);
948
949 try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
|
94 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
95 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
96 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
97 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
98 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
99 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
100 import org.graalvm.compiler.nodes.java.AccessFieldNode;
101 import org.graalvm.compiler.nodes.spi.LoweringProvider;
102 import org.graalvm.compiler.nodes.spi.Replacements;
103 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
104 import org.graalvm.compiler.options.OptionValues;
105 import org.graalvm.compiler.phases.BasePhase;
106 import org.graalvm.compiler.phases.OptimisticOptimizations;
107 import org.graalvm.compiler.phases.Phase;
108 import org.graalvm.compiler.phases.PhaseSuite;
109 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
110 import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;
111 import org.graalvm.compiler.phases.schedule.SchedulePhase;
112 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
113 import org.graalvm.compiler.phases.tiers.HighTierContext;
114 import org.graalvm.compiler.phases.tiers.MidTierContext;
115 import org.graalvm.compiler.phases.tiers.Suites;
116 import org.graalvm.compiler.phases.tiers.TargetProvider;
117 import org.graalvm.compiler.phases.util.Providers;
118 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
119 import org.graalvm.compiler.runtime.RuntimeProvider;
120 import org.graalvm.compiler.test.AddExports;
121 import org.graalvm.compiler.test.GraalTest;
122 import org.graalvm.compiler.test.JLModule;
123 import org.junit.After;
124 import org.junit.Assert;
125 import org.junit.Test;
126 import org.junit.internal.AssumptionViolatedException;
127
128 import jdk.vm.ci.code.Architecture;
129 import jdk.vm.ci.code.BailoutException;
130 import jdk.vm.ci.code.CodeCacheProvider;
131 import jdk.vm.ci.code.InstalledCode;
132 import jdk.vm.ci.code.TargetDescription;
133 import jdk.vm.ci.meta.Assumptions.Assumption;
134 import jdk.vm.ci.meta.ConstantReflectionProvider;
579 result.append('\n');
580 for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
581 result.append(String.format("%1S\n", node));
582 }
583 }
584 return result.toString();
585 }
586
587 protected Backend getBackend() {
588 return backend;
589 }
590
591 protected final Providers getProviders() {
592 return providers;
593 }
594
595 protected HighTierContext getDefaultHighTierContext() {
596 return new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
597 }
598
599 protected MidTierContext getDefaultMidTierContext() {
600 return new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, null);
601 }
602
603 protected SnippetReflectionProvider getSnippetReflection() {
604 return Graal.getRequiredCapability(SnippetReflectionProvider.class);
605 }
606
607 protected TargetDescription getTarget() {
608 return getTargetProvider().getTarget();
609 }
610
611 protected TargetProvider getTargetProvider() {
612 return getBackend();
613 }
614
615 protected CodeCacheProvider getCodeCache() {
616 return getProviders().getCodeCache();
617 }
618
619 protected ConstantReflectionProvider getConstantReflection() {
620 return getProviders().getConstantReflection();
621 }
622
914 * @param forceCompile specifies whether to ignore any previous code cached for the (method,
915 * key) pair
916 */
917 protected final InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile) {
918 return getCode(installedCodeOwner, graph, forceCompile, false, graph == null ? getInitialOptions() : graph.getOptions());
919 }
920
921 /**
922 * Gets installed code for a given method and graph, compiling it first if necessary.
923 *
924 * @param installedCodeOwner the method the compiled code will be associated with when installed
925 * @param graph the graph to be compiled. If null, a graph will be obtained from
926 * {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}.
927 * @param forceCompile specifies whether to ignore any previous code cached for the (method,
928 * key) pair
929 * @param installAsDefault specifies whether to install as the default implementation
930 * @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)}
931 */
932 @SuppressWarnings("try")
933 protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
934 if (!forceCompile && graph == null) {
935 InstalledCode cached = cache.get(installedCodeOwner);
936 if (cached != null) {
937 if (cached.isValid()) {
938 return cached;
939 }
940 }
941 }
942 // loop for retrying compilation
943 for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
944 final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
945
946 InstalledCode installedCode = null;
947 StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
948 DebugContext debug = graphToCompile.getDebug();
949 try (AllocSpy spy = AllocSpy.open(installedCodeOwner); DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
950 CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
951 CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(), id, options);
952 printer.finish(compResult);
953
954 try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
|