8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.hotspot.stubs;
26
27 import static java.util.Collections.singletonList;
28 import static org.graalvm.compiler.core.GraalCompiler.emitBackEnd;
29 import static org.graalvm.compiler.core.GraalCompiler.emitFrontEnd;
30 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
31 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
32 import static org.graalvm.compiler.debug.DebugOptions.DebugStubsAndSnippets;
33 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER;
34 import static org.graalvm.util.CollectionsUtil.allMatch;
35
36 import java.util.ListIterator;
37 import java.util.concurrent.atomic.AtomicInteger;
38
39 import jdk.internal.vm.compiler.collections.EconomicSet;
40 import org.graalvm.compiler.code.CompilationResult;
41 import org.graalvm.compiler.core.common.CompilationIdentifier;
42 import org.graalvm.compiler.core.common.GraalOptions;
43 import org.graalvm.compiler.core.target.Backend;
44 import org.graalvm.compiler.debug.DebugContext;
45 import org.graalvm.compiler.debug.DebugContext.Description;
46 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
47 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
48 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
219
220 @SuppressWarnings("try")
221 private CompilationResult buildCompilationResult(DebugContext debug, final Backend backend) {
222 CompilationIdentifier compilationId = getStubCompilationId();
223 final StructuredGraph graph = getGraph(debug, compilationId);
224 CompilationResult compResult = new CompilationResult(compilationId, toString(), GeneratePIC.getValue(options));
225
226 // Stubs cannot be recompiled so they cannot be compiled with assumptions
227 assert graph.getAssumptions() == null;
228
229 if (!(graph.start() instanceof StubStartNode)) {
230 StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
231 newStart.setStateAfter(graph.start().stateAfter());
232 graph.replaceFixed(graph.start(), newStart);
233 }
234
235 try (DebugContext.Scope s0 = debug.scope("StubCompilation", graph, providers.getCodeCache())) {
236 Suites suites = createSuites();
237 emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites);
238 LIRSuites lirSuites = createLIRSuites();
239 emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites);
240 assert checkStubInvariants(compResult);
241 } catch (Throwable e) {
242 throw debug.handle(e);
243 }
244 return compResult;
245 }
246
247 /**
248 * Gets a {@link CompilationResult} that can be used for code generation. Required for AOT.
249 */
250 @SuppressWarnings("try")
251 public CompilationResult getCompilationResult(DebugContext debug, final Backend backend) {
252 try (DebugContext.Scope d = debug.scope("CompilingStub", providers.getCodeCache(), debugScopeContext())) {
253 return buildCompilationResult(debug, backend);
254 } catch (Throwable e) {
255 throw debug.handle(e);
256 }
257 }
258
259 public CompilationIdentifier getStubCompilationId() {
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.hotspot.stubs;
26
27 import static java.util.Collections.singletonList;
28 import static org.graalvm.compiler.core.GraalCompiler.emitFrontEnd;
29 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
30 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
31 import static org.graalvm.compiler.debug.DebugOptions.DebugStubsAndSnippets;
32 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER;
33 import static org.graalvm.util.CollectionsUtil.allMatch;
34
35 import java.util.ListIterator;
36 import java.util.concurrent.atomic.AtomicInteger;
37
38 import jdk.internal.vm.compiler.collections.EconomicSet;
39 import org.graalvm.compiler.code.CompilationResult;
40 import org.graalvm.compiler.core.common.CompilationIdentifier;
41 import org.graalvm.compiler.core.common.GraalOptions;
42 import org.graalvm.compiler.core.target.Backend;
43 import org.graalvm.compiler.debug.DebugContext;
44 import org.graalvm.compiler.debug.DebugContext.Description;
45 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
46 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
47 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
218
219 @SuppressWarnings("try")
220 private CompilationResult buildCompilationResult(DebugContext debug, final Backend backend) {
221 CompilationIdentifier compilationId = getStubCompilationId();
222 final StructuredGraph graph = getGraph(debug, compilationId);
223 CompilationResult compResult = new CompilationResult(compilationId, toString(), GeneratePIC.getValue(options));
224
225 // Stubs cannot be recompiled so they cannot be compiled with assumptions
226 assert graph.getAssumptions() == null;
227
228 if (!(graph.start() instanceof StubStartNode)) {
229 StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
230 newStart.setStateAfter(graph.start().stateAfter());
231 graph.replaceFixed(graph.start(), newStart);
232 }
233
234 try (DebugContext.Scope s0 = debug.scope("StubCompilation", graph, providers.getCodeCache())) {
235 Suites suites = createSuites();
236 emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites);
237 LIRSuites lirSuites = createLIRSuites();
238 backend.emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites);
239 assert checkStubInvariants(compResult);
240 } catch (Throwable e) {
241 throw debug.handle(e);
242 }
243 return compResult;
244 }
245
246 /**
247 * Gets a {@link CompilationResult} that can be used for code generation. Required for AOT.
248 */
249 @SuppressWarnings("try")
250 public CompilationResult getCompilationResult(DebugContext debug, final Backend backend) {
251 try (DebugContext.Scope d = debug.scope("CompilingStub", providers.getCodeCache(), debugScopeContext())) {
252 return buildCompilationResult(debug, backend);
253 } catch (Throwable e) {
254 throw debug.handle(e);
255 }
256 }
257
258 public CompilationIdentifier getStubCompilationId() {
|