Package kilim.analysis
Class MethodFlow
- java.lang.Object
-
- org.objectweb.asm.MethodVisitor
-
- org.objectweb.asm.tree.MethodNode
-
- kilim.analysis.MethodFlow
-
public class MethodFlow extends org.objectweb.asm.tree.MethodNodeThis represents all the basic blocks of a method.
-
-
Field Summary
Fields Modifier and Type Field Description private BBListbasicBlocksThe list of basic blocks, in the order in which they occur in the class file.(package private) ClassFlowclassFlowThe classFlow to which this methodFlow belongsstatic booleandebugPrintLivenessprint the bit by bit liveness data after calculation(package private) Detectordetectorprivate java.util.HashMap<java.lang.Integer,org.objectweb.asm.tree.FrameNode>frameNodesprivate int[]handlerMapprivate booleanhasPausableAnnotationprivate booleanhasPausableInvokeDynamicprivate java.util.HashMap<org.objectweb.asm.tree.LabelNode,BasicBlock>labelToBBMapMaps labels to BasicBlocksprivate java.util.HashMap<org.objectweb.asm.tree.LabelNode,java.lang.Integer>labelToPosMapReverse map of posToLabelMap.private java.util.TreeMap<java.lang.Integer,org.objectweb.asm.tree.LineNumberNode>lineNumberNodes(package private) java.util.ArrayList<Handler>origHandlerscopy of handlers provided by asm - null after being assigned to the BBsprivate java.util.List<org.objectweb.asm.tree.MethodInsnNode>pausableMethodsprivate java.util.ArrayList<org.objectweb.asm.tree.LabelNode>posToLabelMapMaps instructions[i] to LabelNode or null (if no label).private booleansuppressPausableCheckprivate java.util.PriorityQueue<BasicBlock>workset-
Fields inherited from class org.objectweb.asm.tree.MethodNode
access, annotationDefault, attrs, desc, exceptions, instructions, invisibleAnnotableParameterCount, invisibleAnnotations, invisibleLocalVariableAnnotations, invisibleParameterAnnotations, invisibleTypeAnnotations, localVariables, maxLocals, maxStack, name, parameters, signature, tryCatchBlocks, visibleAnnotableParameterCount, visibleAnnotations, visibleLocalVariableAnnotations, visibleParameterAnnotations, visibleTypeAnnotations
-
-
Constructor Summary
Constructors Constructor Description MethodFlow(ClassFlow classFlow, int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions, Detector detector)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidacceptAnnotation(org.objectweb.asm.AnnotationVisitor av, java.lang.String name, java.lang.Object value)(package private) voidaddInlinedBlock(BasicBlock bb)voidanalyze()private voidassignCatchHandlers()(package private) voidbuildBasicBlocks()private voidbuildHandlerMap(java.util.ArrayList<Handler> sorted)private booleancalcBornOnce()private voidcalcBornUsage()private booleancheckNoBasicBlockLeftBehind()private voidcheckStatus(java.lang.String superClassName, java.lang.String methodName, java.lang.String desc)private voidconsolidateBasicBlocks()In the first pass (buildBasicBlocks()), we create BBs whenever we encounter a label.private voiddataFlow()private BasicBlockdequeue()private voiddoLiveVarAnalysis()In live var analysis a BB asks its successor (in essence) about which vars are live, mixes it with its own uses and defs and passes on a new list of live vars to its predecessors.(package private) voidenqueue(BasicBlock bb)(package private) BasicBlockgetBasicBlock(org.objectweb.asm.tree.LabelNode l)BBListgetBasicBlocks()org.objectweb.asm.tree.LabelNodegetLabelAt(int pos)(package private) intgetLabelPosition(org.objectweb.asm.tree.LabelNode l)intgetNumArgs()(package private) BasicBlockgetOrCreateBasicBlock(org.objectweb.asm.tree.LabelNode l)(package private) org.objectweb.asm.tree.LabelNodegetOrCreateLabelAtPos(int pos)private voidinlineSubroutines()booleanisAbstract()booleanisBridge()booleanisPausable()(package private) booleanisPausableMethodInsn(org.objectweb.asm.tree.MethodInsnNode min)booleanisStatic()(package private) intmapHandler(int start)return the next handler.from >= start, else -1 - valid only until catch handlers are assignedprivate voidmarkPausableJSRs()(package private) booleanneedsWeaving()private voidpreAssignCatchHandlers()(package private) voidprintUsage(java.util.ArrayList<BasicBlock> bbs)voidresetLabels()voidrestoreNonInstructionNodes()private voidsetArgsBorn(BasicBlock bb)(package private) voidsetLabel(int pos, org.objectweb.asm.tree.LabelNode l)voidsetPausable(boolean isPausable)java.lang.StringtoString()private java.lang.StringtoString(java.lang.String className, java.lang.String methName, java.lang.String desc)voidverifyPausables()voidvisitFrame(int type, int nLocal, java.lang.Object[] local, int nStack, java.lang.Object[] stack)voidvisitInvokeDynamicInsn(java.lang.String name, java.lang.String desc, org.objectweb.asm.Handle bsm, java.lang.Object... bsmArgs)voidvisitLabel(org.objectweb.asm.Label label)voidvisitLineNumber(int line, org.objectweb.asm.Label start)(package private) voidvisitLineNumbers(org.objectweb.asm.MethodVisitor mv)voidvisitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc, boolean itf)-
Methods inherited from class org.objectweb.asm.tree.MethodNode
accept, accept, check, getLabelNode, visitAnnotableParameterCount, visitAnnotation, visitAnnotationDefault, visitAttribute, visitCode, visitEnd, visitFieldInsn, visitIincInsn, visitInsn, visitInsnAnnotation, visitIntInsn, visitJumpInsn, visitLdcInsn, visitLocalVariable, visitLocalVariableAnnotation, visitLookupSwitchInsn, visitMaxs, visitMultiANewArrayInsn, visitParameter, visitParameterAnnotation, visitTableSwitchInsn, visitTryCatchAnnotation, visitTryCatchBlock, visitTypeAnnotation, visitTypeInsn, visitVarInsn
-
-
-
-
Field Detail
-
classFlow
ClassFlow classFlow
The classFlow to which this methodFlow belongs
-
posToLabelMap
private java.util.ArrayList<org.objectweb.asm.tree.LabelNode> posToLabelMap
Maps instructions[i] to LabelNode or null (if no label). Note that LabelInsnNodes are not accounted for here because they themselves are not labelled.
-
labelToPosMap
private java.util.HashMap<org.objectweb.asm.tree.LabelNode,java.lang.Integer> labelToPosMap
Reverse map of posToLabelMap. Maps Labels to index within method.instructions.
-
labelToBBMap
private java.util.HashMap<org.objectweb.asm.tree.LabelNode,BasicBlock> labelToBBMap
Maps labels to BasicBlocks
-
basicBlocks
private BBList basicBlocks
The list of basic blocks, in the order in which they occur in the class file. Maintaining this order is important, because we'll use it to drive duplication (in case of JSRs) and also while writing out the class file.
-
workset
private java.util.PriorityQueue<BasicBlock> workset
-
hasPausableAnnotation
private boolean hasPausableAnnotation
-
suppressPausableCheck
private boolean suppressPausableCheck
-
pausableMethods
private java.util.List<org.objectweb.asm.tree.MethodInsnNode> pausableMethods
-
detector
final Detector detector
-
lineNumberNodes
private java.util.TreeMap<java.lang.Integer,org.objectweb.asm.tree.LineNumberNode> lineNumberNodes
-
frameNodes
private java.util.HashMap<java.lang.Integer,org.objectweb.asm.tree.FrameNode> frameNodes
-
hasPausableInvokeDynamic
private boolean hasPausableInvokeDynamic
-
origHandlers
java.util.ArrayList<Handler> origHandlers
copy of handlers provided by asm - null after being assigned to the BBs
-
handlerMap
private int[] handlerMap
-
debugPrintLiveness
public static boolean debugPrintLiveness
print the bit by bit liveness data after calculation
-
-
Method Detail
-
restoreNonInstructionNodes
public void restoreNonInstructionNodes()
-
analyze
public void analyze() throws KilimException- Throws:
KilimException
-
verifyPausables
public void verifyPausables() throws KilimException- Throws:
KilimException
-
checkStatus
private void checkStatus(java.lang.String superClassName, java.lang.String methodName, java.lang.String desc) throws KilimException- Throws:
KilimException
-
toString
private java.lang.String toString(java.lang.String className, java.lang.String methName, java.lang.String desc)
-
visitMethodInsn
public void visitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc, boolean itf)- Overrides:
visitMethodInsnin classorg.objectweb.asm.tree.MethodNode
-
visitInvokeDynamicInsn
public void visitInvokeDynamicInsn(java.lang.String name, java.lang.String desc, org.objectweb.asm.Handle bsm, java.lang.Object... bsmArgs)- Overrides:
visitInvokeDynamicInsnin classorg.objectweb.asm.tree.MethodNode
-
visitLabel
public void visitLabel(org.objectweb.asm.Label label)
- Overrides:
visitLabelin classorg.objectweb.asm.tree.MethodNode
-
visitLineNumber
public void visitLineNumber(int line, org.objectweb.asm.Label start)- Overrides:
visitLineNumberin classorg.objectweb.asm.tree.MethodNode
-
visitLineNumbers
void visitLineNumbers(org.objectweb.asm.MethodVisitor mv)
-
visitFrame
public void visitFrame(int type, int nLocal, java.lang.Object[] local, int nStack, java.lang.Object[] stack)- Overrides:
visitFramein classorg.objectweb.asm.tree.MethodNode
-
inlineSubroutines
private void inlineSubroutines() throws KilimException- Throws:
KilimException
-
markPausableJSRs
private void markPausableJSRs() throws KilimException- Throws:
KilimException
-
isPausableMethodInsn
boolean isPausableMethodInsn(org.objectweb.asm.tree.MethodInsnNode min)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getBasicBlocks
public BBList getBasicBlocks()
-
preAssignCatchHandlers
private void preAssignCatchHandlers()
-
assignCatchHandlers
private void assignCatchHandlers()
-
buildHandlerMap
private void buildHandlerMap(java.util.ArrayList<Handler> sorted)
-
mapHandler
int mapHandler(int start)
return the next handler.from >= start, else -1 - valid only until catch handlers are assigned
-
buildBasicBlocks
void buildBasicBlocks()
-
calcBornOnce
private boolean calcBornOnce()
-
calcBornUsage
private void calcBornUsage()
-
doLiveVarAnalysis
private void doLiveVarAnalysis()
In live var analysis a BB asks its successor (in essence) about which vars are live, mixes it with its own uses and defs and passes on a new list of live vars to its predecessors. Since the information bubbles up the chain, we iterate the list in reverse order, for efficiency. We could order the list topologically or do a depth-first spanning tree, but it seems like overkill for most bytecode procedures. The order of computation doesn't affect the correctness; it merely changes the number of iterations to reach a fixpoint. the algorithm has been updated to track vars that been born, ie def'd by a parameter
-
setArgsBorn
private void setArgsBorn(BasicBlock bb)
-
printUsage
void printUsage(java.util.ArrayList<BasicBlock> bbs)
-
consolidateBasicBlocks
private void consolidateBasicBlocks()
In the first pass (buildBasicBlocks()), we create BBs whenever we encounter a label. We don't really know until we are done with that pass whether a label is the target of a branch instruction or it is there because of an exception handler. See coalesceWithFollowingBlock() for more detail.
-
checkNoBasicBlockLeftBehind
private boolean checkNoBasicBlockLeftBehind()
-
dataFlow
private void dataFlow()
-
setLabel
void setLabel(int pos, org.objectweb.asm.tree.LabelNode l)
-
getOrCreateLabelAtPos
org.objectweb.asm.tree.LabelNode getOrCreateLabelAtPos(int pos)
-
getLabelPosition
int getLabelPosition(org.objectweb.asm.tree.LabelNode l)
-
getOrCreateBasicBlock
BasicBlock getOrCreateBasicBlock(org.objectweb.asm.tree.LabelNode l)
-
getBasicBlock
BasicBlock getBasicBlock(org.objectweb.asm.tree.LabelNode l)
-
dequeue
private BasicBlock dequeue()
-
enqueue
void enqueue(BasicBlock bb)
-
getLabelAt
public org.objectweb.asm.tree.LabelNode getLabelAt(int pos)
-
addInlinedBlock
void addInlinedBlock(BasicBlock bb)
-
getNumArgs
public int getNumArgs()
-
isPausable
public boolean isPausable()
-
setPausable
public void setPausable(boolean isPausable)
-
acceptAnnotation
public static void acceptAnnotation(org.objectweb.asm.AnnotationVisitor av, java.lang.String name, java.lang.Object value)
-
isAbstract
public boolean isAbstract()
-
isStatic
public boolean isStatic()
-
isBridge
public boolean isBridge()
-
resetLabels
public void resetLabels()
-
needsWeaving
boolean needsWeaving()
-
-