com.markcrocker.purifier
Class BranchStack
java.lang.Object
|
+--com.markcrocker.purifier.BranchStack
- public class BranchStack
- extends java.lang.Object
Data structure class for holding and visiting BranchTargets. Not to be
confused with the visitor pattern. Keeps track of whether a branch target has been examined or not so that Control Flow Analysis can avoid going over the same branch multiple times. This is very different than what a full preverifier would do. For example, the org.apache.bcel.verifier.structurals.Pass3bVerifier makes sure that it goes through every possible path through the code to verify that everything is consistent regardless of the path. The BranchStack is designed with the assumption that such a consistency check has already been done and that the only neccessary work required is to go through each branch as few times as possible to calculate the Frame.
- Author:
- M. Dahm, Patrick C. Beard, Mark Crocker
- See Also:
BranchTarget
,
MethodGen
Method Summary |
BranchTarget |
pop()
Pop a branch target off of the branch target stack |
Frame |
push(org.apache.bcel.generic.InstructionHandle target,
int stackDepth,
Frame frame)
Push a branch target onto the branch target stack unless it has already
been visited. |
void |
squeeze(BranchTarget branchTarget)
"Squeeze" a branch target onto the bottom branch target stack. |
private BranchTarget |
visit(org.apache.bcel.generic.InstructionHandle target,
int stackDepth,
Frame frame)
Create a new BranchTarget instance and add it to the list of visited
targets. |
private boolean |
visited(org.apache.bcel.generic.InstructionHandle target)
Indicates whether a particular branch target has been visited before. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
branchTargets
java.util.Stack branchTargets
visitedTargets
java.util.Hashtable visitedTargets
BranchStack
public BranchStack()
push
public Frame push(org.apache.bcel.generic.InstructionHandle target,
int stackDepth,
Frame frame)
- Push a branch target onto the branch target stack unless it has already
been visited. If a target has already been visited and a discrepancy exists between the local variables in the new frame and the stored frame, then the conflict is resolved and the stored frame is updated accordingly.
- Returns:
- normally a null Frame. If there is a dispute in local variable
table entries, a 'corrected' frame is returned.
squeeze
public void squeeze(BranchTarget branchTarget)
- "Squeeze" a branch target onto the bottom branch target stack. This is
required when the StackMapGen pops a BranchTarget off of the stack that has a null entry in the LocalVariables table because it represents an exception entry point to the method and the corresponding try-block has not been examined yet to be able to set the LocalVariables correctly. By squeezing the target under the stack, other targets can be processed in the hope that the offending BranchTarget's try-block will be examined before the target reaches the top of the stack again.
pop
public BranchTarget pop()
- Pop a branch target off of the branch target stack
visit
private final BranchTarget visit(org.apache.bcel.generic.InstructionHandle target,
int stackDepth,
Frame frame)
- Create a new BranchTarget instance and add it to the list of visited
targets. Used by the push method.
visited
private final boolean visited(org.apache.bcel.generic.InstructionHandle target)
- Indicates whether a particular branch target has been visited before.
Keeping track of branches that have already been investigated helps the Control Flow Analysis avoid duplication of effort.
- Parameters:
target
- The target to be checked for evidence of previous
visitation.- Returns:
- true if the target has been visited before, false otherwise.