Package proguard.evaluation
Class PartialEvaluator
- java.lang.Object
-
- proguard.evaluation.PartialEvaluator
-
- All Implemented Interfaces:
AttributeVisitor,ExceptionInfoVisitor
public class PartialEvaluator extends java.lang.Object implements AttributeVisitor, ExceptionInfoVisitor
ThisAttributeVisitorperforms partial evaluation on the code attributes that it visits.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPartialEvaluator.Builderstatic classPartialEvaluator.InstructionBlockThis class represents an instruction block that has to be executed, starting with a given state at a given instruction offset.
-
Field Summary
Fields Modifier and Type Field Description static intAT_CATCH_ENTRYstatic intAT_METHOD_ENTRYstatic booleanENABLE_NEW_EXCEPTIONSEnables new exceptions to be thrown during evaluation.static intNONE
-
Constructor Summary
Constructors Constructor Description PartialEvaluator()Creates a simple PartialEvaluator.PartialEvaluator(ValueFactory valueFactory)Creates a new PartialEvaluator.PartialEvaluator(ValueFactory valueFactory, InvocationUnit invocationUnit, boolean evaluateAllCode)Creates a new PartialEvaluator.PartialEvaluator(ValueFactory valueFactory, InvocationUnit invocationUnit, boolean evaluateAllCode, InstructionVisitor extraInstructionVisitor)Creates a new PartialEvaluator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InstructionOffsetValuebranchOrigins(int instructionOffset)Returns the instruction offsets that branch to the given instruction offset.InstructionOffsetValuebranchTargets(int instructionOffset)Returns the instruction offsets to which the given instruction offset branches.TracedStackgetStackAfter(int instructionOffset)Returns the stack after execution of the instruction at the given offset.TracedStackgetStackBefore(int instructionOffset)Returns the stack before execution of the instruction at the given offset.TracedVariablesgetVariablesAfter(int instructionOffset)Returns the variables after execution of the instruction at the given offset.TracedVariablesgetVariablesBefore(int instructionOffset)Returns the variables before execution of the instruction at the given offset.booleanisBranchOrExceptionTarget(int instructionOffset)Returns whether the instruction at the given offset is the target of a branch instruction or an exception.booleanisBranchOrigin(int instructionOffset)Returns whether the instruction at the given offset is the origin of a branch instruction.booleanisBranchTarget(int instructionOffset)Returns whether the instruction at the given offset is the target of a branch instruction.booleanisCreation(int offset)Returns whether the instruction at the given offset creates a new, uninitialized instance.booleanisExceptionHandler(int instructionOffset)Returns whether the instruction at the given offset is the start of an exception handler.booleanisInitializer(int offset)Returns whether the instruction at the given offset is the special invocation of an instance initializer.booleanisInstruction(int instructionOffset)Returns whether there is an instruction at the given offset.booleanisSubroutine(int instructionOffset)Returns whether the instruction at the given offset is part of a subroutine.booleanisSubroutineInvocation(int instructionOffset)Returns whether the instruction at the given offset is a subroutine invocation.booleanisSubroutineReturning(int instructionOffset)Returns whether the subroutine at the given offset is ever returning by means of a regular 'ret' instruction.booleanisSubroutineStart(int instructionOffset)Returns whether the instruction at the given offset is the start of a subroutine.booleanisTarget(int instructionOffset)Returns whether the instruction at the given offset is the target of any kind.booleanisTraced(int instructionOffset)Returns whether the instruction at the given offset has ever been executed during the partial evaluation.booleanisTraced(int startOffset, int endOffset)Returns whether a block of instructions is ever used.PartialEvaluatorstopAnalysisAfterNEvaluations(int stopAnalysisAfterNEvaluations)It the analysis visits an instruction this many times (this can happen e.g.intsubroutineEnd(int instructionOffset)Returns the offset after the subroutine that starts at the given offset.InstructionVisitortracedInstructionFilter(boolean traced, InstructionVisitor instructionVisitor)Returns a filtering version of the given instruction visitor that only visits traced or untraced instructions.InstructionVisitortracedInstructionFilter(InstructionVisitor instructionVisitor)Returns a filtering version of the given instruction visitor that only visits traced instructions.voidvisitAnyAttribute(Clazz clazz, Attribute attribute)Visits any Attribute instance.voidvisitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)voidvisitCodeAttribute0(Clazz clazz, Method method, CodeAttribute codeAttribute)voidvisitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)-
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, visitAnyAnnotationsAttribute, visitAnyParameterAnnotationsAttribute, visitAnyTypeAnnotationsAttribute, visitBootstrapMethodsAttribute, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitEnclosingMethodAttribute, visitExceptionsAttribute, visitInnerClassesAttribute, visitLineNumberTableAttribute, visitLocalVariableTableAttribute, visitLocalVariableTypeTableAttribute, visitMethodParametersAttribute, visitModuleAttribute, visitModuleMainClassAttribute, visitModulePackagesAttribute, visitNestHostAttribute, visitNestMembersAttribute, visitPermittedSubclassesAttribute, visitRecordAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDebugExtensionAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitStackMapAttribute, visitStackMapTableAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitUnknownAttribute
-
-
-
-
Field Detail
-
ENABLE_NEW_EXCEPTIONS
public static boolean ENABLE_NEW_EXCEPTIONS
Enables new exceptions to be thrown during evaluation. These are exceptions that are not thrown by the original ProGuard code. This is a temporary flag to allow the new exceptions to be tested. TODO: Remove this flag when the new exceptions are stable and will not break any dependent code.
-
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
-
AT_CATCH_ENTRY
public static final int AT_CATCH_ENTRY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PartialEvaluator
public PartialEvaluator()
Creates a simple PartialEvaluator.
-
PartialEvaluator
public PartialEvaluator(ValueFactory valueFactory)
Creates a new PartialEvaluator.- Parameters:
valueFactory- the value factory that will create all values during evaluation.
-
PartialEvaluator
public PartialEvaluator(ValueFactory valueFactory, InvocationUnit invocationUnit, boolean evaluateAllCode)
Creates a new PartialEvaluator.- Parameters:
valueFactory- the value factory that will create all values during the evaluation.invocationUnit- the invocation unit that will handle all communication with other fields and methods.evaluateAllCode- a flag that specifies whether all casts, branch targets, and exception handlers should be evaluated, even if they are unnecessary or unreachable.
-
PartialEvaluator
public PartialEvaluator(ValueFactory valueFactory, InvocationUnit invocationUnit, boolean evaluateAllCode, InstructionVisitor extraInstructionVisitor)
Creates a new PartialEvaluator.- Parameters:
valueFactory- the value factory that will create all values during the evaluation.invocationUnit- the invocation unit that will handle all communication with other fields and methods.evaluateAllCode- a flag that specifies whether all branch targets and exception handlers should be evaluated, even if they are unreachable.extraInstructionVisitor- an optional extra visitor for all instructions right before they are executed.
-
-
Method Detail
-
visitAnyAttribute
public void visitAnyAttribute(Clazz clazz, Attribute attribute)
Description copied from interface:AttributeVisitorVisits any Attribute instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyAttributein interfaceAttributeVisitor
-
visitCodeAttribute
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- Specified by:
visitCodeAttributein interfaceAttributeVisitor
-
visitCodeAttribute0
public void visitCodeAttribute0(Clazz clazz, Method method, CodeAttribute codeAttribute)
-
isTraced
public boolean isTraced(int startOffset, int endOffset)Returns whether a block of instructions is ever used.
-
isTraced
public boolean isTraced(int instructionOffset)
Returns whether the instruction at the given offset has ever been executed during the partial evaluation.
-
isInstruction
public boolean isInstruction(int instructionOffset)
Returns whether there is an instruction at the given offset.
-
isTarget
public boolean isTarget(int instructionOffset)
Returns whether the instruction at the given offset is the target of any kind.
-
isBranchOrigin
public boolean isBranchOrigin(int instructionOffset)
Returns whether the instruction at the given offset is the origin of a branch instruction.
-
isBranchTarget
public boolean isBranchTarget(int instructionOffset)
Returns whether the instruction at the given offset is the target of a branch instruction.
-
isBranchOrExceptionTarget
public boolean isBranchOrExceptionTarget(int instructionOffset)
Returns whether the instruction at the given offset is the target of a branch instruction or an exception.
-
isExceptionHandler
public boolean isExceptionHandler(int instructionOffset)
Returns whether the instruction at the given offset is the start of an exception handler.
-
isSubroutineStart
public boolean isSubroutineStart(int instructionOffset)
Returns whether the instruction at the given offset is the start of a subroutine.
-
isSubroutineInvocation
public boolean isSubroutineInvocation(int instructionOffset)
Returns whether the instruction at the given offset is a subroutine invocation.
-
isSubroutine
public boolean isSubroutine(int instructionOffset)
Returns whether the instruction at the given offset is part of a subroutine.
-
isSubroutineReturning
public boolean isSubroutineReturning(int instructionOffset)
Returns whether the subroutine at the given offset is ever returning by means of a regular 'ret' instruction.
-
subroutineEnd
public int subroutineEnd(int instructionOffset)
Returns the offset after the subroutine that starts at the given offset.
-
isCreation
public boolean isCreation(int offset)
Returns whether the instruction at the given offset creates a new, uninitialized instance.
-
isInitializer
public boolean isInitializer(int offset)
Returns whether the instruction at the given offset is the special invocation of an instance initializer.
-
getVariablesBefore
public TracedVariables getVariablesBefore(int instructionOffset)
Returns the variables before execution of the instruction at the given offset.
-
getVariablesAfter
public TracedVariables getVariablesAfter(int instructionOffset)
Returns the variables after execution of the instruction at the given offset.
-
getStackBefore
public TracedStack getStackBefore(int instructionOffset)
Returns the stack before execution of the instruction at the given offset.
-
getStackAfter
public TracedStack getStackAfter(int instructionOffset)
Returns the stack after execution of the instruction at the given offset.
-
branchOrigins
public InstructionOffsetValue branchOrigins(int instructionOffset)
Returns the instruction offsets that branch to the given instruction offset.
-
branchTargets
public InstructionOffsetValue branchTargets(int instructionOffset)
Returns the instruction offsets to which the given instruction offset branches.
-
tracedInstructionFilter
public InstructionVisitor tracedInstructionFilter(InstructionVisitor instructionVisitor)
Returns a filtering version of the given instruction visitor that only visits traced instructions.
-
tracedInstructionFilter
public InstructionVisitor tracedInstructionFilter(boolean traced, InstructionVisitor instructionVisitor)
Returns a filtering version of the given instruction visitor that only visits traced or untraced instructions.
-
visitExceptionInfo
public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)
- Specified by:
visitExceptionInfoin interfaceExceptionInfoVisitor
-
stopAnalysisAfterNEvaluations
public PartialEvaluator stopAnalysisAfterNEvaluations(int stopAnalysisAfterNEvaluations)
It the analysis visits an instruction this many times (this can happen e.g. for big switches), the analysis of this method is forcibly stopped and a ExcessiveComplexityException is thrown.
-
-