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

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

Print this page

        

*** 21,32 **** * questions. */ package org.graalvm.compiler.replacements; import static java.util.FormattableFlags.ALTERNATE; ! import static org.graalvm.compiler.debug.Debug.applyFormattingFlagsAndWidth; ! import static org.graalvm.compiler.debug.GraalDebugConfig.Options.DebugStubsAndSnippets; import static org.graalvm.compiler.graph.iterators.NodePredicates.isNotA; import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED; import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED; import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Required; import static org.graalvm.word.LocationIdentity.any; --- 21,33 ---- * questions. */ package org.graalvm.compiler.replacements; import static java.util.FormattableFlags.ALTERNATE; ! import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM; ! import static org.graalvm.compiler.debug.DebugContext.applyFormattingFlagsAndWidth; ! import static org.graalvm.compiler.debug.DebugOptions.DebugStubsAndSnippets; import static org.graalvm.compiler.graph.iterators.NodePredicates.isNotA; import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED; import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED; import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Required; import static org.graalvm.word.LocationIdentity.any;
*** 40,49 **** --- 41,51 ---- import java.util.Formattable; import java.util.Formatter; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import org.graalvm.compiler.api.replacements.Snippet; import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
*** 53,70 **** import org.graalvm.compiler.core.common.GraalOptions; import org.graalvm.compiler.core.common.type.Stamp; import org.graalvm.compiler.core.common.type.StampFactory; import org.graalvm.compiler.core.common.type.StampPair; import org.graalvm.compiler.core.common.type.TypeReference; ! import org.graalvm.compiler.debug.Debug; ! import org.graalvm.compiler.debug.Debug.Scope; ! import org.graalvm.compiler.debug.internal.DebugScope; import org.graalvm.compiler.debug.DebugCloseable; ! import org.graalvm.compiler.debug.DebugConfig; ! import org.graalvm.compiler.debug.DebugCounter; ! import org.graalvm.compiler.debug.DebugTimer; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Graph.Mark; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.NodeClass; import org.graalvm.compiler.graph.Position; import org.graalvm.compiler.loop.LoopEx; --- 55,71 ---- import org.graalvm.compiler.core.common.GraalOptions; import org.graalvm.compiler.core.common.type.Stamp; import org.graalvm.compiler.core.common.type.StampFactory; import org.graalvm.compiler.core.common.type.StampPair; import org.graalvm.compiler.core.common.type.TypeReference; ! import org.graalvm.compiler.debug.CounterKey; 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.Graph.Mark; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.NodeClass; import org.graalvm.compiler.graph.Position; import org.graalvm.compiler.loop.LoopEx;
*** 225,250 **** /** * Times instantiations of all templates derived form this snippet. * * @see SnippetTemplate#instantiationTimer */ ! private final DebugTimer instantiationTimer; /** * Counts instantiations of all templates derived from this snippet. * * @see SnippetTemplate#instantiationCounter */ ! private final DebugCounter instantiationCounter; protected abstract Lazy lazy(); protected SnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations) { this.method = method; this.privateLocations = privateLocations; ! instantiationCounter = Debug.counter("SnippetInstantiationCount[%s]", method.getName()); ! instantiationTimer = Debug.timer("SnippetInstantiationTime[%s]", method.getName()); assert method.isStatic() : "snippet method must be static: " + method.format("%H.%n"); } public ResolvedJavaMethod getMethod() { return method; --- 226,251 ---- /** * Times instantiations of all templates derived form this snippet. * * @see SnippetTemplate#instantiationTimer */ ! private final TimerKey instantiationTimer; /** * Counts instantiations of all templates derived from this snippet. * * @see SnippetTemplate#instantiationCounter */ ! private final CounterKey instantiationCounter; protected abstract Lazy lazy(); protected SnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations) { this.method = method; this.privateLocations = privateLocations; ! instantiationCounter = DebugContext.counter("SnippetInstantiationCount[%s]", method.getName()); ! instantiationTimer = DebugContext.timer("SnippetInstantiationTime[%s]", method.getName()); assert method.isStatic() : "snippet method must be static: " + method.format("%H.%n"); } public ResolvedJavaMethod getMethod() { return method;
*** 560,571 **** public int hashCode() { return hash; } } ! private static final DebugTimer SnippetTemplateCreationTime = Debug.timer("SnippetTemplateCreationTime"); ! private static final DebugCounter SnippetTemplates = Debug.counter("SnippetTemplateCount"); static class Options { @Option(help = "Use a LRU cache for snippet templates.")// static final OptionKey<Boolean> UseSnippetTemplateCache = new OptionKey<>(true); --- 561,572 ---- public int hashCode() { return hash; } } ! private static final TimerKey SnippetTemplateCreationTime = DebugContext.timer("SnippetTemplateCreationTime"); ! private static final CounterKey SnippetTemplates = DebugContext.counter("SnippetTemplateCount"); static class Options { @Option(help = "Use a LRU cache for snippet templates.")// static final OptionKey<Boolean> UseSnippetTemplateCache = new OptionKey<>(true);
*** 579,596 **** public abstract static class AbstractTemplates implements org.graalvm.compiler.api.replacements.SnippetTemplateCache { protected final OptionValues options; protected final Providers providers; protected final SnippetReflectionProvider snippetReflection; protected final TargetDescription target; private final Map<CacheKey, SnippetTemplate> templates; ! protected AbstractTemplates(OptionValues options, Providers providers, SnippetReflectionProvider snippetReflection, TargetDescription target) { this.options = options; this.providers = providers; this.snippetReflection = snippetReflection; this.target = target; if (Options.UseSnippetTemplateCache.getValue(options)) { int size = Options.MaxTemplatesPerSnippet.getValue(options); this.templates = Collections.synchronizedMap(new LRUCache<>(size, size)); } else { this.templates = null; --- 580,599 ---- public abstract static class AbstractTemplates implements org.graalvm.compiler.api.replacements.SnippetTemplateCache { protected final OptionValues options; protected final Providers providers; protected final SnippetReflectionProvider snippetReflection; + protected final Iterable<DebugHandlersFactory> factories; protected final TargetDescription target; private final Map<CacheKey, SnippetTemplate> templates; ! protected AbstractTemplates(OptionValues options, Iterable<DebugHandlersFactory> factories, Providers providers, SnippetReflectionProvider snippetReflection, TargetDescription target) { this.options = options; this.providers = providers; this.snippetReflection = snippetReflection; this.target = target; + this.factories = factories; if (Options.UseSnippetTemplateCache.getValue(options)) { int size = Options.MaxTemplatesPerSnippet.getValue(options); this.templates = Collections.synchronizedMap(new LRUCache<>(size, size)); } else { this.templates = null;
*** 625,650 **** } else { return new LazySnippetInfo(javaMethod, privateLocations); } } /** * Gets a template for a given key, creating it first if necessary. */ @SuppressWarnings("try") ! protected SnippetTemplate template(final Arguments args) { SnippetTemplate template = Options.UseSnippetTemplateCache.getValue(options) && args.cacheable ? templates.get(args.cacheKey) : null; if (template == null) { ! SnippetTemplates.increment(); ! DebugConfig config = DebugStubsAndSnippets.getValue(options) ? DebugScope.getConfig() : Debug.silentConfig(); ! try (DebugCloseable a = SnippetTemplateCreationTime.start(); Scope s = Debug.sandbox("SnippetSpecialization", config, args.info.method)) { ! template = new SnippetTemplate(options, providers, snippetReflection, args); if (Options.UseSnippetTemplateCache.getValue(options) && args.cacheable) { templates.put(args.cacheKey, template); } } catch (Throwable e) { ! throw Debug.handle(e); } } return template; } } --- 628,664 ---- } else { return new LazySnippetInfo(javaMethod, privateLocations); } } + static final AtomicInteger nextSnippetTemplateId = new AtomicInteger(); + + private DebugContext openDebugContext(DebugContext outer, Arguments args) { + if (DebugStubsAndSnippets.getValue(options)) { + Description description = new Description(args.cacheKey.method, "SnippetTemplate_" + nextSnippetTemplateId.incrementAndGet()); + return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, factories); + } + return DebugContext.DISABLED; + } + /** * Gets a template for a given key, creating it first if necessary. */ @SuppressWarnings("try") ! protected SnippetTemplate template(DebugContext outer, final Arguments args) { SnippetTemplate template = Options.UseSnippetTemplateCache.getValue(options) && args.cacheable ? templates.get(args.cacheKey) : null; if (template == null) { ! try (DebugContext debug = openDebugContext(outer, args)) { ! try (DebugCloseable a = SnippetTemplateCreationTime.start(debug); DebugContext.Scope s = debug.scope("SnippetSpecialization", args.info.method)) { ! SnippetTemplates.increment(debug); ! template = new SnippetTemplate(options, debug, providers, snippetReflection, args); if (Options.UseSnippetTemplateCache.getValue(options) && args.cacheable) { templates.put(args.cacheKey, template); } } catch (Throwable e) { ! throw debug.handle(e); ! } } } return template; } }
*** 684,711 **** /** * Creates a snippet template. */ @SuppressWarnings("try") ! protected SnippetTemplate(OptionValues options, final Providers providers, SnippetReflectionProvider snippetReflection, Arguments args) { this.snippetReflection = snippetReflection; this.info = args.info; Object[] constantArgs = getConstantArgs(args); StructuredGraph snippetGraph = providers.getReplacements().getSnippet(args.info.method, args.info.original, constantArgs); ! instantiationTimer = Debug.timer("SnippetTemplateInstantiationTime[%#s]", args); ! instantiationCounter = Debug.counter("SnippetTemplateInstantiationCount[%#s]", args); ResolvedJavaMethod method = snippetGraph.method(); Signature signature = method.getSignature(); PhaseContext phaseContext = new PhaseContext(providers); // Copy snippet graph, replacing constant parameters with given arguments ! final StructuredGraph snippetCopy = new StructuredGraph.Builder(options).name(snippetGraph.name).method(snippetGraph.method()).build(); ! try (Debug.Scope scope = Debug.scope("SpecializeSnippet", snippetCopy)) { if (!snippetGraph.isUnsafeAccessTrackingEnabled()) { snippetCopy.disableUnsafeAccessTracking(); } EconomicMap<Node, Node> nodeReplacements = EconomicMap.create(Equivalence.IDENTITY); --- 698,725 ---- /** * Creates a snippet template. */ @SuppressWarnings("try") ! protected SnippetTemplate(OptionValues options, DebugContext debug, final Providers providers, SnippetReflectionProvider snippetReflection, Arguments args) { this.snippetReflection = snippetReflection; this.info = args.info; Object[] constantArgs = getConstantArgs(args); StructuredGraph snippetGraph = providers.getReplacements().getSnippet(args.info.method, args.info.original, constantArgs); ! instantiationTimer = DebugContext.timer("SnippetTemplateInstantiationTime[%#s]", args); ! instantiationCounter = DebugContext.counter("SnippetTemplateInstantiationCount[%#s]", args); ResolvedJavaMethod method = snippetGraph.method(); Signature signature = method.getSignature(); PhaseContext phaseContext = new PhaseContext(providers); // Copy snippet graph, replacing constant parameters with given arguments ! final StructuredGraph snippetCopy = new StructuredGraph.Builder(options, debug).name(snippetGraph.name).method(snippetGraph.method()).build(); ! try (DebugContext.Scope scope = debug.scope("SpecializeSnippet", snippetCopy)) { if (!snippetGraph.isUnsafeAccessTrackingEnabled()) { snippetCopy.disableUnsafeAccessTracking(); } EconomicMap<Node, Node> nodeReplacements = EconomicMap.create(Equivalence.IDENTITY);
*** 746,756 **** } } } snippetCopy.addDuplicates(snippetGraph.getNodes(), snippetGraph, snippetGraph.getNodeCount(), nodeReplacements); ! Debug.dump(Debug.INFO_LEVEL, snippetCopy, "Before specialization"); // Gather the template parameters parameters = new Object[parameterCount]; for (int i = 0; i < parameterCount; i++) { if (args.info.isConstantParameter(i)) { --- 760,770 ---- } } } snippetCopy.addDuplicates(snippetGraph.getNodes(), snippetGraph, snippetGraph.getNodeCount(), nodeReplacements); ! debug.dump(DebugContext.INFO_LEVEL, snippetCopy, "Before specialization"); // Gather the template parameters parameters = new Object[parameterCount]; for (int i = 0; i < parameterCount; i++) { if (args.info.isConstantParameter(i)) {
*** 774,787 **** VarargsPlaceholderNode placeholder = placeholders[i]; if (placeholder != null) { for (Node usage : placeholder.usages().snapshot()) { if (usage instanceof LoadIndexedNode) { LoadIndexedNode loadIndexed = (LoadIndexedNode) usage; ! Debug.dump(Debug.INFO_LEVEL, snippetCopy, "Before replacing %s", loadIndexed); LoadSnippetVarargParameterNode loadSnippetParameter = snippetCopy.add(new LoadSnippetVarargParameterNode(params, loadIndexed.index(), loadIndexed.stamp())); snippetCopy.replaceFixedWithFixed(loadIndexed, loadSnippetParameter); ! Debug.dump(Debug.INFO_LEVEL, snippetCopy, "After replacing %s", loadIndexed); } else if (usage instanceof StoreIndexedNode) { /* * The template lowering doesn't really treat this as an array so * you can't store back into the varargs. Allocate your own array if * you really need this and EA should eliminate it. --- 788,801 ---- VarargsPlaceholderNode placeholder = placeholders[i]; if (placeholder != null) { for (Node usage : placeholder.usages().snapshot()) { if (usage instanceof LoadIndexedNode) { LoadIndexedNode loadIndexed = (LoadIndexedNode) usage; ! debug.dump(DebugContext.INFO_LEVEL, snippetCopy, "Before replacing %s", loadIndexed); LoadSnippetVarargParameterNode loadSnippetParameter = snippetCopy.add(new LoadSnippetVarargParameterNode(params, loadIndexed.index(), loadIndexed.stamp())); snippetCopy.replaceFixedWithFixed(loadIndexed, loadSnippetParameter); ! debug.dump(DebugContext.INFO_LEVEL, snippetCopy, "After replacing %s", loadIndexed); } else if (usage instanceof StoreIndexedNode) { /* * The template lowering doesn't really treat this as an array so * you can't store back into the varargs. Allocate your own array if * you really need this and EA should eliminate it.
*** 807,820 **** // Perform lowering on the snippet if (!guardsStage.allowsFloatingGuards()) { new GuardLoweringPhase().apply(snippetCopy, null); } snippetCopy.setGuardsStage(guardsStage); ! try (Scope s = Debug.scope("LoweringSnippetTemplate", snippetCopy)) { new LoweringPhase(new CanonicalizerPhase(), args.cacheKey.loweringStage).apply(snippetCopy, phaseContext); } catch (Throwable e) { ! throw Debug.handle(e); } ArrayList<StateSplit> curSideEffectNodes = new ArrayList<>(); ArrayList<DeoptimizingNode> curDeoptNodes = new ArrayList<>(); ArrayList<ValueNode> curPlaceholderStampedNodes = new ArrayList<>(); --- 821,834 ---- // Perform lowering on the snippet if (!guardsStage.allowsFloatingGuards()) { new GuardLoweringPhase().apply(snippetCopy, null); } snippetCopy.setGuardsStage(guardsStage); ! try (DebugContext.Scope s = debug.scope("LoweringSnippetTemplate", snippetCopy)) { new LoweringPhase(new CanonicalizerPhase(), args.cacheKey.loweringStage).apply(snippetCopy, phaseContext); } catch (Throwable e) { ! throw debug.handle(e); } ArrayList<StateSplit> curSideEffectNodes = new ArrayList<>(); ArrayList<DeoptimizingNode> curDeoptNodes = new ArrayList<>(); ArrayList<ValueNode> curPlaceholderStampedNodes = new ArrayList<>();
*** 895,905 **** } else { anchor.safeDelete(); this.memoryAnchor = null; } } ! Debug.dump(Debug.INFO_LEVEL, snippet, "SnippetTemplate after fixing memory anchoring"); List<ReturnNode> returnNodes = snippet.getNodes(ReturnNode.TYPE).snapshot(); if (returnNodes.isEmpty()) { this.returnNode = null; } else if (returnNodes.size() == 1) { --- 909,919 ---- } else { anchor.safeDelete(); this.memoryAnchor = null; } } ! debug.dump(DebugContext.INFO_LEVEL, snippet, "SnippetTemplate after fixing memory anchoring"); List<ReturnNode> returnNodes = snippet.getNodes(ReturnNode.TYPE).snapshot(); if (returnNodes.isEmpty()) { this.returnNode = null; } else if (returnNodes.size() == 1) {
*** 939,953 **** if (node != entryPointNode && node != entryPointNode.stateAfter()) { nodes.add(node); } } ! Debug.counter("SnippetTemplateNodeCount[%#s]", args).add(nodes.size()); ! Debug.dump(Debug.INFO_LEVEL, snippet, "SnippetTemplate final state"); } catch (Throwable ex) { ! throw Debug.handle(ex); } } public static void explodeLoops(final StructuredGraph snippetCopy, PhaseContext phaseContext) { // Do any required loop explosion --- 953,970 ---- if (node != entryPointNode && node != entryPointNode.stateAfter()) { nodes.add(node); } } ! if (debug.areMetricsEnabled()) { ! DebugContext.counter("SnippetTemplateNodeCount[%#s]", args).add(debug, nodes.size()); ! } ! debug.dump(DebugContext.INFO_LEVEL, snippet, "SnippetTemplate final state"); ! this.snippet.freeze(); } catch (Throwable ex) { ! throw debug.handle(ex); } } public static void explodeLoops(final StructuredGraph snippetCopy, PhaseContext phaseContext) { // Do any required loop explosion
*** 1063,1080 **** /** * Times instantiations of this template. * * @see SnippetInfo#instantiationTimer */ ! private final DebugTimer instantiationTimer; /** * Counts instantiations of this template. * * @see SnippetInfo#instantiationCounter */ ! private final DebugCounter instantiationCounter; /** * Gets the instantiation-time bindings to this template's parameters. * * @return the map that will be used to bind arguments to parameters when inlining this template --- 1080,1097 ---- /** * Times instantiations of this template. * * @see SnippetInfo#instantiationTimer */ ! private final TimerKey instantiationTimer; /** * Counts instantiations of this template. * * @see SnippetInfo#instantiationCounter */ ! private final CounterKey instantiationCounter; /** * Gets the instantiation-time bindings to this template's parameters. * * @return the map that will be used to bind arguments to parameters when inlining this template
*** 1385,1406 **** * @param killReplacee is true, the replacee node is deleted * @return the map of duplicated nodes (original -&gt; duplicate) */ @SuppressWarnings("try") public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, UsageReplacer replacer, Arguments args, boolean killReplacee) { assert assertSnippetKills(replacee); ! try (DebugCloseable a = args.info.instantiationTimer.start(); DebugCloseable b = instantiationTimer.start()) { ! args.info.instantiationCounter.increment(); ! instantiationCounter.increment(); // Inline the snippet nodes, replacing parameters with the given args in the process StartNode entryPointNode = snippet.start(); FixedNode firstCFGNode = entryPointNode.next(); StructuredGraph replaceeGraph = replacee.graph(); EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args); replacements.put(entryPointNode, AbstractBeginNode.prevBegin(replacee)); UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements); ! Debug.dump(Debug.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method()); // Re-wire the control flow graph around the replacee FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); replacee.replaceAtPredecessor(firstCFGNodeDuplicate); --- 1402,1424 ---- * @param killReplacee is true, the replacee node is deleted * @return the map of duplicated nodes (original -&gt; duplicate) */ @SuppressWarnings("try") public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, UsageReplacer replacer, Arguments args, boolean killReplacee) { + DebugContext debug = replacee.getDebug(); assert assertSnippetKills(replacee); ! try (DebugCloseable a = args.info.instantiationTimer.start(debug); DebugCloseable b = instantiationTimer.start(debug)) { ! args.info.instantiationCounter.increment(debug); ! instantiationCounter.increment(debug); // Inline the snippet nodes, replacing parameters with the given args in the process StartNode entryPointNode = snippet.start(); FixedNode firstCFGNode = entryPointNode.next(); StructuredGraph replaceeGraph = replacee.graph(); EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args); replacements.put(entryPointNode, AbstractBeginNode.prevBegin(replacee)); UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements); ! debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method()); // Re-wire the control flow graph around the replacee FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); replacee.replaceAtPredecessor(firstCFGNodeDuplicate);
*** 1484,1494 **** if (killReplacee) { // Remove the replacee from its graph GraphUtil.killCFG(replacee); } ! Debug.dump(Debug.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this); return duplicates; } } private void propagateStamp(Node node) { --- 1502,1512 ---- if (killReplacee) { // Remove the replacee from its graph GraphUtil.killCFG(replacee); } ! debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this); return duplicates; } } private void propagateStamp(Node node) {
*** 1522,1533 **** } /** * Gets a copy of the specialized graph. */ ! public StructuredGraph copySpecializedGraph() { ! return (StructuredGraph) snippet.copy(); } /** * Replaces a given floating node with this specialized snippet. * --- 1540,1551 ---- } /** * Gets a copy of the specialized graph. */ ! public StructuredGraph copySpecializedGraph(DebugContext debugForCopy) { ! return (StructuredGraph) snippet.copy(debugForCopy); } /** * Replaces a given floating node with this specialized snippet. *
*** 1537,1559 **** * @param tool lowering tool used to insert the snippet into the control-flow * @param args the arguments to be bound to the flattened positional parameters of the snippet */ @SuppressWarnings("try") public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, LoweringTool tool, Arguments args) { assert assertSnippetKills(replacee); ! try (DebugCloseable a = args.info.instantiationTimer.start()) { ! args.info.instantiationCounter.increment(); ! instantiationCounter.increment(); // Inline the snippet nodes, replacing parameters with the given args in the process StartNode entryPointNode = snippet.start(); FixedNode firstCFGNode = entryPointNode.next(); StructuredGraph replaceeGraph = replacee.graph(); EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args); replacements.put(entryPointNode, tool.getCurrentGuardAnchor().asNode()); UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements); ! Debug.dump(Debug.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method()); FixedWithNextNode lastFixedNode = tool.lastFixedNode(); assert lastFixedNode != null && lastFixedNode.isAlive() : replaceeGraph + " lastFixed=" + lastFixedNode; FixedNode next = lastFixedNode.next(); lastFixedNode.setNext(null); --- 1555,1578 ---- * @param tool lowering tool used to insert the snippet into the control-flow * @param args the arguments to be bound to the flattened positional parameters of the snippet */ @SuppressWarnings("try") public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, LoweringTool tool, Arguments args) { + DebugContext debug = replacee.getDebug(); assert assertSnippetKills(replacee); ! try (DebugCloseable a = args.info.instantiationTimer.start(debug)) { ! args.info.instantiationCounter.increment(debug); ! instantiationCounter.increment(debug); // Inline the snippet nodes, replacing parameters with the given args in the process StartNode entryPointNode = snippet.start(); FixedNode firstCFGNode = entryPointNode.next(); StructuredGraph replaceeGraph = replacee.graph(); EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args); replacements.put(entryPointNode, tool.getCurrentGuardAnchor().asNode()); UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements); ! debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method()); FixedWithNextNode lastFixedNode = tool.lastFixedNode(); assert lastFixedNode != null && lastFixedNode.isAlive() : replaceeGraph + " lastFixed=" + lastFixedNode; FixedNode next = lastFixedNode.next(); lastFixedNode.setNext(null);
*** 1573,1583 **** if (returnDuplicate.isAlive()) { returnDuplicate.replaceAndDelete(next); } ! Debug.dump(Debug.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this); } } /** * Replaces a given floating node with this specialized snippet. --- 1592,1602 ---- if (returnDuplicate.isAlive()) { returnDuplicate.replaceAndDelete(next); } ! debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this); } } /** * Replaces a given floating node with this specialized snippet.
*** 1589,1602 **** * @param replacer object that replaces the usages of {@code replacee} * @param args the arguments to be bound to the flattened positional parameters of the snippet */ @SuppressWarnings("try") public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, Arguments args) { assert assertSnippetKills(replacee); ! try (DebugCloseable a = args.info.instantiationTimer.start()) { ! args.info.instantiationCounter.increment(); ! instantiationCounter.increment(); // Inline the snippet nodes, replacing parameters with the given args in the process StartNode entryPointNode = snippet.start(); assert entryPointNode.next() == (memoryAnchor == null ? returnNode : memoryAnchor) : entryPointNode.next(); StructuredGraph replaceeGraph = replacee.graph(); --- 1608,1622 ---- * @param replacer object that replaces the usages of {@code replacee} * @param args the arguments to be bound to the flattened positional parameters of the snippet */ @SuppressWarnings("try") public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, Arguments args) { + DebugContext debug = replacee.getDebug(); assert assertSnippetKills(replacee); ! try (DebugCloseable a = args.info.instantiationTimer.start(debug)) { ! args.info.instantiationCounter.increment(debug); ! instantiationCounter.increment(debug); // Inline the snippet nodes, replacing parameters with the given args in the process StartNode entryPointNode = snippet.start(); assert entryPointNode.next() == (memoryAnchor == null ? returnNode : memoryAnchor) : entryPointNode.next(); StructuredGraph replaceeGraph = replacee.graph();
*** 1611,1621 **** if (n != entryPointNode && n != returnNode) { floatingNodes.add(n); } } UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(floatingNodes, snippet, floatingNodes.size(), replacements); ! Debug.dump(Debug.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method()); rewireFrameStates(replacee, duplicates); updateStamps(replacee, duplicates); rewireMemoryGraph(replacee, duplicates); --- 1631,1641 ---- if (n != entryPointNode && n != returnNode) { floatingNodes.add(n); } } UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(floatingNodes, snippet, floatingNodes.size(), replacements); ! debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method()); rewireFrameStates(replacee, duplicates); updateStamps(replacee, duplicates); rewireMemoryGraph(replacee, duplicates);
*** 1623,1633 **** // Replace all usages of the replacee with the value returned by the snippet ValueNode returnValue = (ValueNode) duplicates.get(returnNode.result()); replacer.replace(replacee, returnValue); ! Debug.dump(Debug.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this); } } protected void rewireFrameStates(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates) { if (replacee instanceof StateSplit) { --- 1643,1653 ---- // Replace all usages of the replacee with the value returned by the snippet ValueNode returnValue = (ValueNode) duplicates.get(returnNode.result()); replacer.replace(replacee, returnValue); ! debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this); } } protected void rewireFrameStates(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates) { if (replacee instanceof StateSplit) {
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetTemplate.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File