src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java

Print this page

        

*** 20,45 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.hotspot.stubs; import static org.graalvm.compiler.core.GraalCompiler.emitBackEnd; import static org.graalvm.compiler.core.GraalCompiler.emitFrontEnd; import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; ! import static org.graalvm.compiler.debug.GraalDebugConfig.Options.DebugStubsAndSnippets; import static org.graalvm.compiler.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER; import static org.graalvm.util.CollectionsUtil.allMatch; import java.util.ListIterator; import org.graalvm.compiler.code.CompilationResult; import org.graalvm.compiler.core.common.CompilationIdentifier; import org.graalvm.compiler.core.target.Backend; ! import org.graalvm.compiler.debug.Debug; ! import org.graalvm.compiler.debug.Debug.Scope; ! import org.graalvm.compiler.debug.DebugConfig; ! import org.graalvm.compiler.debug.internal.DebugScope; import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder; import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; import org.graalvm.compiler.hotspot.meta.HotSpotProviders; import org.graalvm.compiler.hotspot.nodes.StubStartNode; import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory; --- 20,46 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.hotspot.stubs; + import static java.util.Collections.singletonList; import static org.graalvm.compiler.core.GraalCompiler.emitBackEnd; import static org.graalvm.compiler.core.GraalCompiler.emitFrontEnd; import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; ! import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM; ! import static org.graalvm.compiler.debug.DebugOptions.DebugStubsAndSnippets; import static org.graalvm.compiler.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER; import static org.graalvm.util.CollectionsUtil.allMatch; import java.util.ListIterator; + import java.util.concurrent.atomic.AtomicInteger; import org.graalvm.compiler.code.CompilationResult; import org.graalvm.compiler.core.common.CompilationIdentifier; import org.graalvm.compiler.core.target.Backend; ! import org.graalvm.compiler.debug.DebugContext; ! import org.graalvm.compiler.debug.DebugContext.Description; import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder; import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; import org.graalvm.compiler.hotspot.meta.HotSpotProviders; import org.graalvm.compiler.hotspot.nodes.StubStartNode; import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
*** 50,59 **** --- 51,61 ---- import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.OptimisticOptimizations; import org.graalvm.compiler.phases.PhaseSuite; import org.graalvm.compiler.phases.tiers.Suites; + import org.graalvm.compiler.printer.GraalDebugHandlersFactory; import org.graalvm.util.EconomicSet; import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.Register;
*** 153,163 **** /** * Gets the graph that from which the code for this stub will be compiled. * * @param compilationId unique compilation id for the stub */ ! protected abstract StructuredGraph getGraph(CompilationIdentifier compilationId); @Override public String toString() { return "Stub<" + linkage.getDescriptor() + ">"; } --- 155,165 ---- /** * Gets the graph that from which the code for this stub will be compiled. * * @param compilationId unique compilation id for the stub */ ! protected abstract StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId); @Override public String toString() { return "Stub<" + linkage.getDescriptor() + ">"; }
*** 170,243 **** /** * Gets a context object for the debug scope created when producing the code for this stub. */ protected abstract Object debugScopeContext(); /** * Gets the code for this stub, compiling it first if necessary. */ @SuppressWarnings("try") public synchronized InstalledCode getCode(final Backend backend) { if (code == null) { ! DebugConfig config = DebugStubsAndSnippets.getValue(options) ? DebugScope.getConfig() : Debug.silentConfig(); ! try (Scope d = Debug.sandbox("CompilingStub", config, providers.getCodeCache(), debugScopeContext())) { CodeCacheProvider codeCache = providers.getCodeCache(); ! ! CompilationResult compResult = buildCompilationResult(backend); ! try (Scope s = Debug.scope("CodeInstall", compResult)) { assert destroyedCallerRegisters != null; // Add a GeneratePIC check here later, we don't want to install // code if we don't have a corresponding VM global symbol. HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, null, null, compResult); code = codeCache.installCode(null, compiledCode, null, null, false); } catch (Throwable e) { ! throw Debug.handle(e); } } catch (Throwable e) { ! throw Debug.handle(e); } assert code != null : "error installing stub " + this; } return code; } @SuppressWarnings("try") ! private CompilationResult buildCompilationResult(final Backend backend) { CompilationResult compResult = new CompilationResult(toString(), GeneratePIC.getValue(options)); ! final StructuredGraph graph = getGraph(getStubCompilationId()); // Stubs cannot be recompiled so they cannot be compiled with assumptions assert graph.getAssumptions() == null; if (!(graph.start() instanceof StubStartNode)) { StubStartNode newStart = graph.add(new StubStartNode(Stub.this)); newStart.setStateAfter(graph.start().stateAfter()); graph.replaceFixed(graph.start(), newStart); } ! try (Scope s0 = Debug.scope("StubCompilation", graph, providers.getCodeCache())) { Suites suites = createSuites(); emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites); LIRSuites lirSuites = createLIRSuites(); emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites); assert checkStubInvariants(compResult); } catch (Throwable e) { ! throw Debug.handle(e); } return compResult; } /** * Gets a {@link CompilationResult} that can be used for code generation. Required for AOT. */ @SuppressWarnings("try") ! public CompilationResult getCompilationResult(final Backend backend) { ! try (Scope d = Debug.sandbox("CompilingStub", DebugScope.getConfig(), providers.getCodeCache(), debugScopeContext())) { ! return buildCompilationResult(backend); } catch (Throwable e) { ! throw Debug.handle(e); } } public CompilationIdentifier getStubCompilationId() { return new StubCompilationIdentifier(this); --- 172,256 ---- /** * Gets a context object for the debug scope created when producing the code for this stub. */ protected abstract Object debugScopeContext(); + private static final AtomicInteger nextStubId = new AtomicInteger(); + + private DebugContext openDebugContext(DebugContext outer) { + if (DebugStubsAndSnippets.getValue(options)) { + Description description = new Description(linkage, "Stub_" + nextStubId.incrementAndGet()); + return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, singletonList(new GraalDebugHandlersFactory(providers.getSnippetReflection()))); + } + return DebugContext.DISABLED; + } + /** * Gets the code for this stub, compiling it first if necessary. */ @SuppressWarnings("try") public synchronized InstalledCode getCode(final Backend backend) { if (code == null) { ! try (DebugContext debug = openDebugContext(DebugContext.forCurrentThread())) { ! try (DebugContext.Scope d = debug.scope("CompilingStub", providers.getCodeCache(), debugScopeContext())) { CodeCacheProvider codeCache = providers.getCodeCache(); ! CompilationResult compResult = buildCompilationResult(debug, backend); ! try (DebugContext.Scope s = debug.scope("CodeInstall", compResult); ! DebugContext.Activation a = debug.activate()) { assert destroyedCallerRegisters != null; // Add a GeneratePIC check here later, we don't want to install // code if we don't have a corresponding VM global symbol. HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, null, null, compResult); code = codeCache.installCode(null, compiledCode, null, null, false); } catch (Throwable e) { ! throw debug.handle(e); } } catch (Throwable e) { ! throw debug.handle(e); } assert code != null : "error installing stub " + this; } + } return code; } @SuppressWarnings("try") ! private CompilationResult buildCompilationResult(DebugContext debug, final Backend backend) { CompilationResult compResult = new CompilationResult(toString(), GeneratePIC.getValue(options)); ! final StructuredGraph graph = getGraph(debug, getStubCompilationId()); // Stubs cannot be recompiled so they cannot be compiled with assumptions assert graph.getAssumptions() == null; if (!(graph.start() instanceof StubStartNode)) { StubStartNode newStart = graph.add(new StubStartNode(Stub.this)); newStart.setStateAfter(graph.start().stateAfter()); graph.replaceFixed(graph.start(), newStart); } ! try (DebugContext.Scope s0 = debug.scope("StubCompilation", graph, providers.getCodeCache())) { Suites suites = createSuites(); emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites); LIRSuites lirSuites = createLIRSuites(); emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites); assert checkStubInvariants(compResult); } catch (Throwable e) { ! throw debug.handle(e); } return compResult; } /** * Gets a {@link CompilationResult} that can be used for code generation. Required for AOT. */ @SuppressWarnings("try") ! public CompilationResult getCompilationResult(DebugContext debug, final Backend backend) { ! try (DebugContext.Scope d = debug.scope("CompilingStub", providers.getCodeCache(), debugScopeContext())) { ! return buildCompilationResult(debug, backend); } catch (Throwable e) { ! throw debug.handle(e); } } public CompilationIdentifier getStubCompilationId() { return new StubCompilationIdentifier(this);
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File