Class ExecutingInvocationUnit
- All Implemented Interfaces:
ConstantVisitor,MemberVisitor,ParameterVisitor,InvocationUnit
InvocationUnit is capable of executing the invoked methods with particular values as
parameters.
If a method has a return value, this value is determined and supplied as a particular Value. Methods that operate on an instance are able to modify the calling instance. For such
methods, references in the stack and variables to that instance are replaced with the modified
one. This also applies to constructors.
This class is responsible for creating the final particular Values for methods that
were handled without errors and creating fallback values in case the method could not be handled.
It also performs the action of replacing references of instances that changed in the stack and
variables if needed. This is however limited as we only update the instance if it was modified
and ignores all other parameters which might have changed too.
An ExecutingInvocationUnit delegates the acquisition of method results and certain
other decisions (e.g. whether replacing references in the stack and variables is needed) to its
Executors. Per default, an instance of this class will have access to a StringReflectionExecutor that handles methods of String, StringBuilder and
StringBuffer. The ExecutingInvocationUnit.Builder, allows for disabling the default StringReflectionExecutor and adding other Executors.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class proguard.evaluation.BasicInvocationUnit
valueFactory -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExecutingInvocationUnit(@NotNull ClassPool programClassPool, @NotNull ClassPool libraryClassPool, ValueFactory valueFactory, boolean enableSameInstanceIdApproximation, boolean allowNonFinalConstants, List<Executor> registeredExecutors) Creates anExecutingInvocationUnit. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanExecute(@NotNull MethodSignature signature) Returns whether the invocation unit is able to handle the given method.executeMethod(ConcreteCall call, Value... parameters) Execute the method given by aConcreteCall.executeMethod(Executor executor, MethodExecutionInfo methodInfo) Executes a method using a givenExecutor.getFieldValue(Clazz clazz, FieldrefConstant fieldrefConstant, String type) Returns the value of the specified field.getMethodReturnValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, String returnType) Returns the return value of the specified method.booleanmethodMayHaveSideEffects(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, String returnType) Returns true if the method itself can modify the stack/variables and therefore needs to be executed even if it returns void.voidsetMethodParameterValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, int parameterIndex, Value value) Sets the value of the specified method parameter.booleansupportsAnyMethodOf(@NotNull String className) Checks whether any method of the given class is supported by the executors.booleansupportsAnyMethodOf(@NotNull Clazz clazz) Checks whether any method of the given class is supported by the executors.voidvisitAnyMethodrefConstant(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant) Visits any RefConstant instance.Methods inherited from class proguard.evaluation.BasicInvocationUnit
getExceptionValue, getFieldClassValue, getMethodParameterValue, getMethodReturnValue, setFieldClassValue, setFieldValue, setMethodReturnValue, visitLibraryField, visitLibraryMethod, visitProgramField, visitProgramMethodMethods inherited from class proguard.evaluation.SimplifiedInvocationUnit
enterExceptionHandler, enterMethod, exitMethod, invokeMember, visitFieldrefConstant, visitInvokeDynamicConstant, visitParameterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface proguard.classfile.constant.visitor.ConstantVisitor
visitAnyConstant, visitAnyRefConstant, visitClassConstant, visitDoubleConstant, visitDynamicConstant, visitFloatConstant, visitIntegerConstant, visitInterfaceMethodrefConstant, visitLongConstant, visitMethodHandleConstant, visitMethodrefConstant, visitMethodTypeConstant, visitModuleConstant, visitNameAndTypeConstant, visitPackageConstant, visitPrimitiveArrayConstant, visitStringConstant, visitUtf8ConstantMethods inherited from interface proguard.evaluation.InvocationUnit
enterExceptionHandler, enterMethod, exitMethod, invokeMemberMethods inherited from interface proguard.classfile.visitor.MemberVisitor
visitAnyMember, visitLibraryMember, visitProgramMember
-
Constructor Details
-
ExecutingInvocationUnit
protected ExecutingInvocationUnit(@NotNull @NotNull ClassPool programClassPool, @NotNull @NotNull ClassPool libraryClassPool, ValueFactory valueFactory, boolean enableSameInstanceIdApproximation, boolean allowNonFinalConstants, List<Executor> registeredExecutors) Creates anExecutingInvocationUnit.
-
-
Method Details
-
visitAnyMethodrefConstant
Description copied from interface:ConstantVisitorVisits any RefConstant instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyMethodrefConstantin interfaceConstantVisitor- Overrides:
visitAnyMethodrefConstantin classSimplifiedInvocationUnit
-
setMethodParameterValue
public void setMethodParameterValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, int parameterIndex, Value value) Description copied from class:SimplifiedInvocationUnitSets the value of the specified method parameter.- Overrides:
setMethodParameterValuein classBasicInvocationUnit
-
methodMayHaveSideEffects
public boolean methodMayHaveSideEffects(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, String returnType) Description copied from class:SimplifiedInvocationUnitReturns true if the method itself can modify the stack/variables and therefore needs to be executed even if it returns void.- Overrides:
methodMayHaveSideEffectsin classSimplifiedInvocationUnit
-
getMethodReturnValue
public Value getMethodReturnValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, String returnType) Description copied from class:SimplifiedInvocationUnitReturns the return value of the specified method.- Overrides:
getMethodReturnValuein classBasicInvocationUnit
-
executeMethod
Execute the method given by aConcreteCall. SeeexecuteMethod(Executor, MethodExecutionInfo)- Parameters:
call- The concrete call.parameters- The calling parameters.- Returns:
- The method result value.
-
executeMethod
Executes a method using a givenExecutor. Replace references of the instance in variables and stack if necessary. The return value represents the result of the executed method.- Parameters:
executor- TheExecutorwhich handles this method call.methodInfo- Information about the method to execute.- Returns:
- The method result value.
-
canExecute
Returns whether the invocation unit is able to handle the given method.- Parameters:
signature- The method signature of the method being tested- Returns:
- true if the method can be executed.
-
supportsAnyMethodOf
Checks whether any method of the given class is supported by the executors.- Parameters:
clazz- The class to check- Returns:
- true if any method of the given class is supported by the executor
-
supportsAnyMethodOf
Checks whether any method of the given class is supported by the executors.- Parameters:
className- The class name to check- Returns:
- true if any method of the given class is supported by the executor
-
getFieldValue
Description copied from class:SimplifiedInvocationUnitReturns the value of the specified field.- Overrides:
getFieldValuein classBasicInvocationUnit
-