Top Description Inners Fields Constructors Methods
javassist.bytecode.analysis

public Class ControlFlow

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List, javassist.CtClass, .CtMethod, javassist.bytecode.BadBytecode, .MethodInfo, javassist.bytecode.stackmap.BasicBlock

Represents the control flow graph of a given method.

To obtain the control flow graph, do the following:

CtMethod m = ...
ControlFlow cf = new ControlFlow(m);
Block[] blocks = cf.basicBlocks();

blocks is an array of basic blocks in that method body.

Author
Shigeru Chiba
Since
3.16
See Also
javassist.CtMethod, Block, Frame, Analyzer

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
public static class
ControlFlow.Block

Basic block.

public static class
ControlFlow.Catcher

Represents a catch clause.

public static class
ControlFlow.Node

A node of (post) dominator trees.

Field Summary

Modifier and TypeField and Description
private ControlFlow.Block[]
private CtClass
private Frame[]
private MethodInfo

Constructor Summary

AccessConstructor and Description
public
ControlFlow(CtMethod method)

Constructs a control-flow analyzer for the given method.

public
ControlFlow(CtClass ctclazz, MethodInfo minfo)

Constructs a control-flow analyzer.

Method Summary

Modifier and TypeMethod and Description
public ControlFlow.Block[]

Returns:

an array of basic blocks, the array has length 0 if the method doesn't have code.
basicBlocks
()

Returns all the basic blocks in the method body.

public ControlFlow.Node[]

Returns:

an array of the tree nodes, or null if the method doesn't have code.
dominatorTree
()

Constructs a dominator tree.

public Frame
frameAt(int
the position.
pos
)

Returns the types of the local variables and stack frame entries available at the given position.

public ControlFlow.Node[]

Returns:

an array of the tree nodes, or null if the method doesn't have code.
postDominatorTree
()

Constructs a post dominator tree.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

basicBlocksback to summary
private ControlFlow.Block[] basicBlocks
clazzback to summary
private CtClass clazz
framesback to summary
private Frame[] frames
methodInfoback to summary
private MethodInfo methodInfo

Constructor Detail

ControlFlowback to summary
public ControlFlow(CtMethod method) throws BadBytecode

Constructs a control-flow analyzer for the given method.

ControlFlowback to summary
public ControlFlow(CtClass ctclazz, MethodInfo minfo) throws BadBytecode

Constructs a control-flow analyzer.

Method Detail

basicBlocksback to summary
public ControlFlow.Block[] basicBlocks()

Returns all the basic blocks in the method body.

Returns:ControlFlow.Block[]

an array of basic blocks, the array has length 0 if the method doesn't have code.

dominatorTreeback to summary
public ControlFlow.Node[] dominatorTree()

Constructs a dominator tree. This method returns an array of the tree nodes. The first element of the array is the root of the tree.

The order of the elements is the same as that of the elements in the Block array returned by the basicBlocks method. If a Block object is at the i-th position in the Block array, then the Node object referring to that Block object is at the i-th position in the array returned by this method. For every array element node, its index in the array is equivalent to node.block().index().

Returns:ControlFlow.Node[]

an array of the tree nodes, or null if the method doesn't have code.

See Also
Node#block(), Block#index()
frameAtback to summary
public Frame frameAt(int pos) throws BadBytecode

Returns the types of the local variables and stack frame entries available at the given position. If the byte at the position is not the first byte of an instruction, then this method returns null.

Parameters
pos:int

the position.

postDominatorTreeback to summary
public ControlFlow.Node[] postDominatorTree()

Constructs a post dominator tree. This method returns an array of the tree nodes. Note that the tree has multiple roots. The parent of the root nodes is null.

The order of the elements is the same as that of the elements in the Block array returned by the basicBlocks method. If a Block object is at the i-th position in the Block array, then the Node object referring to that Block object is at the i-th position in the array returned by this method. For every array element node, its index in the array is equivalent to node.block().index().

Returns:ControlFlow.Node[]

an array of the tree nodes, or null if the method doesn't have code.

See Also
Node#block(), Block#index()
javassist.bytecode.analysis back to summary

pack-priv abstract Class ControlFlow.Access

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv ControlFlow.Node[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract BasicBlock[]
pack-priv abstract BasicBlock[]
pack-priv ControlFlow.Node
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allback to summary
pack-priv ControlFlow.Node[] all

Constructor Detail

Accessback to summary
pack-priv Access(ControlFlow.Node[] nodes)

Method Detail

entrancesback to summary
pack-priv abstract BasicBlock[] entrances(ControlFlow.Node n)
exitsback to summary
pack-priv abstract BasicBlock[] exits(ControlFlow.Node n)
nodeback to summary
pack-priv ControlFlow.Node node(BasicBlock b)
javassist.bytecode.analysis back to summary

public Class ControlFlow.Block

extends BasicBlock
Class Inheritance

Basic block. It is a sequence of contiguous instructions that do not contain jump/branch instructions except the last one. Since Java6 or later does not allow JSR, we deal with JSR as a non-branch instruction.

Field Summary

Modifier and TypeField and Description
public Object
clientData

A field that can be freely used for storing extra data.

pack-priv ControlFlow.Block[]
pack-priv int
pack-priv MethodInfo
Inherited from javassist.bytecode.stackmap.BasicBlock:
exitincominglengthpositionstoptoCatch

Constructor Summary

AccessConstructor and Description
pack-priv
Block(int pos, MethodInfo minfo)

Method Summary

Modifier and TypeMethod and Description
public ControlFlow.Catcher[]
catchers()

Returns catch clauses that will catch an exception thrown in this block.

public ControlFlow.Block
exit(int
an index in the array of exit blocks.
n
)

Returns the n-th block that may be executed after this block.

public int
exits()

Return the number of the blocks that may be executed after this block.

pack-priv BasicBlock[]
public ControlFlow.Block
incoming(int n)

Returns the block that the control may jump into this block from.

public int
incomings()

Returns the number of the control paths entering this block.

public int
index()

Returns the position of this block in the array of basic blocks that the basicBlocks method returns.

public int
length()

Returns the length of this block.

public int
position()

Returns the position of the first instruction in this block.

protected void
Inherited from javassist.bytecode.stackmap.BasicBlock:
findtoString

Field Detail

clientDataback to summary
public Object clientData

A field that can be freely used for storing extra data. A client program of this control-flow analyzer can append an additional attribute to a Block object. The Javassist library never accesses this field.

entrancesback to summary
pack-priv ControlFlow.Block[] entrances
indexback to summary
pack-priv int index
methodback to summary
pack-priv MethodInfo method

Constructor Detail

Blockback to summary
pack-priv Block(int pos, MethodInfo minfo)

Method Detail

catchersback to summary
public ControlFlow.Catcher[] catchers()

Returns catch clauses that will catch an exception thrown in this block.

exitback to summary
public ControlFlow.Block exit(int n)

Returns the n-th block that may be executed after this block.

Parameters
n:int

an index in the array of exit blocks.

exitsback to summary
public int exits()

Return the number of the blocks that may be executed after this block.

getExitback to summary
pack-priv BasicBlock[] getExit()
incomingback to summary
public ControlFlow.Block incoming(int n)

Returns the block that the control may jump into this block from.

incomingsback to summary
public int incomings()

Returns the number of the control paths entering this block.

indexback to summary
public int index()

Returns the position of this block in the array of basic blocks that the basicBlocks method returns.

See Also
basicBlocks()
lengthback to summary
public int length()

Returns the length of this block.

positionback to summary
public int position()

Returns the position of the first instruction in this block.

toString2back to summary
protected void toString2(StringBuilder sbuf)

Overrides javassist.bytecode.stackmap.BasicBlock.toString2.

Annotations
@Override
javassist.bytecode.analysis back to summary

public Class ControlFlow.Catcher

extends Object
Class Inheritance

Represents a catch clause.

Field Summary

Modifier and TypeField and Description
private ControlFlow.Block
private int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public ControlFlow.Block
block()

Returns the first block of the catch clause.

public String
type()

Returns the name of the exception type that this catch clause catches.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nodeback to summary
private ControlFlow.Block node
typeIndexback to summary
private int typeIndex

Constructor Detail

Catcherback to summary
pack-priv Catcher(BasicBlock.Catch c)

Method Detail

blockback to summary
public ControlFlow.Block block()

Returns the first block of the catch clause.

typeback to summary
public String type()

Returns the name of the exception type that this catch clause catches.

javassist.bytecode.analysis back to summary

public Class ControlFlow.Node

extends Object
Class Inheritance

A node of (post) dominator trees.

Field Summary

Modifier and TypeField and Description
private ControlFlow.Block
private ControlFlow.Node[]
private ControlFlow.Node

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public ControlFlow.Block
block()

Returns the basic block indicated by this node.

public ControlFlow.Node
child(int
an index in the array of children.
n
)

Returns the n-th child of this node.

public int
children()

Returns the number of the children of this node.

private static ControlFlow.Node
getAncestor(ControlFlow.Node n1, ControlFlow.Node n2, int[] distance)

pack-priv int
makeDepth1stTree(ControlFlow.Node caller, boolean[] visited, int counter, int[] distance, ControlFlow.Access access)

pack-priv boolean
makeDominatorTree(boolean[] visited, int[] distance, ControlFlow.Access access)

public ControlFlow.Node
parent()

Returns the parent of this node.

private static void
public String
toString()

Overrides java.lang.Object.toString.

Returns a String representation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

blockback to summary
private ControlFlow.Block block
childrenback to summary
private ControlFlow.Node[] children
parentback to summary
private ControlFlow.Node parent

Constructor Detail

Nodeback to summary
pack-priv Node(ControlFlow.Block b)

Method Detail

blockback to summary
public ControlFlow.Block block()

Returns the basic block indicated by this node.

childback to summary
public ControlFlow.Node child(int n)

Returns the n-th child of this node.

Parameters
n:int

an index in the array of children.

childrenback to summary
public int children()

Returns the number of the children of this node.

getAncestorback to summary
private static ControlFlow.Node getAncestor(ControlFlow.Node n1, ControlFlow.Node n2, int[] distance)
makeDepth1stTreeback to summary
pack-priv int makeDepth1stTree(ControlFlow.Node caller, boolean[] visited, int counter, int[] distance, ControlFlow.Access access)
makeDominatorTreeback to summary
pack-priv boolean makeDominatorTree(boolean[] visited, int[] distance, ControlFlow.Access access)
parentback to summary
public ControlFlow.Node parent()

Returns the parent of this node.

setChildrenback to summary
private static void setChildren(ControlFlow.Node[] all)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a String representation.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override