public class Graph extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Graph.DuplicationReplacement |
static class |
Graph.Mark
A snapshot of the live node count in a graph.
|
static class |
Graph.NodeEvent
The type of events sent to a
Graph.NodeEventListener. |
static class |
Graph.NodeEventListener
Client interested in one or more node related events.
|
class |
Graph.NodeEventScope
Registers a given
Graph.NodeEventListener with the enclosing graph until this object is
closed. |
static class |
Graph.Options |
| Modifier and Type | Field and Description |
|---|---|
String |
name |
protected boolean |
trackNodeSourcePosition
Records if updating of node source information is required when performing inlining.
|
boolean |
verifyGraphEdges |
boolean |
verifyGraphs
Cached actual value of the
Graph.Options to avoid expensive map lookup for every time a
node / graph is verified. |
| Constructor and Description |
|---|
Graph(OptionValues options,
DebugContext debug)
Creates an empty Graph with no name.
|
Graph(String name,
OptionValues options,
DebugContext debug,
boolean trackNodeSourcePosition)
Creates an empty Graph with a given name.
|
| Modifier and Type | Method and Description |
|---|---|
<T extends Node> |
add(T node)
Adds a new node to the graph.
|
org.graalvm.collections.EconomicMap<Node,Node> |
addDuplicates(Iterable<? extends Node> newNodes,
Graph oldGraph,
int estimatedNodeCount,
org.graalvm.collections.EconomicMap<Node,Node> replacementsMap)
Adds duplicates of the nodes in
newNodes to this graph. |
org.graalvm.collections.EconomicMap<Node,Node> |
addDuplicates(Iterable<? extends Node> newNodes,
Graph oldGraph,
int estimatedNodeCount,
Graph.DuplicationReplacement replacements) |
<T extends Node> |
addOrUnique(T node) |
<T extends Node> |
addOrUniqueWithInputs(T node) |
<T extends Node> |
addWithoutUnique(T node) |
<T extends Node> |
addWithoutUniqueWithInputs(T node) |
void |
afterDecodingFields(Node node)
Notifies node event listeners registered with this graph that
node has been created
as part of decoding a graph and its fields have now been initialized. |
protected void |
afterNodeIdChange(Node node,
Object value) |
protected void |
afterRegister(Node node) |
void |
beforeDecodingFields(Node node)
Notifies node event listeners registered with this graph that
node has been created
as part of decoding a graph but its fields have yet to be initialized. |
void |
beforeNodeDuplication(Graph sourceGraph)
This is called before nodes are transferred to
sourceGraph by
NodeClass.addGraphDuplicate(org.graalvm.compiler.graph.Graph, org.graalvm.compiler.graph.Graph, int, java.lang.Iterable<? extends org.graalvm.compiler.graph.Node>, org.graalvm.compiler.graph.Graph.DuplicationReplacement) to allow the transfer of any other state which should
also be transferred. |
protected Object |
beforeNodeIdChange(Node node) |
protected boolean |
compress(boolean minimizeSize) |
Graph |
copy(Consumer<org.graalvm.collections.UnmodifiableEconomicMap<Node,Node>> duplicationMapCallback,
DebugContext debugForCopy)
Creates a copy of this graph.
|
Graph |
copy(DebugContext debugForCopy)
Creates a copy of this graph.
|
protected Graph |
copy(String newName,
Consumer<org.graalvm.collections.UnmodifiableEconomicMap<Node,Node>> duplicationMapCallback,
DebugContext debugForCopy)
Creates a copy of this graph.
|
Graph |
copy(String newName,
DebugContext debugForCopy)
Creates a copy of this graph.
|
NodeWorkList |
createIterativeNodeWorkList(boolean fill,
int iterationLimitPerNode) |
NodeBitMap |
createNodeBitMap() |
NodeFlood |
createNodeFlood() |
<T> NodeMap<T> |
createNodeMap() |
NodeWorkList |
createNodeWorkList() |
NodeSourcePosition |
currentNodeSourcePosition() |
<T extends Node> |
findDuplicate(T node)
Returns a possible duplicate for the given node in the graph or
null if no such
duplicate exists. |
void |
freeze() |
int |
getCompressions()
Gets the number of times this graph has been compressed.
|
DebugContext |
getDebug() |
void |
getDebugProperties(Map<Object,Object> properties)
Add any per graph properties that might be useful for debugging (e.g., to view in the ideal
graph visualizer).
|
int |
getEdgeModificationCount() |
Graph.Mark |
getMark()
Gets a mark that can be used with
Graph.getNewNodes(org.graalvm.compiler.graph.Graph.Mark). |
NodeIterable<Node> |
getNewNodes(Graph.Mark mark)
|
Node |
getNode(int id) |
int |
getNodeCount()
Gets the number of live nodes in this graph.
|
NodeIterable<Node> |
getNodes()
Returns an
Iterable providing all the live nodes. |
<T extends Node & IterableNodeType> |
getNodes(NodeClass<T> nodeClass)
Returns an
Iterable providing all the live nodes whose type is compatible with
type. |
int |
getNodesDeletedSinceLastCompression()
Gets the number of nodes which have been deleted from this graph since it was last
compressed.
|
OptionValues |
getOptions() |
int |
getTotalNodesDeleted()
Gets the total number of nodes which have been deleted from this graph.
|
<T extends Node & IterableNodeType> |
hasNode(NodeClass<T> type)
Returns whether the graph contains at least one node of the given type.
|
boolean |
isFrozen() |
boolean |
isNew(Graph.Mark mark,
Node node) |
static boolean |
isNodeModificationCountsEnabled()
We only want the expensive modification count tracking when assertions are enabled for the
Graph class. |
boolean |
maybeCompress()
If the 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.
|
void |
minimizeSize()
Minimize the memory occupied by the graph by trimming all node arrays to the minimum size.
|
int |
nodeIdCount()
Returns the number of node ids generated so far.
|
void |
resetDebug(DebugContext newDebug)
Resets the
DebugContext for this graph to a new value. |
void |
setTrackNodeSourcePosition() |
void |
temporaryFreeze() |
String |
toString() |
Graph.NodeEventScope |
trackNodeEvents(Graph.NodeEventListener listener)
Registers a given
Graph.NodeEventListener with this graph. |
boolean |
trackNodeSourcePosition() |
static boolean |
trackNodeSourcePositionDefault(OptionValues options,
DebugContext debug) |
void |
unfreeze() |
<T extends Node & Node.ValueNumberable> |
unique(T node)
Looks for a node similar to
node and returns it if found. |
boolean |
verify() |
boolean |
verifySourcePositions(boolean performConsistencyCheck) |
DebugCloseable |
withNodeSourcePosition(Node node)
Opens a scope in which the source information from
node is copied into nodes created
within the scope. |
DebugCloseable |
withNodeSourcePosition(NodeSourcePosition sourcePosition)
Opens a scope in which
sourcePosition is copied into nodes created within the scope. |
DebugCloseable |
withoutNodeSourcePosition()
Opens a scope in which newly created nodes do not get any source information added.
|
public final String name
public final boolean verifyGraphs
Graph.Options to avoid expensive map lookup for every time a
node / graph is verified.public final boolean verifyGraphEdges
protected boolean trackNodeSourcePosition
public Graph(OptionValues options, DebugContext debug)
public Graph(String name, OptionValues options, DebugContext debug, boolean trackNodeSourcePosition)
name - the name of the graph, used for debugging purposespublic NodeSourcePosition currentNodeSourcePosition()
public DebugCloseable withNodeSourcePosition(Node node)
node is copied into nodes created
within the scope. If node has no source information information, no scope is opened
and null is returned.DebugCloseable for managing the opened scope or null if no scope
was openedpublic DebugCloseable withNodeSourcePosition(NodeSourcePosition sourcePosition)
sourcePosition is copied into nodes created within the scope.
If sourcePosition == null, no scope is opened and null is returned.DebugCloseable for managing the opened scope or null if no scope
was openedpublic DebugCloseable withoutNodeSourcePosition()
DebugCloseable for managing the opened scopepublic boolean trackNodeSourcePosition()
public void setTrackNodeSourcePosition()
public static boolean trackNodeSourcePositionDefault(OptionValues options, DebugContext debug)
public void getDebugProperties(Map<Object,Object> properties)
public void beforeNodeDuplication(Graph sourceGraph)
sourceGraph by
NodeClass.addGraphDuplicate(org.graalvm.compiler.graph.Graph, org.graalvm.compiler.graph.Graph, int, java.lang.Iterable<? extends org.graalvm.compiler.graph.Node>, org.graalvm.compiler.graph.Graph.DuplicationReplacement) to allow the transfer of any other state which should
also be transferred.sourceGraph - the source of the nodes that were duplicatedpublic static boolean isNodeModificationCountsEnabled()
Graph class.public int getEdgeModificationCount()
public final Graph copy(DebugContext debugForCopy)
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<org.graalvm.collections.UnmodifiableEconomicMap<Node,Node>> duplicationMapCallback, DebugContext debugForCopy)
duplicationMapCallback - consumer of the duplication map created during the copyingdebugForCopy - 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)
newName - the name of the copy, used for debugging purposes (can be null)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<org.graalvm.collections.UnmodifiableEconomicMap<Node,Node>> duplicationMapCallback, DebugContext debugForCopy)
newName - the name of the copy, used for debugging purposes (can be null)duplicationMapCallback - consumer of the duplication map created during the copyingdebugForCopy - 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 OptionValues getOptions()
public DebugContext getDebug()
public void resetDebug(DebugContext newDebug)
DebugContext for this graph to a new value. This is useful when a graph is
"handed over" from its creating thread to another thread.
This must only be done when the current thread is no longer using the graph. This is in
general impossible to test due to races and since metrics can be updated at any time. As
such, this method only performs a weak sanity check that at least the current debug context
does not have a nested scope open (the top level scope will always be open if scopes are
enabled).public int getNodeCount()
public int getCompressions()
NodeIdAccessor.public int getNodesDeletedSinceLastCompression()
public int getTotalNodesDeleted()
public <T extends Node> T add(T node)
node - the node to be addedpublic <T extends Node> T addWithoutUnique(T node)
public <T extends Node> T addOrUnique(T node)
public <T extends Node> T addOrUniqueWithInputs(T node)
public <T extends Node> T addWithoutUniqueWithInputs(T node)
public void beforeDecodingFields(Node node)
node has been created
as part of decoding a graph but its fields have yet to be initialized.public void afterDecodingFields(Node node)
node has been created
as part of decoding a graph and its fields have now been initialized.public Graph.NodeEventScope trackNodeEvents(Graph.NodeEventListener listener)
Graph.NodeEventListener with this graph. This should be used in
conjunction with try-with-resources statement as follows:
try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
// make changes to the graph
}
public <T extends Node & Node.ValueNumberable> T unique(T node)
node and returns it if found. Otherwise
node is added to this graph and returned.node if one exists, otherwise nodepublic <T extends Node> T findDuplicate(T node)
null if no such
duplicate exists.public boolean isNew(Graph.Mark mark, Node node)
public Graph.Mark getMark()
Graph.getNewNodes(org.graalvm.compiler.graph.Graph.Mark).public NodeIterable<Node> getNewNodes(Graph.Mark mark)
public NodeIterable<Node> getNodes()
Iterable providing all the live nodes.Iterable providing all the live nodes.public final boolean maybeCompress()
public final void minimizeSize()
protected boolean compress(boolean minimizeSize)
public <T extends Node & IterableNodeType> NodeIterable<T> getNodes(NodeClass<T> nodeClass)
Iterable providing all the live nodes whose type is compatible with
type.nodeClass - the type of node to returnIterable providing all the matching nodespublic <T extends Node & IterableNodeType> boolean hasNode(NodeClass<T> type)
type - the type of node that is checked for occurrencepublic NodeBitMap createNodeBitMap()
public <T> NodeMap<T> createNodeMap()
public NodeFlood createNodeFlood()
public NodeWorkList createNodeWorkList()
public NodeWorkList createIterativeNodeWorkList(boolean fill, int iterationLimitPerNode)
protected void afterRegister(Node node)
public boolean verify()
public boolean verifySourcePositions(boolean performConsistencyCheck)
public Node getNode(int id)
public int nodeIdCount()
public org.graalvm.collections.EconomicMap<Node,Node> addDuplicates(Iterable<? extends Node> newNodes, Graph oldGraph, int estimatedNodeCount, org.graalvm.collections.EconomicMap<Node,Node> replacementsMap)
newNodes to this graph. This will recreate any edges
between the duplicate nodes. The 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.newNodes - the nodes to be duplicatedreplacementsMap - the replacement map (can be null if no replacement is to be performed)nodes to their duplicatespublic org.graalvm.collections.EconomicMap<Node,Node> addDuplicates(Iterable<? extends Node> newNodes, Graph oldGraph, int estimatedNodeCount, Graph.DuplicationReplacement replacements)
public boolean isFrozen()
public void freeze()
public void temporaryFreeze()
public void unfreeze()