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

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Graph.java

Print this page

        

*** 20,52 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.graph; ! import org.graalvm.compiler.debug.Debug; import org.graalvm.compiler.debug.DebugCloseable; ! import org.graalvm.compiler.debug.DebugCounter; ! import org.graalvm.compiler.debug.DebugTimer; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Node.ValueNumberable; import org.graalvm.compiler.graph.iterators.NodeIterable; import org.graalvm.compiler.options.Option; import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionType; import org.graalvm.compiler.options.OptionValues; import org.graalvm.util.EconomicMap; import org.graalvm.util.Equivalence; import org.graalvm.util.UnmodifiableEconomicMap; - import java.util.ArrayList; - import java.util.Arrays; - import java.util.Iterator; - import java.util.function.Consumer; - - import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED; - import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED; - /** * This class is a graph container, it contains the set of nodes that belong to this graph. */ public class Graph { --- 20,52 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.graph; ! import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED; ! import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED; ! ! import java.util.ArrayList; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.function.Consumer; ! ! import org.graalvm.compiler.debug.CounterKey; import org.graalvm.compiler.debug.DebugCloseable; ! import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.GraalError; + import org.graalvm.compiler.debug.TimerKey; import org.graalvm.compiler.graph.Node.ValueNumberable; import org.graalvm.compiler.graph.iterators.NodeIterable; import org.graalvm.compiler.options.Option; import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionType; import org.graalvm.compiler.options.OptionValues; import org.graalvm.util.EconomicMap; import org.graalvm.util.Equivalence; import org.graalvm.util.UnmodifiableEconomicMap; /** * This class is a graph container, it contains the set of nodes that belong to this graph. */ public class Graph {
*** 145,163 **** --- 145,173 ---- /** * The option values used while compiling this graph. */ private final OptionValues options; + /** + * The {@link DebugContext} used while compiling this graph. + */ + private final DebugContext debug; + private class NodeSourcePositionScope implements DebugCloseable { private final NodeSourcePosition previous; NodeSourcePositionScope(NodeSourcePosition sourcePosition) { previous = currentNodeSourcePosition; currentNodeSourcePosition = sourcePosition; } @Override + public DebugContext getDebug() { + return debug; + } + + @Override public void close() { currentNodeSourcePosition = previous; } }
*** 215,226 **** } /** * Creates an empty Graph with no name. */ ! public Graph(OptionValues options) { ! this(null, options); } /** * We only want the expensive modification count tracking when assertions are enabled for the * {@link Graph} class. --- 225,236 ---- } /** * Creates an empty Graph with no name. */ ! public Graph(OptionValues options, DebugContext debug) { ! this(null, options, debug); } /** * We only want the expensive modification count tracking when assertions are enabled for the * {@link Graph} class.
*** 237,252 **** /** * Creates an empty Graph with a given name. * * @param name the name of the graph, used for debugging purposes */ ! public Graph(String name, OptionValues options) { nodes = new Node[INITIAL_NODES_SIZE]; iterableNodesFirst = new ArrayList<>(NodeClass.allocatedNodeIterabledIds()); iterableNodesLast = new ArrayList<>(NodeClass.allocatedNodeIterabledIds()); this.name = name; this.options = options; if (isModificationCountsEnabled()) { nodeModCounts = new int[INITIAL_NODES_SIZE]; nodeUsageModCounts = new int[INITIAL_NODES_SIZE]; } --- 247,264 ---- /** * Creates an empty Graph with a given name. * * @param name the name of the graph, used for debugging purposes */ ! public Graph(String name, OptionValues options, DebugContext debug) { nodes = new Node[INITIAL_NODES_SIZE]; iterableNodesFirst = new ArrayList<>(NodeClass.allocatedNodeIterabledIds()); iterableNodesLast = new ArrayList<>(NodeClass.allocatedNodeIterabledIds()); this.name = name; this.options = options; + assert debug != null; + this.debug = debug; if (isModificationCountsEnabled()) { nodeModCounts = new int[INITIAL_NODES_SIZE]; nodeUsageModCounts = new int[INITIAL_NODES_SIZE]; }
*** 300,340 **** } } /** * Creates a copy of this graph. */ ! public final Graph copy() { ! return copy(name, null); } /** * Creates a copy of this graph. * * @param duplicationMapCallback consumer of the duplication map created during the copying */ ! public final Graph copy(Consumer<UnmodifiableEconomicMap<Node, Node>> duplicationMapCallback) { ! return copy(name, duplicationMapCallback); } /** * Creates a copy of this graph. * * @param newName the name of the copy, used for debugging purposes (can be null) */ ! public final Graph copy(String newName) { ! return copy(newName, null); } /** * Creates a copy of this graph. * * @param newName the name of the copy, used for debugging purposes (can be null) * @param duplicationMapCallback consumer of the duplication map created during the copying */ ! protected Graph copy(String newName, Consumer<UnmodifiableEconomicMap<Node, Node>> duplicationMapCallback) { ! Graph copy = new Graph(newName, options); UnmodifiableEconomicMap<Node, Node> duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), (EconomicMap<Node, Node>) null); if (duplicationMapCallback != null) { duplicationMapCallback.accept(duplicates); } return copy; --- 312,365 ---- } } /** * Creates a copy of this graph. + * + * @param debugForCopy the debug context for the graph copy. This must not be the debug for this + * graph if this graph can be accessed from multiple threads (e.g., it's in a cache + * accessed by multiple threads). */ ! public final Graph copy(DebugContext debugForCopy) { ! return copy(name, null, debugForCopy); } /** * Creates a copy of this graph. * * @param duplicationMapCallback consumer of the duplication map created during the copying + * @param debugForCopy the debug context for the graph copy. This must not be the debug for this + * graph if this graph can be accessed from multiple threads (e.g., it's in a cache + * accessed by multiple threads). */ ! public final Graph copy(Consumer<UnmodifiableEconomicMap<Node, Node>> duplicationMapCallback, DebugContext debugForCopy) { ! return copy(name, duplicationMapCallback, debugForCopy); } /** * Creates a copy of this graph. * * @param newName the name of the copy, used for debugging purposes (can be null) + * @param debugForCopy the debug context for the graph copy. This must not be the debug for this + * graph if this graph can be accessed from multiple threads (e.g., it's in a cache + * accessed by multiple threads). */ ! public final Graph copy(String newName, DebugContext debugForCopy) { ! return copy(newName, null, debugForCopy); } /** * Creates a copy of this graph. * * @param newName the name of the copy, used for debugging purposes (can be null) * @param duplicationMapCallback consumer of the duplication map created during the copying + * @param debugForCopy the debug context for the graph copy. This must not be the debug for this + * graph if this graph can be accessed from multiple threads (e.g., it's in a cache + * accessed by multiple threads). */ ! protected Graph copy(String newName, Consumer<UnmodifiableEconomicMap<Node, Node>> duplicationMapCallback, DebugContext debugForCopy) { ! Graph copy = new Graph(newName, options, debugForCopy); UnmodifiableEconomicMap<Node, Node> duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), (EconomicMap<Node, Node>) null); if (duplicationMapCallback != null) { duplicationMapCallback.accept(duplicates); } return copy;
*** 342,351 **** --- 367,380 ---- public final OptionValues getOptions() { return options; } + public DebugContext getDebug() { + return debug; + } + @Override public String toString() { return name == null ? super.toString() : "Graph " + name; }
*** 804,831 **** super(TYPE); } } ! private static final DebugCounter GraphCompressions = Debug.counter("GraphCompressions"); /** * If the {@linkplain Options#GraphCompressionThreshold compression threshold} is met, the list * of nodes is compressed such that all non-null entries precede all null entries while * preserving the ordering between the nodes within the list. */ public boolean maybeCompress() { ! if (Debug.isDumpEnabledForMethod() || Debug.isLogEnabledForMethod()) { return false; } int liveNodeCount = getNodeCount(); int liveNodePercent = liveNodeCount * 100 / nodesSize; int compressionThreshold = Options.GraphCompressionThreshold.getValue(options); if (compressionThreshold == 0 || liveNodePercent >= compressionThreshold) { return false; } ! GraphCompressions.increment(); int nextId = 0; for (int i = 0; nextId < liveNodeCount; i++) { Node n = nodes[i]; if (n != null) { assert n.id == i; --- 833,860 ---- super(TYPE); } } ! private static final CounterKey GraphCompressions = DebugContext.counter("GraphCompressions"); /** * If the {@linkplain Options#GraphCompressionThreshold compression threshold} is met, the list * of nodes is compressed such that all non-null entries precede all null entries while * preserving the ordering between the nodes within the list. */ public boolean maybeCompress() { ! if (debug.isDumpEnabledForMethod() || debug.isLogEnabledForMethod()) { return false; } int liveNodeCount = getNodeCount(); int liveNodePercent = liveNodeCount * 100 / nodesSize; int compressionThreshold = Options.GraphCompressionThreshold.getValue(options); if (compressionThreshold == 0 || liveNodePercent >= compressionThreshold) { return false; } ! GraphCompressions.increment(debug); int nextId = 0; for (int i = 0; nextId < liveNodeCount; i++) { Node n = nodes[i]; if (n != null) { assert n.id == i;
*** 1075,1085 **** int nodeIdCount() { return nodesSize; } /** ! * Adds duplicates of the nodes in {@code nodes} to this graph. This will recreate any edges * between the duplicate nodes. The {@code replacement} map can be used to replace a node from * the source graph by a given node (which must already be in this graph). Edges between * duplicate and replacement nodes will also be recreated so care should be taken regarding the * matching of node types in the replacement map. * --- 1104,1114 ---- int nodeIdCount() { return nodesSize; } /** ! * Adds duplicates of the nodes in {@code newNodes} to this graph. This will recreate any edges * between the duplicate nodes. The {@code replacement} map can be used to replace a node from * the source graph by a given node (which must already be in this graph). Edges between * duplicate and replacement nodes will also be recreated so care should be taken regarding the * matching of node types in the replacement map. *
*** 1116,1130 **** return replacement != null ? replacement : original; } } ! private static final DebugTimer DuplicateGraph = Debug.timer("DuplicateGraph"); @SuppressWarnings({"all", "try"}) public EconomicMap<Node, Node> addDuplicates(Iterable<? extends Node> newNodes, final Graph oldGraph, int estimatedNodeCount, DuplicationReplacement replacements) { ! try (DebugCloseable s = DuplicateGraph.start()) { return NodeClass.addGraphDuplicate(this, oldGraph, estimatedNodeCount, newNodes, replacements); } } public boolean isFrozen() { --- 1145,1159 ---- return replacement != null ? replacement : original; } } ! private static final TimerKey DuplicateGraph = DebugContext.timer("DuplicateGraph"); @SuppressWarnings({"all", "try"}) public EconomicMap<Node, Node> addDuplicates(Iterable<? extends Node> newNodes, final Graph oldGraph, int estimatedNodeCount, DuplicationReplacement replacements) { ! try (DebugCloseable s = DuplicateGraph.start(getDebug())) { return NodeClass.addGraphDuplicate(this, oldGraph, estimatedNodeCount, newNodes, replacements); } } public boolean isFrozen() {
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Graph.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File