proguard.optimize.peephole
Class BranchTargetFinder

java.lang.Object
  extended by proguard.classfile.util.SimplifiedVisitor
      extended by proguard.optimize.peephole.BranchTargetFinder
All Implemented Interfaces:
AttributeVisitor, ExceptionInfoVisitor, ConstantVisitor, InstructionVisitor

public class BranchTargetFinder
extends SimplifiedVisitor
implements AttributeVisitor, InstructionVisitor, ExceptionInfoVisitor, ConstantVisitor

This AttributeVisitor finds all instruction offsets, branch targets, and exception targets in the CodeAttribute objects that it visits.


Field Summary
static int AT_METHOD_ENTRY
           
static int NONE
           
 
Constructor Summary
BranchTargetFinder()
           
 
Method Summary
 int creationOffset(int offset)
          Returns the offset of the 'new' instruction that corresponds to the invocation of the instance initializer at the given offset, or AT_METHOD_ENTRY if the invocation is calling the "super" or "this" initializer method, , or NONE if it is not a 'new' instruction.
 int initializationOffset(int offset)
          Returns the instruction offset at which the object instance that is created at the given 'new' instruction offset is initialized, or NONE if it is not being created.
 boolean isAfterBranch(int offset)
          Returns whether the instruction at the given offset comes right after a definite branch instruction in the CodeAttribute that was visited most recently.
 boolean isBranchOrigin(int offset)
          Returns whether the instruction at the given offset is the origin of a branch instruction in the CodeAttribute that was visited most recently.
 boolean isBranchTarget(int offset)
          Returns whether the instruction at the given offset is the target of a branch instruction in the CodeAttribute that was visited most recently.
 boolean isExceptionEnd(int offset)
          Returns whether the instruction at the given offset is the end of an exception try block in the CodeAttribute that was visited most recently.
 boolean isExceptionHandler(int offset)
          Returns whether the instruction at the given offset is the start of an exception catch block in the CodeAttribute that was visited most recently.
 boolean isExceptionStart(int offset)
          Returns whether the instruction at the given offset is the start of an exception try block in the CodeAttribute that was visited most recently.
 boolean isInitializer()
          Returns whether the method is an instance initializer, in the CodeAttribute that was visited most recently.
 boolean isInitializer(int offset)
          Returns whether the instruction at the given offset is the special invocation of an instance initializer, in the CodeAttribute that was visited most recently.
 boolean isInstruction(int offset)
          Returns whether there is an instruction at the given offset in the CodeAttribute that was visited most recently.
 boolean isNew(int offset)
          Returns whether the instruction at the given offset is a 'new' instruction, in the CodeAttribute that was visited most recently.
 boolean isSubroutine(int offset)
          Returns whether the instruction at the given offset is part of a subroutine in the CodeAttribute that was visited most recently.
 boolean isSubroutineInvocation(int offset)
          Returns whether the instruction at the given offset is a subroutine invocation in the CodeAttribute that was visited most recently.
 boolean isSubroutineReturning(int offset)
          Returns whether the subroutine at the given offset is ever returning by means of a regular 'ret' instruction.
 boolean isSubroutineStart(int offset)
          Returns whether the instruction at the given offset is the start of a subroutine in the CodeAttribute that was visited most recently.
 boolean isTarget(int offset)
          Returns whether the instruction at the given offset is the target of any kind in the CodeAttribute that was visited most recently.
 int subroutineEnd(int offset)
          Returns the offset after the subroutine at the given offset, in the CodeAttribute that was visited most recently.
 int subroutineStart(int offset)
          Returns the start offset of the subroutine at the given offset, in the CodeAttribute that was visited most recently.
 int superInitializationOffset()
          Returns the instruction offset at which this initializer is calling the "super" or "this" initializer method, or NONE if it is not an initializer.
 void visitAnyAttribute(Clazz clazz, Attribute attribute)
          Visit any type of attribute.
 void visitAnyConstant(Clazz clazz, Constant constant)
           
 void visitAnySwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SwitchInstruction switchInstruction)
          Visits either type of SwitchInstruction.
 void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
           
 void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
           
 void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
           
 void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)
           
 void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
           
 void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
           
 void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
           
 
Methods inherited from class proguard.classfile.util.SimplifiedVisitor
visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotationDefaultAttribute, visitAnnotationElementValue, visitAnyAnnotationsAttribute, visitAnyClass, visitAnyElementValue, visitAnyInstruction, visitAnyMember, visitAnyMethodrefConstant, visitAnyParameterAnnotationsAttribute, visitAnyRefConstant, visitAnyStackMapFrame, visitAnyVerificationType, visitArrayElementValue, visitClassConstant, visitClassElementValue, visitConstantElementValue, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDoubleConstant, visitDoubleType, visitEnclosingMethodAttribute, visitEnumConstantElementValue, visitExceptionsAttribute, visitFieldrefConstant, visitFloatConstant, visitFloatType, visitFullFrame, visitInnerClassesAttribute, visitIntegerConstant, visitIntegerType, visitInterfaceMethodrefConstant, visitLessZeroFrame, visitLibraryClass, visitLibraryField, visitLibraryMember, visitLibraryMethod, visitLineNumberTableAttribute, visitLocalVariableTableAttribute, visitLocalVariableTypeTableAttribute, visitLongConstant, visitLongType, visitLookUpSwitchInstruction, visitMoreZeroFrame, visitNameAndTypeConstant, visitNullType, visitObjectType, visitProgramClass, visitProgramField, visitProgramMember, visitProgramMethod, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitSameOneFrame, visitSameZeroFrame, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitStackDoubleType, visitStackFloatType, visitStackIntegerType, visitStackLongType, visitStackMapAttribute, visitStackMapTableAttribute, visitStackNullType, visitStackObjectType, visitStackTopType, visitStackUninitializedThisType, visitStackUninitializedType, visitStringConstant, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitTableSwitchInstruction, visitTopType, visitUninitializedThisType, visitUninitializedType, visitUnknownAttribute, visitUtf8Constant, visitVariablesDoubleType, visitVariablesFloatType, visitVariablesIntegerType, visitVariablesLongType, visitVariablesNullType, visitVariablesObjectType, visitVariablesTopType, visitVariablesUninitializedThisType, visitVariablesUninitializedType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface proguard.classfile.attribute.visitor.AttributeVisitor
visitAnnotationDefaultAttribute, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitEnclosingMethodAttribute, visitExceptionsAttribute, visitInnerClassesAttribute, visitLineNumberTableAttribute, visitLocalVariableTableAttribute, visitLocalVariableTypeTableAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitStackMapAttribute, visitStackMapTableAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitUnknownAttribute
 
Methods inherited from interface proguard.classfile.instruction.visitor.InstructionVisitor
visitLookUpSwitchInstruction, visitTableSwitchInstruction
 
Methods inherited from interface proguard.classfile.constant.visitor.ConstantVisitor
visitClassConstant, visitDoubleConstant, visitFieldrefConstant, visitFloatConstant, visitIntegerConstant, visitInterfaceMethodrefConstant, visitLongConstant, visitNameAndTypeConstant, visitStringConstant, visitUtf8Constant
 

Field Detail

NONE

public static final int NONE
See Also:
Constant Field Values

AT_METHOD_ENTRY

public static final int AT_METHOD_ENTRY
See Also:
Constant Field Values
Constructor Detail

BranchTargetFinder

public BranchTargetFinder()
Method Detail

isInstruction

public boolean isInstruction(int offset)
Returns whether there is an instruction at the given offset in the CodeAttribute that was visited most recently.


isTarget

public boolean isTarget(int offset)
Returns whether the instruction at the given offset is the target of any kind in the CodeAttribute that was visited most recently.


isBranchOrigin

public boolean isBranchOrigin(int offset)
Returns whether the instruction at the given offset is the origin of a branch instruction in the CodeAttribute that was visited most recently.


isBranchTarget

public boolean isBranchTarget(int offset)
Returns whether the instruction at the given offset is the target of a branch instruction in the CodeAttribute that was visited most recently.


isAfterBranch

public boolean isAfterBranch(int offset)
Returns whether the instruction at the given offset comes right after a definite branch instruction in the CodeAttribute that was visited most recently.


isExceptionStart

public boolean isExceptionStart(int offset)
Returns whether the instruction at the given offset is the start of an exception try block in the CodeAttribute that was visited most recently.


isExceptionEnd

public boolean isExceptionEnd(int offset)
Returns whether the instruction at the given offset is the end of an exception try block in the CodeAttribute that was visited most recently.


isExceptionHandler

public boolean isExceptionHandler(int offset)
Returns whether the instruction at the given offset is the start of an exception catch block in the CodeAttribute that was visited most recently.


isSubroutineInvocation

public boolean isSubroutineInvocation(int offset)
Returns whether the instruction at the given offset is a subroutine invocation in the CodeAttribute that was visited most recently.


isSubroutineStart

public boolean isSubroutineStart(int offset)
Returns whether the instruction at the given offset is the start of a subroutine in the CodeAttribute that was visited most recently.


isSubroutine

public boolean isSubroutine(int offset)
Returns whether the instruction at the given offset is part of a subroutine in the CodeAttribute that was visited most recently.


isSubroutineReturning

public boolean isSubroutineReturning(int offset)
Returns whether the subroutine at the given offset is ever returning by means of a regular 'ret' instruction.


subroutineStart

public int subroutineStart(int offset)
Returns the start offset of the subroutine at the given offset, in the CodeAttribute that was visited most recently.


subroutineEnd

public int subroutineEnd(int offset)
Returns the offset after the subroutine at the given offset, in the CodeAttribute that was visited most recently.


isNew

public boolean isNew(int offset)
Returns whether the instruction at the given offset is a 'new' instruction, in the CodeAttribute that was visited most recently.


initializationOffset

public int initializationOffset(int offset)
Returns the instruction offset at which the object instance that is created at the given 'new' instruction offset is initialized, or NONE if it is not being created.


isInitializer

public boolean isInitializer()
Returns whether the method is an instance initializer, in the CodeAttribute that was visited most recently.


superInitializationOffset

public int superInitializationOffset()
Returns the instruction offset at which this initializer is calling the "super" or "this" initializer method, or NONE if it is not an initializer.


isInitializer

public boolean isInitializer(int offset)
Returns whether the instruction at the given offset is the special invocation of an instance initializer, in the CodeAttribute that was visited most recently.


creationOffset

public int creationOffset(int offset)
Returns the offset of the 'new' instruction that corresponds to the invocation of the instance initializer at the given offset, or AT_METHOD_ENTRY if the invocation is calling the "super" or "this" initializer method, , or NONE if it is not a 'new' instruction.


visitAnyAttribute

public void visitAnyAttribute(Clazz clazz,
                              Attribute attribute)
Description copied from class: SimplifiedVisitor
Visit any type of attribute.

Overrides:
visitAnyAttribute in class SimplifiedVisitor

visitCodeAttribute

public void visitCodeAttribute(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute)
Specified by:
visitCodeAttribute in interface AttributeVisitor
Overrides:
visitCodeAttribute in class SimplifiedVisitor

visitSimpleInstruction

public void visitSimpleInstruction(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   int offset,
                                   SimpleInstruction simpleInstruction)
Specified by:
visitSimpleInstruction in interface InstructionVisitor
Overrides:
visitSimpleInstruction in class SimplifiedVisitor

visitConstantInstruction

public void visitConstantInstruction(Clazz clazz,
                                     Method method,
                                     CodeAttribute codeAttribute,
                                     int offset,
                                     ConstantInstruction constantInstruction)
Specified by:
visitConstantInstruction in interface InstructionVisitor
Overrides:
visitConstantInstruction in class SimplifiedVisitor

visitVariableInstruction

public void visitVariableInstruction(Clazz clazz,
                                     Method method,
                                     CodeAttribute codeAttribute,
                                     int offset,
                                     VariableInstruction variableInstruction)
Specified by:
visitVariableInstruction in interface InstructionVisitor
Overrides:
visitVariableInstruction in class SimplifiedVisitor

visitBranchInstruction

public void visitBranchInstruction(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   int offset,
                                   BranchInstruction branchInstruction)
Specified by:
visitBranchInstruction in interface InstructionVisitor
Overrides:
visitBranchInstruction in class SimplifiedVisitor

visitAnySwitchInstruction

public void visitAnySwitchInstruction(Clazz clazz,
                                      Method method,
                                      CodeAttribute codeAttribute,
                                      int offset,
                                      SwitchInstruction switchInstruction)
Description copied from class: SimplifiedVisitor
Visits either type of SwitchInstruction.

Overrides:
visitAnySwitchInstruction in class SimplifiedVisitor

visitAnyConstant

public void visitAnyConstant(Clazz clazz,
                             Constant constant)
Overrides:
visitAnyConstant in class SimplifiedVisitor

visitMethodrefConstant

public void visitMethodrefConstant(Clazz clazz,
                                   MethodrefConstant methodrefConstant)
Specified by:
visitMethodrefConstant in interface ConstantVisitor
Overrides:
visitMethodrefConstant in class SimplifiedVisitor

visitExceptionInfo

public void visitExceptionInfo(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute,
                               ExceptionInfo exceptionInfo)
Specified by:
visitExceptionInfo in interface ExceptionInfoVisitor