21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 package jdk.tools.jaotc; |
24 package jdk.tools.jaotc; |
25 |
25 |
26 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
|
27 import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode; |
|
28 |
|
29 import java.util.ListIterator; |
26 import java.util.ListIterator; |
30 |
27 |
31 import org.graalvm.compiler.code.CompilationResult; |
28 import org.graalvm.compiler.code.CompilationResult; |
32 import org.graalvm.compiler.core.GraalCompiler; |
29 import org.graalvm.compiler.core.GraalCompiler; |
33 import org.graalvm.compiler.core.common.CompilationIdentifier; |
|
34 import org.graalvm.compiler.debug.Debug; |
30 import org.graalvm.compiler.debug.Debug; |
35 import org.graalvm.compiler.debug.Debug.Scope; |
31 import org.graalvm.compiler.debug.Debug.Scope; |
36 import org.graalvm.compiler.debug.GraalError; |
|
37 import org.graalvm.compiler.hotspot.HotSpotBackend; |
32 import org.graalvm.compiler.hotspot.HotSpotBackend; |
38 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder; |
33 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder; |
39 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
34 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
40 import org.graalvm.compiler.java.GraphBuilderPhase; |
35 import org.graalvm.compiler.java.GraphBuilderPhase; |
41 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory; |
36 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory; |
42 import org.graalvm.compiler.lir.phases.LIRSuites; |
37 import org.graalvm.compiler.lir.phases.LIRSuites; |
43 import org.graalvm.compiler.nodes.StructuredGraph; |
38 import org.graalvm.compiler.nodes.StructuredGraph; |
44 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; |
39 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; |
45 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; |
40 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; |
46 import org.graalvm.compiler.options.OptionValue; |
41 import org.graalvm.compiler.options.OptionValues; |
47 import org.graalvm.compiler.options.OptionValue.OverrideScope; |
|
48 import org.graalvm.compiler.phases.BasePhase; |
42 import org.graalvm.compiler.phases.BasePhase; |
49 import org.graalvm.compiler.phases.OptimisticOptimizations; |
43 import org.graalvm.compiler.phases.OptimisticOptimizations; |
50 import org.graalvm.compiler.phases.PhaseSuite; |
44 import org.graalvm.compiler.phases.PhaseSuite; |
51 import org.graalvm.compiler.phases.tiers.HighTierContext; |
45 import org.graalvm.compiler.phases.tiers.HighTierContext; |
52 import org.graalvm.compiler.phases.tiers.Suites; |
46 import org.graalvm.compiler.phases.tiers.Suites; |
60 import jdk.vm.ci.meta.TriState; |
54 import jdk.vm.ci.meta.TriState; |
61 |
55 |
62 public class AOTBackend { |
56 public class AOTBackend { |
63 |
57 |
64 private final Main main; |
58 private final Main main; |
|
59 private final OptionValues graalOptions; |
65 |
60 |
66 private final HotSpotBackend backend; |
61 private final HotSpotBackend backend; |
67 |
62 |
68 private final HotSpotProviders providers; |
63 private final HotSpotProviders providers; |
69 private final HotSpotCodeCacheProvider codeCache; |
64 private final HotSpotCodeCacheProvider codeCache; |
70 private final PhaseSuite<HighTierContext> graphBuilderSuite; |
65 private final PhaseSuite<HighTierContext> graphBuilderSuite; |
71 private final HighTierContext highTierContext; |
66 private final HighTierContext highTierContext; |
72 private final GraalFilters filters; |
67 private final GraalFilters filters; |
73 |
68 |
74 public AOTBackend(Main main, HotSpotBackend backend, GraalFilters filters) { |
69 public AOTBackend(Main main, OptionValues graalOptions, HotSpotBackend backend, GraalFilters filters) { |
75 this.main = main; |
70 this.main = main; |
|
71 this.graalOptions = graalOptions; |
76 this.backend = backend; |
72 this.backend = backend; |
77 this.filters = filters; |
73 this.filters = filters; |
78 providers = backend.getProviders(); |
74 providers = backend.getProviders(); |
79 codeCache = providers.getCodeCache(); |
75 codeCache = providers.getCodeCache(); |
80 graphBuilderSuite = initGraphBuilderSuite(backend, main.options.compileWithAssertions); |
76 graphBuilderSuite = initGraphBuilderSuite(backend, main.options.compileWithAssertions); |
85 return graphBuilderSuite; |
81 return graphBuilderSuite; |
86 } |
82 } |
87 |
83 |
88 private Suites getSuites() { |
84 private Suites getSuites() { |
89 // create suites every time, as we modify options for the compiler |
85 // create suites every time, as we modify options for the compiler |
90 return backend.getSuites().getDefaultSuites(); |
86 return backend.getSuites().getDefaultSuites(graalOptions); |
91 } |
87 } |
92 |
88 |
93 private LIRSuites getLirSuites() { |
89 private LIRSuites getLirSuites() { |
94 // create suites every time, as we modify options for the compiler |
90 // create suites every time, as we modify options for the compiler |
95 return backend.getSuites().getDefaultLIRSuites(); |
91 return backend.getSuites().getDefaultLIRSuites(graalOptions); |
96 } |
92 } |
97 |
93 |
98 @SuppressWarnings("try") |
94 @SuppressWarnings("try") |
99 public CompilationResult compileMethod(ResolvedJavaMethod resolvedMethod) { |
95 public CompilationResult compileMethod(ResolvedJavaMethod resolvedMethod) { |
100 try (OverrideScope s = OptionValue.override(ImmutableCode, true, GeneratePIC, true)) { |
96 StructuredGraph graph = buildStructuredGraph(resolvedMethod); |
101 StructuredGraph graph = buildStructuredGraph(resolvedMethod); |
97 if (graph != null) { |
102 if (graph != null) { |
98 return compileGraph(resolvedMethod, graph); |
103 return compileGraph(resolvedMethod, graph); |
|
104 } |
|
105 return null; |
|
106 } |
99 } |
|
100 return null; |
107 } |
101 } |
108 |
102 |
109 /** |
103 /** |
110 * Build a structured graph for the member. |
104 * Build a structured graph for the member. |
111 * |
105 * |
113 * @return structured graph |
107 * @return structured graph |
114 */ |
108 */ |
115 @SuppressWarnings("try") |
109 @SuppressWarnings("try") |
116 private StructuredGraph buildStructuredGraph(ResolvedJavaMethod javaMethod) { |
110 private StructuredGraph buildStructuredGraph(ResolvedJavaMethod javaMethod) { |
117 try (Scope s = Debug.scope("AOTParseMethod")) { |
111 try (Scope s = Debug.scope("AOTParseMethod")) { |
118 StructuredGraph graph = new StructuredGraph(javaMethod, StructuredGraph.AllowAssumptions.NO, false, CompilationIdentifier.INVALID_COMPILATION_ID); |
112 StructuredGraph graph = new StructuredGraph.Builder(graalOptions).method(javaMethod).useProfilingInfo(false).build(); |
119 graphBuilderSuite.apply(graph, highTierContext); |
113 graphBuilderSuite.apply(graph, highTierContext); |
120 return graph; |
114 return graph; |
121 } catch (Throwable e) { |
115 } catch (Throwable e) { |
122 handleError(javaMethod, e, " (building graph)"); |
116 handleError(javaMethod, e, " (building graph)"); |
123 } |
117 } |