use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class BigInteger_Ctor method executeFunction.
@Override
public Object executeFunction() {
String conc_string = (String) this.getConcArgument(0);
ReferenceConstant str_ref = (ReferenceConstant) this.getSymbArgument(0);
StringValue symb_string = this.env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_string, str_ref, conc_string);
if (symb_string.containsSymbolicVariable()) {
ReferenceConstant symb_big_integer = (ReferenceConstant) env.topFrame().operandStack.peekRef();
BigInteger bigInteger = new BigInteger(conc_string);
long concVal = bigInteger.longValue();
StringToIntegerCast big_integer_value = new StringToIntegerCast(symb_string, concVal);
env.heap.putField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, null, /* conc_big_integer */
symb_big_integer, big_integer_value);
}
// return void
return null;
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class CallVM method METHOD_BEGIN.
/**
* Pop operands off caller stack
*
* Method methName is about to start execution.
*
* At this point we have either already seen (observed InvokeXXX) or missed
* this invocation of the methName method.
*
* We miss any of the following: - invoke <clinit> (as there are no such
* statements) - invoke <init> (as we do not add instrumentation code for
* these)
*
* User code cannot call the <clinit>() method directly. Instead, the JVM
* invokes a class's initializer implicitly, upon the first use of the
* class.
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html
* #32316
* http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc
* .html#19075
* http://java.sun.com/docs/books/jvms/second_edition/html/Overview
* .doc.html#16262
*/
@Override
public void METHOD_BEGIN(int access, String className, String methName, String methDesc) {
if (conf.CLINIT.equals(methName)) {
CLINIT_BEGIN(className);
return;
}
if (env.topFrame().weInvokedInstrumentedCode() == false) {
// An uninstrumented caller has called instrumented code
// This is problemtatic
}
prepareStackIfNeeded(className, methName, methDesc);
/* Begin of a method or constructor */
// guy who (transitively)
final Frame callerFrame = env.topFrame();
// called us
Frame frame;
boolean calleeNeedsThis = false;
if (conf.INIT.equals(methName)) {
Constructor<?> constructor = resolveConstructorOverloading(className, methDesc);
int maxLocals = conf.MAX_LOCALS_DEFAULT;
MemberInfo memberInfo = memberInfos.get(constructor);
if (memberInfo != null)
maxLocals = memberInfo.maxLocals;
frame = new ConstructorFrame(constructor, maxLocals);
calleeNeedsThis = true;
if (callerFrame.weInvokedInstrumentedCode() == false) {
/**
* Since this is a constructor called from un-instrumented code,
* we need to "simulate" the missing NEW. This means 1) create a
* new object reference 2) populate the localstable with the new
* reference
*/
Class<?> clazz = classLoader.getClassForName(className);
Type objectType = Type.getType(clazz);
ReferenceConstant newObject = this.env.heap.buildNewReferenceConstant(objectType);
frame.localsTable.setRefLocal(0, newObject);
}
} else {
Method method = resolveMethodOverloading(className, methName, methDesc);
int maxLocals = conf.MAX_LOCALS_DEFAULT;
MemberInfo memberInfo = memberInfos.get(method);
if (memberInfo != null)
maxLocals = memberInfo.maxLocals;
frame = new MethodFrame(method, maxLocals);
calleeNeedsThis = !Modifier.isStatic(method.getModifiers());
}
/*
* If our caller called uninstrumented code then we should not ruin his
* operand stack! Instead, METHOD_BEGIN_PARAM will supply the concrete
* parameter values and create corresponding symbolic constants.
*/
if (callerFrame.weInvokedInstrumentedCode() == false) {
env.pushFrame(frame);
return;
}
/*
* Our caller directly called us. We should take our parameters from his
* stack.
*/
Class<?>[] paramTypes = getArgumentClasses(methDesc);
final Deque<Operand> params = new LinkedList<Operand>();
Iterator<Operand> it = env.topFrame().operandStack.iterator();
for (int i = paramTypes.length - 1; i >= 0; i--) {
// read parameters from caller operand srack
Operand param = it.next();
params.push(param);
}
int index = 0;
for (Operand param : params) {
frame.localsTable.setOperand(index + (calleeNeedsThis ? 1 : 0), param);
if (param instanceof SingleWordOperand)
index += 1;
else if (param instanceof DoubleWordOperand)
index += 2;
else {
throw new IllegalStateException("Unknown operand type " + param.getClass().getName());
}
}
if (calleeNeedsThis) {
// "this" instance
Operand param = it.next();
ReferenceOperand refOperand = (ReferenceOperand) param;
frame.localsTable.setRefLocal(0, refOperand.getReference());
}
env.pushFrame(frame);
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class ExpressionFactory method buildNewNullExpression.
public static ReferenceConstant buildNewNullExpression() {
final Type objectType = Type.getType(Object.class);
final ReferenceConstant referenceConstant = new ReferenceConstant(objectType, 0);
referenceConstant.initializeReference(null);
return referenceConstant;
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class StringBuffer_ToString method executeFunction.
@Override
public Object executeFunction() {
ReferenceConstant symb_str_buffer = this.getSymbReceiver();
StringBuffer conc_str_buffer = (StringBuffer) this.getConcReceiver();
// retrieve symbolic value from heap
String conc_value = conc_str_buffer.toString();
StringValue symb_value = env.heap.getField(Types.JAVA_LANG_STRING_BUFFER, SymbolicHeap.$STRING_BUFFER_CONTENTS, conc_str_buffer, symb_str_buffer, conc_value);
String conc_ret_val = (String) this.getConcRetVal();
ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, symb_value);
// return symbolic value
return symb_ret_val;
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class StringBuilder_Append method executeFunction.
@Override
public final Object executeFunction() {
// string builder
StringBuilder conc_str_builder = (StringBuilder) this.getConcReceiver();
ReferenceConstant symb_str_builder = (ReferenceConstant) this.getSymbReceiver();
// return value
StringBuilder res = (StringBuilder) this.getConcRetVal();
ReferenceConstant symb_res = (ReferenceConstant) this.getSymbRetVal();
StringValue leftExpr = this.env.heap.getField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, conc_str_builder, symb_str_builder, conc_str_builder_to_string_pre);
// append string expression
StringValue newStrExpr = appendExpression(leftExpr, res);
// store to symbolic heap
env.heap.putField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, conc_str_builder, symb_res, newStrExpr);
return symb_res;
}
Aggregations