Package edu.umd.cs.findbugs.visitclass
Class DismantleBytecode
- java.lang.Object
-
- edu.umd.cs.findbugs.visitclass.BetterVisitor
-
- edu.umd.cs.findbugs.visitclass.PreorderVisitor
-
- edu.umd.cs.findbugs.visitclass.AnnotationVisitor
-
- edu.umd.cs.findbugs.visitclass.DismantleBytecode
-
- All Implemented Interfaces:
org.apache.bcel.classfile.Visitor
- Direct Known Subclasses:
BytecodeScanningDetector
,CloneIdiom
,NoteDirectlyRelevantTypeQualifiers
public abstract class DismantleBytecode extends AnnotationVisitor
-
-
Field Summary
Fields Modifier and Type Field Description private int
branchFallThrough
private int
branchOffset
private int
branchTarget
private java.lang.String
classConstantOperand
protected byte[]
codeBytes
private org.apache.bcel.classfile.Constant
constantRefOperand
private int
currentPosInPrevOpcodeBuffer
private int
defaultSwitchOffset
private java.lang.String
dottedClassConstantOperand
private double
doubleConstant
private float
floatConstant
private static java.text.NumberFormat
formatter
private int
intConstant
private static int
INVALID_OFFSET
private boolean
isRegisterLoad
private boolean
isRegisterStore
protected org.apache.bcel.classfile.LineNumberTable
lineNumberTable
private long
longConstant
static byte
M_BR
static byte
M_CP
static byte
M_INT
Meaning of bytecode operandsstatic byte
M_PAD
static byte
M_R
static byte
M_UINT
(package private) static byte[][]
MEANING_OF_OPERANDS
Meaning of bytecode operandsprivate java.lang.String
nameConstantOperand
private int
nextPC
private static java.lang.String
NOT_AVAILABLE
private int
opcode
private boolean
opcodeIsWide
private int
PC
private int[]
prevOpcode
private java.lang.String
refConstantOperand
private ClassDescriptor
referencedClass
private FieldDescriptor
referencedField
private MethodDescriptor
referencedMethod
private XClass
referencedXClass
private XField
referencedXField
private XMethod
referencedXMethod
private boolean
refFieldIsStatic
private int
registerOperand
private java.lang.String
sigConstantOperand
private int
sizePrevOpcodeBuffer
private java.lang.String
stringConstantOperand
private int[]
switchLabels
private int[]
switchOffsets
-
Fields inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor
DEBUG
-
Fields inherited from class edu.umd.cs.findbugs.visitclass.PreorderVisitor
argumentSignature, visitMethodsInCallOrder
-
-
Constructor Summary
Constructors Constructor Description DismantleBytecode()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
afterOpcode(int seen)
static boolean
areOppositeBranches(int opcode1, int opcode2)
boolean
atCatchBlock()
boolean
beforeOpcode(int seen)
return false if we should skip calling sawOpcodeint
getBranchFallThrough()
int
getBranchOffset()
int
getBranchTarget()
java.lang.String
getClassConstantOperand()
If the current opcode has a class constant operand, get the classname, slash-formatted.ClassDescriptor
getClassDescriptorOperand()
int
getCodeByte(int offset)
org.apache.bcel.classfile.Constant
getConstantRefOperand()
int
getDefaultSwitchOffset()
java.lang.String
getDottedClassConstantOperand()
If the current opcode has a class operand, get the associated class constant, dot-formattedFieldDescriptor
getFieldDescriptorOperand()
int
getIntConstant()
long
getLongConstant()
int
getMaxPC()
MethodDescriptor
getMethodDescriptorOperand()
java.lang.String
getNameConstantOperand()
If the current opcode has a reference constant operand, get its nameint
getNextCodeByte(int offset)
int
getNextOpcode()
int
getNextPC()
int
getOpcode()
int
getPC()
int
getPrevOpcode(int offset)
return previous opcode;java.lang.String
getRefConstantOperand()
Deprecated.private XClass
getReferencedXClass()
boolean
getRefFieldIsStatic()
int
getRegisterOperand()
java.lang.String
getSigConstantOperand()
If the current opcode has a reference constant operand, get its signature, slash-formattedjava.lang.String
getStringConstantOperand()
If the current opcode has a string constant operand, get its nameint[]
getSwitchLabels()
int[]
getSwitchOffsets()
XClass
getXClassOperand()
XField
getXFieldOperand()
XMethod
getXMethodOperand()
static boolean
isBranch(int opcode)
Return whether or not given opcode is a branch instruction.boolean
isMethodCall()
boolean
isRegisterLoad()
boolean
isRegisterStore()
boolean
isRegisterStore(int opcode)
boolean
isReturn(int opcode)
boolean
isShift(int opcode)
static boolean
isSwitch(int opcode)
Return whether or not given opcode is a switch instruction.boolean
isWideOpcode()
void
printOpCode(int seen)
(package private) static java.lang.String
replaceSlashesWithDots(java.lang.String c)
private void
resetState()
void
sawBranchTo(int targetPC)
void
sawClass()
void
sawDouble(double seen)
void
sawField()
void
sawFloat(float seen)
void
sawIMethod()
void
sawInt(int seen)
void
sawLong(long seen)
void
sawMethod()
void
sawOpcode(int seen)
void
sawRegister(int r)
void
sawString(java.lang.String seen)
private void
setReferencedXClass(XClass referencedXClass)
private static void
sortByOffset(int[] switchOffsets, int[] switchLabels)
void
visit(org.apache.bcel.classfile.Code obj)
-
Methods inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor
getAnnotationParameterAsEnum, getAnnotationParameterAsString, getAnnotationParameterAsStringArray, visitAnnotation, visitAnnotation, visitParameterAnnotation, visitParameterAnnotation, visitSyntheticParameterAnnotation
-
Methods inherited from class edu.umd.cs.findbugs.visitclass.PreorderVisitor
amVisitingMainMethod, asUnsignedByte, doVisitMethod, getClassDescriptor, getClassName, getCode, getConstantPool, getDottedClassName, getDottedFieldSig, getDottedMethodSig, getDottedSuperclassName, getField, getFieldDescriptor, getFieldIsStatic, getFieldName, getFieldSig, getFullyQualifiedFieldName, getFullyQualifiedMethodName, getMethod, getMethodDescriptor, getMethodName, getMethodSig, getMethodVisitOrder, getNumberArguments, getNumberMethodArguments, getPackageName, getSizeOfSurroundingTryBlock, getSizeOfSurroundingTryBlock, getSourceFile, getStringFromIndex, getSuperclassName, getSurroundingCaughtExceptions, getSurroundingCaughtExceptions, getSurroundingCaughtExceptionTypes, getSurroundingTryBlock, getSurroundingTryBlock, getThisClass, getXClass, getXField, getXMethod, hasInterestingClass, hasInterestingMethod, isVisitMethodsInCallOrder, setupVisitorForClass, setVisitMethodsInCallOrder, shouldVisit, toString, visitAfter, visitAfter, visitAnnotationDefault, visitAnnotationEntry, visitBootstrapMethods, visitCode, visitConstantInvokeDynamic, visitConstantMethodHandle, visitConstantMethodType, visitConstantModule, visitConstantPackage, visitConstantPool, visitEnclosingMethod, visitingField, visitingMethod, visitInnerClasses, visitJavaClass, visitLineNumberTable, visitLocalVariableTable, visitMethodParameters, visitParameterAnnotationEntry, visitStackMap, visitStackMapEntry
-
Methods inherited from class edu.umd.cs.findbugs.visitclass.BetterVisitor
clone, report, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, visitField, visitInnerClass, visitLineNumber, visitLocalVariable, visitLocalVariableTypeTable, visitMethod, visitSignature, visitSourceFile, visitSynthetic, visitUnknown
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.bcel.classfile.Visitor
visitConstantDynamic, visitMethodParameter, visitModule, visitModuleExports, visitModuleMainClass, visitModuleOpens, visitModulePackages, visitModuleProvides, visitModuleRequires, visitNestHost, visitNestMembers, visitRecord, visitRecordComponent, visitStackMapType
-
-
-
-
Field Detail
-
opcode
private int opcode
-
opcodeIsWide
private boolean opcodeIsWide
-
PC
private int PC
-
nextPC
private int nextPC
-
branchOffset
private int branchOffset
-
branchTarget
private int branchTarget
-
branchFallThrough
private int branchFallThrough
-
switchOffsets
private int[] switchOffsets
-
switchLabels
private int[] switchLabels
-
prevOpcode
private final int[] prevOpcode
-
currentPosInPrevOpcodeBuffer
private int currentPosInPrevOpcodeBuffer
-
sizePrevOpcodeBuffer
private int sizePrevOpcodeBuffer
-
defaultSwitchOffset
private int defaultSwitchOffset
-
classConstantOperand
@SlashedClassName private java.lang.String classConstantOperand
-
referencedClass
private ClassDescriptor referencedClass
-
referencedXClass
private XClass referencedXClass
-
referencedMethod
private MethodDescriptor referencedMethod
-
referencedXMethod
private XMethod referencedXMethod
-
referencedField
private FieldDescriptor referencedField
-
referencedXField
private XField referencedXField
-
dottedClassConstantOperand
private java.lang.String dottedClassConstantOperand
-
nameConstantOperand
private java.lang.String nameConstantOperand
-
sigConstantOperand
private java.lang.String sigConstantOperand
-
stringConstantOperand
private java.lang.String stringConstantOperand
-
refConstantOperand
private java.lang.String refConstantOperand
-
refFieldIsStatic
private boolean refFieldIsStatic
-
constantRefOperand
private org.apache.bcel.classfile.Constant constantRefOperand
-
intConstant
private int intConstant
-
longConstant
private long longConstant
-
floatConstant
private float floatConstant
-
doubleConstant
private double doubleConstant
-
registerOperand
private int registerOperand
-
isRegisterLoad
private boolean isRegisterLoad
-
isRegisterStore
private boolean isRegisterStore
-
INVALID_OFFSET
private static final int INVALID_OFFSET
- See Also:
- Constant Field Values
-
NOT_AVAILABLE
private static final java.lang.String NOT_AVAILABLE
- See Also:
- Constant Field Values
-
M_INT
public static final byte M_INT
Meaning of bytecode operands- See Also:
- Constant Field Values
-
M_UINT
public static final byte M_UINT
- See Also:
- Constant Field Values
-
M_CP
public static final byte M_CP
- See Also:
- Constant Field Values
-
M_R
public static final byte M_R
- See Also:
- Constant Field Values
-
M_BR
public static final byte M_BR
- See Also:
- Constant Field Values
-
M_PAD
public static final byte M_PAD
- See Also:
- Constant Field Values
-
MEANING_OF_OPERANDS
static final byte[][] MEANING_OF_OPERANDS
Meaning of bytecode operands
-
codeBytes
protected byte[] codeBytes
-
lineNumberTable
protected org.apache.bcel.classfile.LineNumberTable lineNumberTable
-
formatter
private static java.text.NumberFormat formatter
-
-
Method Detail
-
replaceSlashesWithDots
static java.lang.String replaceSlashesWithDots(java.lang.String c)
-
getClassDescriptorOperand
public ClassDescriptor getClassDescriptorOperand()
-
getXClassOperand
@CheckForNull public XClass getXClassOperand()
-
isMethodCall
public boolean isMethodCall()
-
getMethodDescriptorOperand
public MethodDescriptor getMethodDescriptorOperand()
-
getXMethodOperand
@CheckForNull public XMethod getXMethodOperand()
-
getFieldDescriptorOperand
public FieldDescriptor getFieldDescriptorOperand()
-
getXFieldOperand
@CheckForNull public XField getXFieldOperand()
-
getDottedClassConstantOperand
public java.lang.String getDottedClassConstantOperand()
If the current opcode has a class operand, get the associated class constant, dot-formatted
-
getRefConstantOperand
@Deprecated public java.lang.String getRefConstantOperand()
Deprecated.If the current opcode has a reference constant operand, get its string representation
-
getNameConstantOperand
public java.lang.String getNameConstantOperand()
If the current opcode has a reference constant operand, get its name
-
getSigConstantOperand
public java.lang.String getSigConstantOperand()
If the current opcode has a reference constant operand, get its signature, slash-formatted
-
getClassConstantOperand
@SlashedClassName public java.lang.String getClassConstantOperand()
If the current opcode has a class constant operand, get the classname, slash-formatted.
-
getStringConstantOperand
public java.lang.String getStringConstantOperand()
If the current opcode has a string constant operand, get its name
-
getConstantRefOperand
public org.apache.bcel.classfile.Constant getConstantRefOperand()
-
isRegisterLoad
public boolean isRegisterLoad()
-
isRegisterStore
public boolean isRegisterStore()
-
getRegisterOperand
public int getRegisterOperand()
-
getIntConstant
public int getIntConstant()
-
getLongConstant
public long getLongConstant()
-
getBranchOffset
public int getBranchOffset()
-
getBranchTarget
public int getBranchTarget()
-
getBranchFallThrough
public int getBranchFallThrough()
-
getDefaultSwitchOffset
public int getDefaultSwitchOffset()
-
getRefFieldIsStatic
public boolean getRefFieldIsStatic()
-
getPC
public int getPC()
-
getPrevOpcode
public int getPrevOpcode(int offset)
return previous opcode;- Parameters:
offset
- 0 for current opcode, 1 for one before that, etc.
-
isWideOpcode
public boolean isWideOpcode()
-
isBranch
public static boolean isBranch(int opcode)
Return whether or not given opcode is a branch instruction.- Parameters:
opcode
- the opcode- Returns:
- true if instruction is a branch, false if not
-
isSwitch
public static boolean isSwitch(int opcode)
Return whether or not given opcode is a switch instruction.- Parameters:
opcode
- the opcode- Returns:
- true if instruction is a switch, false if not
-
getSwitchOffsets
public int[] getSwitchOffsets()
-
getSwitchLabels
public int[] getSwitchLabels()
-
resetState
private void resetState()
-
sortByOffset
private static void sortByOffset(int[] switchOffsets, int[] switchLabels)
-
getMaxPC
public int getMaxPC()
-
getCodeByte
public int getCodeByte(int offset)
-
getOpcode
public int getOpcode()
-
atCatchBlock
public boolean atCatchBlock()
-
visit
public void visit(org.apache.bcel.classfile.Code obj)
- Overrides:
visit
in classBetterVisitor
-
sawDouble
public void sawDouble(double seen)
-
sawFloat
public void sawFloat(float seen)
-
sawRegister
public void sawRegister(int r)
-
sawInt
public void sawInt(int seen)
-
sawLong
public void sawLong(long seen)
-
sawBranchTo
public void sawBranchTo(int targetPC)
-
beforeOpcode
public boolean beforeOpcode(int seen)
return false if we should skip calling sawOpcode
-
afterOpcode
public void afterOpcode(int seen)
-
sawOpcode
public void sawOpcode(int seen)
-
sawString
public void sawString(java.lang.String seen)
-
sawField
public void sawField()
-
sawMethod
public void sawMethod()
-
sawIMethod
public void sawIMethod()
-
sawClass
public void sawClass()
-
printOpCode
public void printOpCode(int seen)
-
getNextPC
public int getNextPC()
- Returns:
- Returns the nextPC.
-
getNextOpcode
public int getNextOpcode()
-
getNextCodeByte
public int getNextCodeByte(int offset)
-
isReturn
public boolean isReturn(int opcode)
-
isShift
public boolean isShift(int opcode)
-
areOppositeBranches
public static boolean areOppositeBranches(int opcode1, int opcode2)
-
isRegisterStore
public boolean isRegisterStore(int opcode)
-
setReferencedXClass
private void setReferencedXClass(XClass referencedXClass)
- Parameters:
referencedXClass
- The referencedXClass to set.
-
getReferencedXClass
private XClass getReferencedXClass()
- Returns:
- Returns the referencedXClass.
-
-