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
ThisAttributeVisitor
performs partial evaluation on the code attributes that it visits.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PartialEvaluator.Builder
static class
PartialEvaluator.InstructionBlock
This 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 int
AT_CATCH_ENTRY
static int
AT_METHOD_ENTRY
static boolean
ENABLE_NEW_EXCEPTIONS
Enables new exceptions to be thrown during evaluation.static int
NONE
-
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 InstructionOffsetValue
branchOrigins(int instructionOffset)
Returns the instruction offsets that branch to the given instruction offset.InstructionOffsetValue
branchTargets(int instructionOffset)
Returns the instruction offsets to which the given instruction offset branches.TracedStack
getStackAfter(int instructionOffset)
Returns the stack after execution of the instruction at the given offset.TracedStack
getStackBefore(int instructionOffset)
Returns the stack before execution of the instruction at the given offset.TracedVariables
getVariablesAfter(int instructionOffset)
Returns the variables after execution of the instruction at the given offset.TracedVariables
getVariablesBefore(int instructionOffset)
Returns the variables before execution of the instruction at the given offset.boolean
isBranchOrExceptionTarget(int instructionOffset)
Returns whether the instruction at the given offset is the target of a branch instruction or an exception.boolean
isBranchOrigin(int instructionOffset)
Returns whether the instruction at the given offset is the origin of a branch instruction.boolean
isBranchTarget(int instructionOffset)
Returns whether the instruction at the given offset is the target of a branch instruction.boolean
isCreation(int offset)
Returns whether the instruction at the given offset creates a new, uninitialized instance.boolean
isExceptionHandler(int instructionOffset)
Returns whether the instruction at the given offset is the start of an exception handler.boolean
isInitializer(int offset)
Returns whether the instruction at the given offset is the special invocation of an instance initializer.boolean
isInstruction(int instructionOffset)
Returns whether there is an instruction at the given offset.boolean
isSubroutine(int instructionOffset)
Returns whether the instruction at the given offset is part of a subroutine.boolean
isSubroutineInvocation(int instructionOffset)
Returns whether the instruction at the given offset is a subroutine invocation.boolean
isSubroutineReturning(int instructionOffset)
Returns whether the subroutine at the given offset is ever returning by means of a regular 'ret' instruction.boolean
isSubroutineStart(int instructionOffset)
Returns whether the instruction at the given offset is the start of a subroutine.boolean
isTarget(int instructionOffset)
Returns whether the instruction at the given offset is the target of any kind.boolean
isTraced(int instructionOffset)
Returns whether the instruction at the given offset has ever been executed during the partial evaluation.boolean
isTraced(int startOffset, int endOffset)
Returns whether a block of instructions is ever used.PartialEvaluator
stopAnalysisAfterNEvaluations(int stopAnalysisAfterNEvaluations)
It the analysis visits an instruction this many times (this can happen e.g.int
subroutineEnd(int instructionOffset)
Returns the offset after the subroutine that starts at the given offset.InstructionVisitor
tracedInstructionFilter(boolean traced, InstructionVisitor instructionVisitor)
Returns a filtering version of the given instruction visitor that only visits traced or untraced instructions.InstructionVisitor
tracedInstructionFilter(InstructionVisitor instructionVisitor)
Returns a filtering version of the given instruction visitor that only visits traced instructions.void
visitAnyAttribute(Clazz clazz, Attribute attribute)
Visits any Attribute instance.void
visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
void
visitCodeAttribute0(Clazz clazz, Method method, CodeAttribute codeAttribute)
void
visitExceptionInfo(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:AttributeVisitor
Visits any Attribute instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyAttribute
in interfaceAttributeVisitor
-
visitCodeAttribute
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- Specified by:
visitCodeAttribute
in 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:
visitExceptionInfo
in 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.
-
-