src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.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.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java

Print this page

        

*** 21,38 **** --- 21,42 ---- * questions. */ package org.graalvm.compiler.replacements; import static org.graalvm.compiler.core.common.GraalOptions.UseSnippetGraphCache; + import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM; import static org.graalvm.compiler.java.BytecodeParserOptions.InlineDuringParsing; import static org.graalvm.compiler.java.BytecodeParserOptions.InlineIntrinsicsDuringParsing; import static org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createIntrinsicInlineInfo; import static org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext.INLINE_AFTER_PARSING; import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Required; + import java.util.Collections; + import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; + import java.util.concurrent.atomic.AtomicInteger; import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.api.replacements.MethodSubstitution; import org.graalvm.compiler.api.replacements.Snippet; import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
*** 40,54 **** import org.graalvm.compiler.bytecode.Bytecode; import org.graalvm.compiler.bytecode.BytecodeProvider; import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode; import org.graalvm.compiler.core.common.GraalOptions; import org.graalvm.compiler.core.common.spi.ConstantFieldProvider; - import org.graalvm.compiler.debug.Debug; - import org.graalvm.compiler.debug.Debug.Scope; import org.graalvm.compiler.debug.DebugCloseable; ! import org.graalvm.compiler.debug.DebugTimer; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.Node.NodeIntrinsic; import org.graalvm.compiler.java.GraphBuilderPhase; import org.graalvm.compiler.java.GraphBuilderPhase.Instance; import org.graalvm.compiler.nodes.CallTargetNode; --- 44,59 ---- import org.graalvm.compiler.bytecode.Bytecode; import org.graalvm.compiler.bytecode.BytecodeProvider; import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode; import org.graalvm.compiler.core.common.GraalOptions; import org.graalvm.compiler.core.common.spi.ConstantFieldProvider; import org.graalvm.compiler.debug.DebugCloseable; ! import org.graalvm.compiler.debug.DebugHandlersFactory; ! import org.graalvm.compiler.debug.DebugContext; ! import org.graalvm.compiler.debug.DebugContext.Description; import org.graalvm.compiler.debug.GraalError; + import org.graalvm.compiler.debug.TimerKey; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.Node.NodeIntrinsic; import org.graalvm.compiler.java.GraphBuilderPhase; import org.graalvm.compiler.java.GraphBuilderPhase.Instance; import org.graalvm.compiler.nodes.CallTargetNode;
*** 90,99 **** --- 95,105 ---- protected final OptionValues options; public final Providers providers; public final SnippetReflectionProvider snippetReflection; public final TargetDescription target; private GraphBuilderConfiguration.Plugins graphBuilderPlugins; + private final DebugHandlersFactory debugHandlersFactory; @Override public OptionValues getOptions() { return options; }
*** 178,218 **** // This map is key'ed by a class name instead of a Class object so that // it is stable across VM executions (in support of replay compilation). private final EconomicMap<String, SnippetTemplateCache> snippetTemplateCache; ! public ReplacementsImpl(OptionValues options, Providers providers, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider, TargetDescription target) { this.options = options; this.providers = providers.copyWith(this); this.snippetReflection = snippetReflection; this.target = target; this.graphs = new ConcurrentHashMap<>(); this.snippetTemplateCache = EconomicMap.create(Equivalence.DEFAULT); this.defaultBytecodeProvider = bytecodeProvider; } ! private static final DebugTimer SnippetPreparationTime = Debug.timer("SnippetPreparationTime"); @Override public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args) { return getSnippet(method, null, args); } @Override @SuppressWarnings("try") public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args) { assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName(); assert method.hasBytecodes() : "Snippet must not be abstract or native"; StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null; if (graph == null) { ! try (DebugCloseable a = SnippetPreparationTime.start()) { ! StructuredGraph newGraph = makeGraph(defaultBytecodeProvider, method, args, recursiveEntry); ! Debug.counter("SnippetNodeCount[%#s]", method).add(newGraph.getNodeCount()); if (!UseSnippetGraphCache.getValue(options) || args != null) { return newGraph; } graphs.putIfAbsent(method, newGraph); graph = graphs.get(method); } } return graph; --- 184,238 ---- // This map is key'ed by a class name instead of a Class object so that // it is stable across VM executions (in support of replay compilation). private final EconomicMap<String, SnippetTemplateCache> snippetTemplateCache; ! public ReplacementsImpl(OptionValues options, DebugHandlersFactory debugHandlersFactory, Providers providers, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider, ! TargetDescription target) { this.options = options; this.providers = providers.copyWith(this); this.snippetReflection = snippetReflection; this.target = target; this.graphs = new ConcurrentHashMap<>(); this.snippetTemplateCache = EconomicMap.create(Equivalence.DEFAULT); this.defaultBytecodeProvider = bytecodeProvider; + this.debugHandlersFactory = debugHandlersFactory; + } ! private static final TimerKey SnippetPreparationTime = DebugContext.timer("SnippetPreparationTime"); @Override public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args) { return getSnippet(method, null, args); } + private static final AtomicInteger nextDebugContextId = new AtomicInteger(); + + protected DebugContext openDebugContext(String idPrefix, ResolvedJavaMethod method) { + DebugContext outer = DebugContext.forCurrentThread(); + Description description = new Description(method, idPrefix + nextDebugContextId.incrementAndGet()); + List<DebugHandlersFactory> factories = debugHandlersFactory == null ? Collections.emptyList() : Collections.singletonList(debugHandlersFactory); + return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, factories); + } + @Override @SuppressWarnings("try") public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args) { assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName(); assert method.hasBytecodes() : "Snippet must not be abstract or native"; StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null; if (graph == null) { ! try (DebugContext debug = openDebugContext("Snippet_", method); ! DebugCloseable a = SnippetPreparationTime.start(debug)) { ! StructuredGraph newGraph = makeGraph(debug, defaultBytecodeProvider, method, args, recursiveEntry); ! DebugContext.counter("SnippetNodeCount[%#s]", method).add(newGraph.getDebug(), newGraph.getNodeCount()); if (!UseSnippetGraphCache.getValue(options) || args != null) { return newGraph; } + newGraph.freeze(); graphs.putIfAbsent(method, newGraph); graph = graphs.get(method); } } return graph;
*** 254,276 **** if (plugin instanceof MethodSubstitutionPlugin) { MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin; ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess); StructuredGraph graph = graphs.get(substitute); if (graph == null) { ! graph = makeGraph(msPlugin.getBytecodeProvider(), substitute, null, method); graph.freeze(); graphs.putIfAbsent(substitute, graph); graph = graphs.get(substitute); } assert graph.isFrozen(); result = graph; } else { Bytecode code = new ResolvedJavaMethodBytecode(method); ConstantReflectionProvider constantReflection = providers.getConstantReflection(); ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider(); StampProvider stampProvider = providers.getStampProvider(); ! result = new IntrinsicGraphBuilder(options, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin); } } else { result = null; } return result; --- 274,300 ---- if (plugin instanceof MethodSubstitutionPlugin) { MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin; ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess); StructuredGraph graph = graphs.get(substitute); if (graph == null) { ! try (DebugContext debug = openDebugContext("Substitution_", method)) { ! graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method); graph.freeze(); graphs.putIfAbsent(substitute, graph); graph = graphs.get(substitute); } + } assert graph.isFrozen(); result = graph; } else { Bytecode code = new ResolvedJavaMethodBytecode(method); ConstantReflectionProvider constantReflection = providers.getConstantReflection(); ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider(); StampProvider stampProvider = providers.getStampProvider(); ! try (DebugContext debug = openDebugContext("Substitution_", method)) { ! result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin); ! } } } else { result = null; } return result;
*** 283,294 **** * @param method the snippet or method substitution for which a graph will be created * @param args * @param original the original method if {@code method} is a {@linkplain MethodSubstitution * substitution} otherwise null */ ! public StructuredGraph makeGraph(BytecodeProvider bytecodeProvider, ResolvedJavaMethod method, Object[] args, ResolvedJavaMethod original) { ! return createGraphMaker(method, original).makeGraph(bytecodeProvider, args); } /** * Can be overridden to return an object that specializes various parts of graph preprocessing. */ --- 307,318 ---- * @param method the snippet or method substitution for which a graph will be created * @param args * @param original the original method if {@code method} is a {@linkplain MethodSubstitution * substitution} otherwise null */ ! public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, ResolvedJavaMethod method, Object[] args, ResolvedJavaMethod original) { ! return createGraphMaker(method, original).makeGraph(debug, bytecodeProvider, args); } /** * Can be overridden to return an object that specializes various parts of graph preprocessing. */
*** 321,342 **** this.method = substitute; this.substitutedMethod = substitutedMethod; } @SuppressWarnings("try") ! public StructuredGraph makeGraph(BytecodeProvider bytecodeProvider, Object[] args) { ! try (Scope s = Debug.scope("BuildSnippetGraph", method)) { assert method.hasBytecodes() : method; ! StructuredGraph graph = buildInitialGraph(bytecodeProvider, method, args); finalizeGraph(graph); ! Debug.dump(Debug.INFO_LEVEL, graph, "%s: Final", method.getName()); return graph; } catch (Throwable e) { ! throw Debug.handle(e); } } /** * Does final processing of a snippet graph. --- 345,366 ---- this.method = substitute; this.substitutedMethod = substitutedMethod; } @SuppressWarnings("try") ! public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, Object[] args) { ! try (DebugContext.Scope s = debug.scope("BuildSnippetGraph", method)) { assert method.hasBytecodes() : method; ! StructuredGraph graph = buildInitialGraph(debug, bytecodeProvider, method, args); finalizeGraph(graph); ! debug.dump(DebugContext.INFO_LEVEL, graph, "%s: Final", method.getName()); return graph; } catch (Throwable e) { ! throw debug.handle(e); } } /** * Does final processing of a snippet graph.
*** 388,407 **** /** * Builds the initial graph for a replacement. */ @SuppressWarnings("try") ! protected StructuredGraph buildInitialGraph(BytecodeProvider bytecodeProvider, final ResolvedJavaMethod methodToParse, Object[] args) { // Replacements cannot have optimistic assumptions since they have // to be valid for the entire run of the VM. ! final StructuredGraph graph = new StructuredGraph.Builder(replacements.options).method(methodToParse).build(); ! ! // They are not user code so they do not participate in unsafe access tracking graph.disableUnsafeAccessTracking(); ! try (Scope s = Debug.scope("buildInitialGraph", graph)) { MetaAccessProvider metaAccess = replacements.providers.getMetaAccess(); Plugins plugins = new Plugins(replacements.graphBuilderPlugins); GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins); if (args != null) { --- 412,431 ---- /** * Builds the initial graph for a replacement. */ @SuppressWarnings("try") ! protected StructuredGraph buildInitialGraph(DebugContext debug, BytecodeProvider bytecodeProvider, final ResolvedJavaMethod methodToParse, Object[] args) { // Replacements cannot have optimistic assumptions since they have // to be valid for the entire run of the VM. + final StructuredGraph graph = new StructuredGraph.Builder(replacements.options, debug).method(methodToParse).build(); ! // Replacements are not user code so they do not participate in unsafe access ! // tracking graph.disableUnsafeAccessTracking(); ! try (DebugContext.Scope s = debug.scope("buildInitialGraph", graph)) { MetaAccessProvider metaAccess = replacements.providers.getMetaAccess(); Plugins plugins = new Plugins(replacements.graphBuilderPlugins); GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins); if (args != null) {
*** 421,431 **** createGraphBuilder(metaAccess, replacements.providers.getStampProvider(), replacements.providers.getConstantReflection(), replacements.providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext).apply(graph); new CanonicalizerPhase().apply(graph, new PhaseContext(replacements.providers)); } catch (Throwable e) { ! throw Debug.handle(e); } return graph; } protected Instance createGraphBuilder(MetaAccessProvider metaAccess, StampProvider stampProvider, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider, --- 445,455 ---- createGraphBuilder(metaAccess, replacements.providers.getStampProvider(), replacements.providers.getConstantReflection(), replacements.providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext).apply(graph); new CanonicalizerPhase().apply(graph, new PhaseContext(replacements.providers)); } catch (Throwable e) { ! throw debug.handle(e); } return graph; } protected Instance createGraphBuilder(MetaAccessProvider metaAccess, StampProvider stampProvider, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider,
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File