Package edu.umd.cs.findbugs
Class OpcodeStack
java.lang.Object
edu.umd.cs.findbugs.OpcodeStack
tracks the types and numbers of objects that are currently on the operand
stack throughout the execution of method. To use, a detector should
instantiate one for each method, and call
stack.sawOpcode(this,seen);
at the bottom of their sawOpcode method. at any point you can then inspect the stack and see what the types of objects are on the stack, including constant values if they were pushed. The types described are of course, only the static types. There are some outstanding opcodes that have yet to be implemented, I couldn't find any code that actually generated these, so i didn't put them in because I couldn't test them:- dup2_x2
- jsr_w
- wide
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interface
You can put this annotation on a OpcodeStack detector to indicate that it usesOpcodeStack.Item.userValue
, and thus should not reuse generic OpcodeStack information from an iterative evaluation of the opcode stack.(package private) static class
static class
static class
static class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
(package private) int
(package private) int
private static final boolean
private static final boolean
(package private) boolean
(package private) BitSet
private String
private static final String
private static final String
private Map
<Integer, List<OpcodeStack.Item>> private BitSet
private boolean
private boolean
private Map
<Integer, List<OpcodeStack.Item>> private List
<OpcodeStack.Item> private String
(package private) boolean
(package private) boolean
private boolean
(package private) int
private boolean
private List
<OpcodeStack.Item> private boolean
private final boolean
(package private) DismantleBytecode
(package private) int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addBoxedType
(Class<?>... clss) private void
addJumpValue
(int from, int target) void
clear()
(package private) void
(package private) void
private static void
clearRegisterLoad
(List<OpcodeStack.Item> list, int register) private double
private float
private int
private long
private void
eraseKnowledgeOf
(XField fieldOperand) private org.apache.bcel.classfile.BootstrapMethod
getBootstrapMethod
(org.apache.bcel.classfile.Attribute[] attribs, org.apache.bcel.classfile.Constant index) static String
getExceptionSig
(DismantleBytecode dbc, org.apache.bcel.classfile.CodeException e) private OpcodeStack.JumpInfo
int
getLastUpdate
(int reg) getLVValue
(int index) int
int
int
getStackItem
(int stackOffset) private String
getStringFromIndex
(DismantleBytecode dbc, int i) private void
handleDcmp
(int opcode) private void
private void
private void
private void
private void
private void
private void
handleFcmp
(int opcode) private void
private void
boolean
hasIncomingBranches
(int pc) void
(package private) boolean
protected boolean
boolean
isJumpTarget
(int pc) private boolean
isMethodThatReturnsGivenReference
(String clsName, String methodName) (package private) boolean
boolean
isTop()
void
private void
void
private boolean
mergeLists
(List<OpcodeStack.Item> mergeInto, List<OpcodeStack.Item> mergeFrom, boolean errorIfSizesDoNotMatch) (package private) int
nullSafeSize
(Collection<?> c) private OpcodeStack.Item
pop()
private void
pop
(int count) void
void
private void
private void
processMethodCall
(DismantleBytecode dbc, int seen) private void
private void
pushByConstant
(DismantleBytecode dbc, org.apache.bcel.classfile.Constant c) private void
pushByDoubleMath
(int seen, OpcodeStack.Item it, OpcodeStack.Item it2) private void
pushByFloatMath
(int seen, OpcodeStack.Item it, OpcodeStack.Item it2) private void
pushByIntMath
(DismantleBytecode dbc, int seen, OpcodeStack.Item lhs, OpcodeStack.Item rhs) private void
pushByInvoke
(DismantleBytecode dbc, boolean popThis) private void
pushByLocalLoad
(String signature, int register) private void
pushByLocalObjectLoad
(DismantleBytecode dbc, int register) private void
pushByLocalStore
(int register) private void
pushByLongMath
(int seen, OpcodeStack.Item lhs, OpcodeStack.Item rhs) private void
pushBySignature
(String s, DismantleBytecode dbc) void
replace
(int stackOffset, OpcodeStack.Item value) void
replaceTop
(OpcodeStack.Item newTop) int
resetForMethodEntry
(DismantleBytecode visitor) private int
resetForMethodEntry0
(PreorderVisitor visitor) (package private) int
resetForMethodEntry0
(String className, org.apache.bcel.classfile.Method m) void
sawOpcode
(DismantleBytecode dbc, int seen) void
setJumpInfoChangedByBackwardBranch
(String kind, int from, int to) (package private) void
setJumpInfoChangedByBackwardsBranch
(int from, int to) protected void
private void
setLastUpdate
(int reg, int pc) private void
setLVValue
(int index, OpcodeStack.Item value) (package private) void
setReachOnlyByBranch
(boolean reachOnlyByBranch) private void
setTop
(boolean top) private OpcodeStack.Item
top()
toString()
-
Field Details
-
JAVA_UTIL_ARRAYS_ARRAY_LIST
- See Also:
-
JAVA_UTIL_COLLECTIONS
- See Also:
-
DEBUG
private static final boolean DEBUG -
DEBUG2
private static final boolean DEBUG2 -
IMMUTABLE_RETURNER_MAP
-
boxedTypes
-
stack
-
lvValues
-
lastUpdate
-
top
private boolean top -
seenTransferOfControl
private boolean seenTransferOfControl -
useIterativeAnalysis
private final boolean useIterativeAnalysis -
encountedTop
boolean encountedTop -
backwardsBranch
boolean backwardsBranch -
exceptionHandlers
BitSet exceptionHandlers -
jumpInfoChangedByBackwardsBranch
private boolean jumpInfoChangedByBackwardsBranch -
jumpInfoChangedByNewTarget
private boolean jumpInfoChangedByNewTarget -
jumpEntries
-
jumpStackEntries
-
jumpEntryLocations
-
convertJumpToOneZeroState
int convertJumpToOneZeroState -
convertJumpToZeroOneState
int convertJumpToZeroOneState -
registerTestedFoundToBeNonnegative
int registerTestedFoundToBeNonnegative -
zeroOneComing
int zeroOneComing -
oneMeansNull
boolean oneMeansNull -
needToMerge
boolean needToMerge -
reachOnlyByBranch
private boolean reachOnlyByBranch -
methodName
-
fullyQualifiedMethodName
-
v
-
-
Constructor Details
-
OpcodeStack
public OpcodeStack()
-
-
Method Details
-
toString
-
hasIncomingBranches
public boolean hasIncomingBranches(int pc) -
getExceptionSig
public static String getExceptionSig(DismantleBytecode dbc, org.apache.bcel.classfile.CodeException e) -
mergeJumps
-
setLastUpdate
private void setLastUpdate(int reg, int pc) -
getLastUpdate
public int getLastUpdate(int reg) -
getNumLastUpdates
public int getNumLastUpdates() -
sawOpcode
-
eraseKnowledgeOf
-
precomputation
-
constantToInt
-
constantToFloat
-
constantToDouble
-
constantToLong
-
handleDcmp
private void handleDcmp(int opcode) -
handleFcmp
private void handleFcmp(int opcode) -
handleLcmp
private void handleLcmp() -
handleSwap
private void handleSwap() -
handleDup
private void handleDup() -
handleDupX1
private void handleDupX1() -
handleDup2
private void handleDup2() -
handleDup2X1
private void handleDup2X1() -
handleDup2X2
private void handleDup2X2() -
handleDupX2
private void handleDupX2() -
addBoxedType
-
markConstantValueUnknown
-
processMethodCall
-
isMethodThatReturnsGivenReference
-
processInvokeDynamic
-
getBootstrapMethod
private org.apache.bcel.classfile.BootstrapMethod getBootstrapMethod(org.apache.bcel.classfile.Attribute[] attribs, org.apache.bcel.classfile.Constant index) -
mergeLists
private boolean mergeLists(List<OpcodeStack.Item> mergeInto, List<OpcodeStack.Item> mergeFrom, boolean errorIfSizesDoNotMatch) -
clear
public void clear() -
printJumpEntries
public void printJumpEntries() -
isJumpTarget
public boolean isJumpTarget(int pc) -
addJumpValue
private void addJumpValue(int from, int target) -
learnFrom
-
initialize
public void initialize() -
resetForMethodEntry
-
nullSafeSize
-
getJumpInfo
-
getJumpInfoFromStackMap
-
setJumpInfoChangedByBackwardBranch
-
resetForMethodEntry0
-
resetForMethodEntry0
-
getStackDepth
public int getStackDepth() -
getStackItem
-
pop
-
top
-
replace
-
replaceTop
-
pop
private void pop(int count) -
push
-
pushByConstant
-
pushByLocalObjectLoad
-
pushByIntMath
private void pushByIntMath(DismantleBytecode dbc, int seen, OpcodeStack.Item lhs, OpcodeStack.Item rhs) -
pushByLongMath
-
pushByFloatMath
-
pushByDoubleMath
-
pushByInvoke
-
getItemMethodInvokedOn
-
getStringFromIndex
-
pushBySignature
-
pushByLocalStore
private void pushByLocalStore(int register) -
clearRegisterLoad
-
pushByLocalLoad
-
setLVValue
-
getLVValue
-
getNumLocalValues
public int getNumLocalValues() -
setTop
private void setTop(boolean top) -
isTop
public boolean isTop() -
setReachOnlyByBranch
void setReachOnlyByBranch(boolean reachOnlyByBranch) -
isReachOnlyByBranch
boolean isReachOnlyByBranch() -
isJumpInfoChangedByBackwardsBranch
boolean isJumpInfoChangedByBackwardsBranch() -
clearJumpInfoChangedByBackwardsBranch
void clearJumpInfoChangedByBackwardsBranch() -
setJumpInfoChangedByBackwardsBranch
void setJumpInfoChangedByBackwardsBranch(int from, int to) -
isJumpInfoChangedByNewTarget
protected boolean isJumpInfoChangedByNewTarget()- Returns:
- Returns the jumpInfoChangedByNewTarget.
-
clearJumpInfoChangedByNewTarget
void clearJumpInfoChangedByNewTarget() -
setJumpInfoChangedByNewTarget
protected void setJumpInfoChangedByNewTarget()
-