public class ExecutingInvocationUnit extends BasicInvocationUnit
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 Value
s 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
Executor
s. 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 Executor
s.
Modifier and Type | Class and Description |
---|---|
static class |
ExecutingInvocationUnit.Builder
Builds an
ExecutingInvocationUnit . |
valueFactory
Modifier | Constructor and Description |
---|---|
|
ExecutingInvocationUnit(ValueFactory valueFactory)
Deprecated.
|
protected |
ExecutingInvocationUnit(ValueFactory valueFactory,
boolean enableSameInstanceIdApproximation,
java.util.List<Executor> registeredExecutors)
Creates an
ExecutingInvocationUnit . |
Modifier and Type | Method and Description |
---|---|
Value |
executeMethod(ConcreteCall call,
Value... parameters)
Execute the method given by a
ConcreteCall . |
Value |
executeMethod(Executor executor,
MethodExecutionInfo methodInfo,
Value... parameters)
Executes a method using a given
Executor . |
Value |
getFieldValue(Clazz clazz,
FieldrefConstant fieldrefConstant,
java.lang.String type)
Returns the value of the specified field.
|
Value |
getMethodReturnValue(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant,
java.lang.String returnType)
Returns the return value of the specified method.
|
boolean |
isSupportedMethodCall(MethodSignature methodSignature) |
boolean |
isSupportedMethodCall(java.lang.String internalClassName,
java.lang.String methodName)
Return whether the invocation unit is expected to handle the method call based on the class
name and the method name.
|
boolean |
methodMayHaveSideEffects(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant,
java.lang.String returnType)
Returns true if the method itself can modify the stack/variables and therefore needs to be
executed even if it returns void.
|
boolean |
returnsOwnInstance(Clazz clazz,
Method method,
Value instance)
Determines whether the stack/variables need to be updated with the changed instance.
|
void |
setMethodParameterValue(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant,
int parameterIndex,
Value value)
Sets the value of the specified method parameter.
|
void |
visitAnyMethodrefConstant(Clazz clazz,
AnyMethodrefConstant anyMethodrefConstant)
Visits any RefConstant instance.
|
getExceptionValue, getFieldClassValue, getMethodParameterValue, getMethodReturnValue, setFieldClassValue, setFieldValue, setMethodReturnValue, visitLibraryField, visitLibraryMethod, visitProgramField, visitProgramMethod
enterExceptionHandler, enterMethod, exitMethod, invokeMember, visitFieldrefConstant, visitInvokeDynamicConstant, visitParameter
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
enterExceptionHandler, enterMethod, exitMethod, invokeMember
visitAnyMember, visitLibraryMember, visitProgramMember
visitAnyConstant, visitAnyRefConstant, visitClassConstant, visitDoubleConstant, visitDynamicConstant, visitFloatConstant, visitIntegerConstant, visitInterfaceMethodrefConstant, visitLongConstant, visitMethodHandleConstant, visitMethodrefConstant, visitMethodTypeConstant, visitModuleConstant, visitNameAndTypeConstant, visitPackageConstant, visitPrimitiveArrayConstant, visitStringConstant, visitUtf8Constant
protected ExecutingInvocationUnit(ValueFactory valueFactory, boolean enableSameInstanceIdApproximation, java.util.List<Executor> registeredExecutors)
ExecutingInvocationUnit
.@Deprecated public ExecutingInvocationUnit(ValueFactory valueFactory)
ExecutingInvocationUnit.Builder
.public void visitAnyMethodrefConstant(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant)
ConstantVisitor
visitAnyMethodrefConstant
in interface ConstantVisitor
visitAnyMethodrefConstant
in class SimplifiedInvocationUnit
public void setMethodParameterValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, int parameterIndex, Value value)
SimplifiedInvocationUnit
setMethodParameterValue
in class BasicInvocationUnit
public boolean methodMayHaveSideEffects(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, java.lang.String returnType)
SimplifiedInvocationUnit
methodMayHaveSideEffects
in class SimplifiedInvocationUnit
public Value getMethodReturnValue(Clazz clazz, AnyMethodrefConstant anyMethodrefConstant, java.lang.String returnType)
SimplifiedInvocationUnit
getMethodReturnValue
in class BasicInvocationUnit
public Value executeMethod(ConcreteCall call, Value... parameters)
ConcreteCall
. See executeMethod(Executor, MethodExecutionInfo, Value...)
call
- The concrete call.parameters
- The calling parameters.public Value executeMethod(Executor executor, MethodExecutionInfo methodInfo, Value... parameters)
Executor
. Replace references of the instance in
variables and stack if necessary. The return value represents the result of the executed
method.executor
- The Executor
which handles this method call.methodInfo
- Information about the method to execute.parameters
- The calling parameters.public boolean isSupportedMethodCall(java.lang.String internalClassName, java.lang.String methodName)
internalClassName
- The class name for the method.methodName
- The name of the method.public boolean isSupportedMethodCall(MethodSignature methodSignature)
public boolean returnsOwnInstance(Clazz clazz, Method method, Value instance)
clazz
- The class of the method.method
- The method.instance
- The instance of the method call.public Value getFieldValue(Clazz clazz, FieldrefConstant fieldrefConstant, java.lang.String type)
SimplifiedInvocationUnit
getFieldValue
in class BasicInvocationUnit