public class InstructionSequenceMatcher extends java.lang.Object implements InstructionVisitor, ConstantVisitor
InstructionVisitor checks whether a given pattern instruction sequence
occurs in the instructions that are visited. The arguments of the
instruction sequence can be wildcards that are matched.| Modifier and Type | Field and Description |
|---|---|
static int |
A |
static int |
B |
static int |
C |
static int |
D |
static int |
E |
static int |
F |
static int |
G |
static int |
H |
static int |
I |
static int |
J |
static int |
K |
static int |
L |
static int |
M |
protected boolean |
matchingConstant |
static int |
N |
static int |
O |
static int |
P |
protected Constant |
patternConstant |
protected Constant[] |
patternConstants |
protected Instruction[] |
patternInstructions |
static int |
Q |
static int |
R |
static int |
X |
static int |
Y |
static int |
Z |
| Constructor and Description |
|---|
InstructionSequenceMatcher(Constant[] patternConstants,
Instruction[] patternInstructions)
Creates a new InstructionSequenceMatcher.
|
InstructionSequenceMatcher(Constant[] patternConstants,
Instruction[] patternInstructions,
boolean matchSubclasses)
Creates a new InstructionSequenceMatcher.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
finalMatch(Clazz clazz,
Method method,
CodeAttribute codeAttribute,
int offset,
Instruction instruction)
Performs a final check on the candidate sequence to match,
after the pattern has been successfully fully matched with the
sequence.
|
int |
instructionCount()
Returns the number of instructions in the pattern sequence.
|
boolean |
isMatching()
Returns whether the complete pattern sequence has been matched.
|
static void |
main(java.lang.String[] args)
Small sample application that illustrates the use of this class.
|
int |
matchedArgument(int argument)
Returns the value of the specified matched argument (wildcard or not).
|
int[] |
matchedArguments(int[] arguments)
Returns the values of the specified matched arguments (wildcard or not).
|
int |
matchedBranchOffset(int offset,
int branchOffset)
Returns the value of the specified matched branch offset (wildcard or
not).
|
int |
matchedConstantIndex(int constantIndex)
Returns the index of the specified matched constant (wildcard or not).
|
int |
matchedInstructionOffset(int index)
Returns the matched instruction offset of the specified pattern
instruction.
|
int[] |
matchedJumpOffsets(int offset,
int[] jumpOffsets)
Returns the values of the specified matched jump offsets (wildcard or
not).
|
protected boolean |
matchingArguments(int[] arguments1,
int[] arguments2) |
protected boolean |
matchingArguments(int argument1,
int argument2) |
protected boolean |
matchingBranchOffsets(int offset,
int branchOffset1,
int branchOffset2) |
protected boolean |
matchingConstantIndices(Clazz clazz,
int constantIndex1,
int constantIndex2) |
protected boolean |
matchingJumpOffsets(int offset,
int[] jumpOffsets1,
int[] jumpOffsets2) |
protected boolean |
matchingOpcodes(Instruction instruction1,
Instruction instruction2) |
void |
reset()
Starts matching from the first instruction again next time.
|
void |
visitAnyRefConstant(Clazz clazz,
RefConstant refConstant)
Visits any RefConstant instance.
|
void |
visitBranchInstruction(Clazz clazz,
Method method,
CodeAttribute codeAttribute,
int offset,
BranchInstruction branchInstruction) |
void |
visitClassConstant(Clazz clazz,
ClassConstant classConstant) |
void |
visitConstantInstruction(Clazz clazz,
Method method,
CodeAttribute codeAttribute,
int offset,
ConstantInstruction constantInstruction) |
void |
visitDoubleConstant(Clazz clazz,
DoubleConstant doubleConstant) |
void |
visitDynamicConstant(Clazz clazz,
DynamicConstant dynamicConstant) |
void |
visitFloatConstant(Clazz clazz,
FloatConstant floatConstant) |
void |
visitIntegerConstant(Clazz clazz,
IntegerConstant integerConstant) |
void |
visitInvokeDynamicConstant(Clazz clazz,
InvokeDynamicConstant invokeDynamicConstant) |
void |
visitLongConstant(Clazz clazz,
LongConstant longConstant) |
void |
visitLookUpSwitchInstruction(Clazz clazz,
Method method,
CodeAttribute codeAttribute,
int offset,
LookUpSwitchInstruction lookUpSwitchInstruction) |
void |
visitMethodHandleConstant(Clazz clazz,
MethodHandleConstant methodHandleConstant) |
void |
visitMethodTypeConstant(Clazz clazz,
MethodTypeConstant methodTypeConstant) |
void |
visitNameAndTypeConstant(Clazz clazz,
NameAndTypeConstant nameAndTypeConstant) |
void |
visitPrimitiveArrayConstant(Clazz clazz,
PrimitiveArrayConstant primitiveArrayConstant) |
void |
visitSimpleInstruction(Clazz clazz,
Method method,
CodeAttribute codeAttribute,
int offset,
SimpleInstruction simpleInstruction) |
void |
visitStringConstant(Clazz clazz,
StringConstant stringConstant) |
void |
visitTableSwitchInstruction(Clazz clazz,
Method method,
CodeAttribute codeAttribute,
int offset,
TableSwitchInstruction tableSwitchInstruction) |
void |
visitUtf8Constant(Clazz clazz,
Utf8Constant utf8Constant) |
void |
visitVariableInstruction(Clazz clazz,
Method method,
CodeAttribute codeAttribute,
int offset,
VariableInstruction variableInstruction) |
boolean |
wasConstant(int argument)
Returns whether the specified wildcard argument was a constant from
the constant pool in the most recent match.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitvisitAnyInstruction, visitAnySwitchInstructionvisitAnyConstant, visitAnyMethodrefConstant, visitFieldrefConstant, visitInterfaceMethodrefConstant, visitMethodrefConstant, visitModuleConstant, visitPackageConstantpublic static final int X
public static final int Y
public static final int Z
public static final int A
public static final int B
public static final int C
public static final int D
public static final int E
public static final int F
public static final int G
public static final int H
public static final int I
public static final int J
public static final int K
public static final int L
public static final int M
public static final int N
public static final int O
public static final int P
public static final int Q
public static final int R
protected final Constant[] patternConstants
protected final Instruction[] patternInstructions
protected Constant patternConstant
protected boolean matchingConstant
public InstructionSequenceMatcher(Constant[] patternConstants, Instruction[] patternInstructions)
patternConstants - any constants referenced by the pattern
instruction.patternInstructions - the pattern instruction sequence.public InstructionSequenceMatcher(Constant[] patternConstants, Instruction[] patternInstructions, boolean matchSubclasses)
patternConstants - any constants referenced by the pattern
instruction.patternInstructions - the pattern instruction sequence.matchSubclasses - whether constant references on subclasses are matching when the pattern contains
a constant of a superclass. (default: false)public void reset()
public boolean isMatching()
public int instructionCount()
public int matchedInstructionOffset(int index)
public boolean wasConstant(int argument)
public int matchedArgument(int argument)
public int[] matchedArguments(int[] arguments)
public int matchedConstantIndex(int constantIndex)
public int matchedBranchOffset(int offset,
int branchOffset)
public int[] matchedJumpOffsets(int offset,
int[] jumpOffsets)
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
visitSimpleInstruction in interface InstructionVisitorpublic void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
visitVariableInstruction in interface InstructionVisitorpublic void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
visitConstantInstruction in interface InstructionVisitorpublic void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
visitBranchInstruction in interface InstructionVisitorpublic void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction)
visitTableSwitchInstruction in interface InstructionVisitorpublic void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction)
visitLookUpSwitchInstruction in interface InstructionVisitorpublic void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)
visitIntegerConstant in interface ConstantVisitorpublic void visitLongConstant(Clazz clazz, LongConstant longConstant)
visitLongConstant in interface ConstantVisitorpublic void visitFloatConstant(Clazz clazz, FloatConstant floatConstant)
visitFloatConstant in interface ConstantVisitorpublic void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)
visitDoubleConstant in interface ConstantVisitorpublic void visitPrimitiveArrayConstant(Clazz clazz, PrimitiveArrayConstant primitiveArrayConstant)
visitPrimitiveArrayConstant in interface ConstantVisitorpublic void visitStringConstant(Clazz clazz, StringConstant stringConstant)
visitStringConstant in interface ConstantVisitorpublic void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
visitUtf8Constant in interface ConstantVisitorpublic void visitDynamicConstant(Clazz clazz, DynamicConstant dynamicConstant)
visitDynamicConstant in interface ConstantVisitorpublic void visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant)
visitInvokeDynamicConstant in interface ConstantVisitorpublic void visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant)
visitMethodHandleConstant in interface ConstantVisitorpublic void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
ConstantVisitorvisitAnyRefConstant in interface ConstantVisitorpublic void visitClassConstant(Clazz clazz, ClassConstant classConstant)
visitClassConstant in interface ConstantVisitorpublic void visitMethodTypeConstant(Clazz clazz, MethodTypeConstant methodTypeConstant)
visitMethodTypeConstant in interface ConstantVisitorpublic void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)
visitNameAndTypeConstant in interface ConstantVisitorprotected boolean matchingOpcodes(Instruction instruction1, Instruction instruction2)
protected boolean matchingArguments(int argument1,
int argument2)
protected boolean matchingArguments(int[] arguments1,
int[] arguments2)
protected boolean matchingConstantIndices(Clazz clazz, int constantIndex1, int constantIndex2)
protected boolean matchingBranchOffsets(int offset,
int branchOffset1,
int branchOffset2)
protected boolean matchingJumpOffsets(int offset,
int[] jumpOffsets1,
int[] jumpOffsets2)
protected boolean finalMatch(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction)
public static void main(java.lang.String[] args)