public class BinaryGraphPrinter extends Object implements GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>, GraphBlocks<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Block,Node>, GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>, GraphLocations<ResolvedJavaMethod,NodeSourcePosition,SourceLanguagePosition>, GraphTypes
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_CONSTANT_TO_STRING_LENGTH |
static List<Class<?>> |
TRUSTED_CLASSES
Classes whose
#toString() method does not run any untrusted code. |
| Constructor and Description |
|---|
BinaryGraphPrinter(DebugContext ctx,
SnippetReflectionProvider snippetReflection) |
| Modifier and Type | Method and Description |
|---|---|
void |
beginGroup(DebugContext debug,
String name,
String shortName,
ResolvedJavaMethod method,
int bci,
Map<Object,Object> properties)
Starts a new group of graphs with the given name, short name and method byte code index (BCI)
as properties.
|
int |
blockId(Block sux)
Unique id of a block.
|
List<Node> |
blockNodes(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info,
Block block) |
List<Block> |
blocks(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo graph)
All blocks in the graph.
|
List<Block> |
blockSuccessors(Block block) |
NodeClass<?> |
classForNode(Node node)
Finds a node class for
node. |
void |
close() |
static String |
constantArrayToString(Object array,
Set<Object> visited) |
static String |
constantToString(Object value,
Set<Object> visited) |
boolean |
edgeDirect(Edges port,
int index)
Checks whether an edge is direct.
|
String |
edgeName(Edges port,
int index)
The name of an edge.
|
Collection<? extends Node> |
edgeNodes(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo graph,
Node node,
Edges port,
int i)
Nodes where the edges for a port lead to/from.
|
Object |
edgeType(Edges port,
int index)
Type of an edge.
|
void |
endGroup()
Ends the current group.
|
Object |
enumClass(Object enumValue)
Recognizes an
enumobject. |
int |
enumOrdinal(Object obj)
Ordinal of an enum.
|
String[] |
enumTypeValues(Object clazz)
All possible values of an enum.
|
ResolvedJavaField |
field(Object object)
Recognizes a field.
|
Object |
fieldDeclaringClass(ResolvedJavaField field)
Field's declaring class.
|
int |
fieldModifiers(ResolvedJavaField field)
Field modifiers.
|
String |
fieldName(ResolvedJavaField field)
Name of a field.
|
String |
fieldTypeName(ResolvedJavaField field)
Type name of the field.
|
default String |
format(JavaConstant constant)
Use the real
Object.toString() method for JavaConstants that are
wrapping trusted types, otherwise just return the result of JavaConstant#toString(). |
static StructuredGraph.ScheduleResult |
getScheduleOrNull(Graph graph) |
SnippetReflectionProvider |
getSnippetReflectionProvider() |
org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo |
graph(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo currrent,
Object obj)
Casts
obj to graph, if possible. |
static boolean |
isToStringTrusted(Class<?> c)
Determines if invoking
Object.toString() on an instance of c will only run
trusted code. |
String |
locationLanguage(SourceLanguagePosition location)
Identification of the language.
|
int |
locationLineNumber(SourceLanguagePosition location)
Line number of a location.
|
int |
locationOffsetEnd(SourceLanguagePosition location)
Offset of the location.
|
int |
locationOffsetStart(SourceLanguagePosition location)
Offset of the location.
|
URI |
locationURI(SourceLanguagePosition location)
The universal resource identification that contains the location.If the location can be found
in an assummably accessible resource, then use such resource identification.
|
ResolvedJavaMethod |
method(Object object)
Recognize method.
|
byte[] |
methodCode(ResolvedJavaMethod method)
Bytecode for a method.
|
Object |
methodDeclaringClass(ResolvedJavaMethod method)
Method's declaring class.
|
Iterable<SourceLanguagePosition> |
methodLocation(ResolvedJavaMethod method,
int bci,
NodeSourcePosition pos)
Stack trace element for a method, index and position.
|
int |
methodModifiers(ResolvedJavaMethod method)
Method modifiers.
|
String |
methodName(ResolvedJavaMethod method)
Method name.
|
Signature |
methodSignature(ResolvedJavaMethod method)
Method's signature.
|
StackTraceElement |
methodStackTraceElement(ResolvedJavaMethod method,
int bci,
NodeSourcePosition pos)
Stack trace element for a method, index and position.
|
String |
nameTemplate(NodeClass<?> nodeClass)
The template used to build the name of nodes of this class.
|
Node |
node(Object obj)
Finds a node for
obj, if possible. |
NodeClass<?> |
nodeClass(Object obj)
Finds a node class for
obj, if possible. |
Object |
nodeClassType(NodeClass<?> node)
Java class for a node class.
|
boolean |
nodeHasPredecessor(Node node)
Checks if there is a predecessor for a node.
|
int |
nodeId(Node n)
Id of
node. |
void |
nodeProperties(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info,
Node node,
Map<String,? super Object> props)
Collects node properties.
|
Iterable<Node> |
nodes(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info)
Nodes of a graph.
|
int |
nodesCount(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info)
Number of nodes in a graph.
|
NodeSourcePosition |
nodeSourcePosition(Object object)
Recognize a source position.
|
int |
nodeSourcePositionBCI(NodeSourcePosition pos)
Byte code index of a position.
|
NodeSourcePosition |
nodeSourcePositionCaller(NodeSourcePosition pos)
Caller of a position.
|
ResolvedJavaMethod |
nodeSourcePositionMethod(NodeSourcePosition pos)
Method for a position.
|
Edges |
portInputs(NodeClass<?> nodeClass)
Input ports of a node class.
|
Edges |
portOutputs(NodeClass<?> nodeClass)
Output ports of a node class.
|
int |
portSize(Edges port)
The number of edges in a port.
|
void |
print(DebugContext debug,
Graph graph,
Map<Object,Object> properties,
int id,
String format,
Object... args)
Prints an entire
Graph with the specified title, optionally using short names for
nodes. |
Signature |
signature(Object object)
Recognizes signature.
|
int |
signatureParameterCount(Signature signature)
Number of parameters of a signature.
|
String |
signatureParameterTypeName(Signature signature,
int index)
Type name of a signature parameter.
|
String |
signatureReturnTypeName(Signature signature)
Type name of a return type.
|
default Object[] |
simplifyClassArgs(Object... args)
Replaces all
JavaType elements in args with the result of
JavaType.getUnqualifiedName(). |
static String |
truncate(String s) |
String |
typeName(Object obj)
Finds Java type name for a given class.
|
default void |
updateStringPropertiesForConstant(Map<Object,Object> props,
ConstantNode cn)
Sets or updates the
"rawvalue" and "toString" properties in props for
cn if it's a boxed Object value and snippetReflection can access the raw
value. |
public static final List<Class<?>> TRUSTED_CLASSES
#toString() method does not run any untrusted code.public static final int MAX_CONSTANT_TO_STRING_LENGTH
public BinaryGraphPrinter(DebugContext ctx, SnippetReflectionProvider snippetReflection) throws IOException
IOExceptionpublic SnippetReflectionProvider getSnippetReflectionProvider()
public void beginGroup(DebugContext debug, String name, String shortName, ResolvedJavaMethod method, int bci, Map<Object,Object> properties) throws IOException
IOExceptionpublic void endGroup()
throws IOException
IOExceptionpublic void close()
public ResolvedJavaMethod method(Object object)
GraphElementsmethod in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>object - the object to checknull if the object isn't a method, non-null value otherwisepublic Node node(Object obj)
GraphStructureobj, if possible. If the given object obj can be seen
as an instance of node return the properly typed instance of the node class. Otherwise return
null.node in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>obj - an object to find node fornull if the object doesn't represent a nodepublic NodeClass<?> nodeClass(Object obj)
GraphStructureobj, if possible. If the given object obj can be
seen as an instance of node class return the properly typed instance of the node class.
Otherwise return null.nodeClass in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>obj - an object to find node class fornull if the object doesn't represent a node
classpublic NodeClass<?> classForNode(Node node)
GraphStructurenode.classForNode in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>node - an instance of node in this graphnullpublic Object nodeClassType(NodeClass<?> node)
GraphStructurenodeClassType in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>node - the node classClass or other type representation of the node classpublic String nameTemplate(NodeClass<?> nodeClass)
GraphStructurenameTemplate in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>nodeClass - the node class to find name template forpublic final org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo graph(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo currrent,
Object obj)
GraphStructureobj to graph, if possible. If the given object obj can be seen as
a graph or sub-graph of a graph, then return the properly typed instance. Otherwise return
nullgraph in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>currrent - the currently processed graphobj - an object to check and view as a graphnull if the object doesn't represent a graphpublic int nodeId(Node n)
GraphStructurenode. Each node in the graph is uniquely identified by an integer value. If two
nodes have the same id, then they shall be == to each other.nodeId in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>n - the node to query for an idpublic Edges portInputs(NodeClass<?> nodeClass)
GraphStructureportInputs in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>nodeClass - the node classpublic Edges portOutputs(NodeClass<?> nodeClass)
GraphStructureportOutputs in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>nodeClass - the node classpublic List<Node> blockNodes(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info, Block block)
blockNodes in interface GraphBlocks<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Block,Node>public int blockId(Block sux)
GraphBlocksblockId in interface GraphBlocks<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Block,Node>sux - the blockpublic List<Block> blockSuccessors(Block block)
blockSuccessors in interface GraphBlocks<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Block,Node>public Iterable<Node> nodes(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info)
GraphStructureGraphStructure.nodesCount(java.lang.Object) method.nodes in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>info - the graph to query for nodesGraphStructure.nodesCount(java.lang.Object)public int nodesCount(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info)
GraphStructureGraphStructure.nodes(java.lang.Object) method.nodesCount in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>info - the graph to queryGraphStructure.nodes(java.lang.Object)public void nodeProperties(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo info,
Node node,
Map<String,? super Object> props)
GraphStructurenodeProperties in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>info - the current graphnode - the node to collect properties forprops - the map to put the properties topublic boolean nodeHasPredecessor(Node node)
GraphStructurenodeHasPredecessor in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>node - the node to checktrue if it has a predecessor, false otherwisepublic List<Block> blocks(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo graph)
GraphBlocksblocks in interface GraphBlocks<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Block,Node>graph - the graphpublic void print(DebugContext debug, Graph graph, Map<Object,Object> properties, int id, String format, Object... args) throws IOException
Graph with the specified title, optionally using short names for
nodes.IOExceptionpublic int portSize(Edges port)
GraphStructureGraphStructure.edgeDirect(java.lang.Object, int), GraphStructure.edgeName(java.lang.Object, int),
GraphStructure.edgeType(java.lang.Object, int) and
GraphStructure.edgeNodes(java.lang.Object, java.lang.Object, java.lang.Object, int) for indexes
from 0 to portSize - 1portSize in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>port - the portpublic boolean edgeDirect(Edges port, int index)
GraphStructureedgeDirect in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>port - the portindex - index from 0 to GraphStructure.portSize(java.lang.Object) minus
1true if only one node can be returned from
GraphStructure.edgeNodes(java.lang.Object, java.lang.Object, java.lang.Object, int) methodpublic String edgeName(Edges port, int index)
GraphStructureedgeName in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>port - the portindex - index from 0 to GraphStructure.portSize(java.lang.Object) minus
1public Object edgeType(Edges port, int index)
GraphStructureenum- e.g. either real instance of
Enum subclass, or something that the
GraphOutput.Builder can recognize as
enum.
edgeType in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>index - index from 0 to GraphStructure.portSize(java.lang.Object) minus
1Enum representing type of the edgepublic Collection<? extends Node> edgeNodes(org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo graph, Node node, Edges port, int i)
GraphStructuredirect/non-direct edges. In case of a direct edge
the returned collection must have exactly one element.edgeNodes in interface GraphStructure<org.graalvm.compiler.printer.BinaryGraphPrinter.GraphInfo,Node,NodeClass<?>,Edges>graph - the graphnode - the node in the graphport - port of the node classi - index from 0 to GraphStructure.portSize(java.lang.Object) minus
1null if there are no edges associated with given port or collection of
nodes where to/from the edges lead topublic Object enumClass(Object enumValue)
GraphTypesenumobject. If the
enumValue object represents an enum, then an object
that represents its class shall be returned.enumClass in interface GraphTypesenumValue - the value to testnull if the value isn't enum, otherwise its classpublic int enumOrdinal(Object obj)
GraphTypesobj represents an enum, then return its ordinal
number otherwise return -1enumOrdinal in interface GraphTypesobj - the value to test-1 if the obj isn't enum, otherwise its ordinal numberpublic String[] enumTypeValues(Object clazz)
GraphTypesmaybeEnumClass object represents
an enum, then compute enum value names in ordinal order and return them as a string array.
Otherwise return nullenumTypeValues in interface GraphTypesclazz - the class to testnull if the clazz isn't an enum, otherwise names of its valuespublic String typeName(Object obj)
GraphTypestypeName in interface GraphTypesobj - object representing the classnull if the parameter doesn't represent a
classpublic byte[] methodCode(ResolvedJavaMethod method)
GraphElementsmethodCode in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>method - the methodpublic int methodModifiers(ResolvedJavaMethod method)
GraphElementsmethodModifiers in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>method - the methodpublic Signature methodSignature(ResolvedJavaMethod method)
GraphElementsmethodSignature in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>method - the methodpublic String methodName(ResolvedJavaMethod method)
GraphElementsmethodName in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>method - the methodpublic Object methodDeclaringClass(ResolvedJavaMethod method)
GraphElementsClass or be recognizable by
GraphTypes.typeName(java.lang.Object) method.methodDeclaringClass in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>method - the methodpublic int fieldModifiers(ResolvedJavaField field)
GraphElementsfieldModifiers in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>field - the fieldpublic String fieldTypeName(ResolvedJavaField field)
GraphElementsfieldTypeName in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>field - the fieldpublic String fieldName(ResolvedJavaField field)
GraphElementsfieldName in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>field - the fieldpublic Object fieldDeclaringClass(ResolvedJavaField field)
GraphElementsClass or be recognizable by
GraphTypes.typeName(java.lang.Object) method.fieldDeclaringClass in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>field - the fieldpublic ResolvedJavaField field(Object object)
GraphElementsfield in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>object - the object to checknull if the object isn't a field, non-null value otherwisepublic Signature signature(Object object)
GraphElementssignature in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>object - the object to checknull if the object isn't a signature, non-null value otherwisepublic int signatureParameterCount(Signature signature)
GraphElementssignatureParameterCount in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>signature - the signaturepublic String signatureParameterTypeName(Signature signature, int index)
GraphElementssignatureParameterTypeName in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>signature - the signatureindex - index from 0 to GraphElements.signatureParameterCount(java.lang.Object) - 1public String signatureReturnTypeName(Signature signature)
GraphElementssignatureReturnTypeName in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>signature - the signaturepublic NodeSourcePosition nodeSourcePosition(Object object)
GraphElementsnodeSourcePosition in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>object - the object to checknull if the object isn't a position, non-null otherwisepublic ResolvedJavaMethod nodeSourcePositionMethod(NodeSourcePosition pos)
GraphElementsnodeSourcePositionMethod in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>pos - the positionpublic NodeSourcePosition nodeSourcePositionCaller(NodeSourcePosition pos)
GraphElementsnodeSourcePositionCaller in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>pos - the positionnull or another positionpublic int nodeSourcePositionBCI(NodeSourcePosition pos)
GraphElementsnodeSourcePositionBCI in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>pos - the positionpublic StackTraceElement methodStackTraceElement(ResolvedJavaMethod method, int bci, NodeSourcePosition pos)
GraphElementsStackTraceElement and is suitable for Java-like languages. Should you
need to provide more details about the location of multiple strata, see
GraphLocations interface that gives more control over the provided location data.methodStackTraceElement in interface GraphElements<ResolvedJavaMethod,ResolvedJavaField,Signature,NodeSourcePosition>method - the methodbci - the indexpos - the positionpublic Iterable<SourceLanguagePosition> methodLocation(ResolvedJavaMethod method, int bci, NodeSourcePosition pos)
GraphLocationslanguage.methodLocation in interface GraphLocations<ResolvedJavaMethod,NodeSourcePosition,SourceLanguagePosition>method - the methodbci - the indexpos - the positionpublic String locationLanguage(SourceLanguagePosition location)
GraphLocationslocationLanguage in interface GraphLocations<ResolvedJavaMethod,NodeSourcePosition,SourceLanguagePosition>location - the locationpublic URI locationURI(SourceLanguagePosition location)
GraphLocationsfile,
http, or https are assumed to be accessible.
If the location is inside of a virtual source, or source which is unlikely to be accessible outside of running program, then it may be better to encode the whole source into the resource identifier. This can be done by using data URIs like:
data:text/javascript,alert('Vivat graphs!')
locationURI in interface GraphLocations<ResolvedJavaMethod,NodeSourcePosition,SourceLanguagePosition>location - the locationnull if it is not knownpublic int locationLineNumber(SourceLanguagePosition location)
GraphLocationsGraphLocations.locationOffsetStart(java.lang.Object) and
GraphLocations.locationOffsetEnd(java.lang.Object) methods.locationLineNumber in interface GraphLocations<ResolvedJavaMethod,NodeSourcePosition,SourceLanguagePosition>location - the locationpublic int locationOffsetStart(SourceLanguagePosition location)
GraphLocationsline number of a location in source. In such
case return the start offset from this method and end offset via
GraphLocations.locationOffsetEnd(java.lang.Object) method. Offsets are counted from 0.locationOffsetStart in interface GraphLocations<ResolvedJavaMethod,NodeSourcePosition,SourceLanguagePosition>location - the locationpublic int locationOffsetEnd(SourceLanguagePosition location)
GraphLocationsline number of a location in source. In such
case return the start offset via GraphLocations.locationOffsetStart(java.lang.Object) method and
end from this method. Offsets are counted from 0.locationOffsetEnd in interface GraphLocations<ResolvedJavaMethod,NodeSourcePosition,SourceLanguagePosition>location - the locationpublic static boolean isToStringTrusted(Class<?> c)
Object.toString() on an instance of c will only run
trusted code.public String format(JavaConstant constant)
Object.toString() method for JavaConstants that are
wrapping trusted types, otherwise just return the result of JavaConstant#toString().format in interface JavaConstantFormatterpublic void updateStringPropertiesForConstant(Map<Object,Object> props, ConstantNode cn)
"rawvalue" and "toString" properties in props for
cn if it's a boxed Object value and snippetReflection can access the raw
value.public Object[] simplifyClassArgs(Object... args)
JavaType elements in args with the result of
JavaType.getUnqualifiedName().args with the above mentioned substitutions or args if no
substitutions were performedpublic static StructuredGraph.ScheduleResult getScheduleOrNull(Graph graph)