use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class HeapVM method PUTFIELD.
/**
* Store a value in an instance field.
*
* Before actually retrieving the value, the JVM will check if the instance
* is null. If the receiver instance is null, the JVM will throw a null
* pointer exception.
*/
@Override
public void PUTFIELD(Object conc_receiver, String className, String fieldName, String desc) {
/**
* Pop symbolic heap
*/
Operand value_operand = env.topFrame().operandStack.popOperand();
ReferenceExpression receiver_ref = env.topFrame().operandStack.popRef();
/* check reference initialization */
env.heap.initializeReference(conc_receiver, receiver_ref);
/**
* Prepare classes
*/
Field field = resolveField(classLoader.getClassForName(className), fieldName);
env.ensurePrepared(field.getDeclaringClass());
/* null-check */
if (nullReferenceViolation(receiver_ref, conc_receiver)) {
return;
}
ReferenceExpression symb_receiver = (ReferenceExpression) receiver_ref;
/**
* Compute new symbolic state
*/
Expression<?> symb_value = null;
if (value_operand instanceof IntegerOperand) {
IntegerOperand intOp = (IntegerOperand) value_operand;
symb_value = intOp.getIntegerExpression();
} else if (value_operand instanceof RealOperand) {
RealOperand realOp = (RealOperand) value_operand;
symb_value = realOp.getRealExpression();
} else if (value_operand instanceof ReferenceOperand) {
// NonNullReference are not stored in the symbolic heap fields
return;
}
env.heap.putField(className, fieldName, conc_receiver, symb_receiver, symb_value);
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class HeapVM method BASTORE.
@Override
public void BASTORE(Object conc_array, int conc_index) {
// pop arguments
IntegerValue symb_value = env.topFrame().operandStack.popBv32();
IntegerValue symb_index = env.topFrame().operandStack.popBv32();
ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
/* check reference initialization */
env.heap.initializeReference(conc_array, array_ref);
/* null-check */
if (nullReferenceViolation(array_ref, conc_array)) {
return;
}
/* negative index */
if (negativeIndexViolation(conc_index, symb_index)) {
return;
}
/* out of bound index */
ReferenceExpression symb_array = array_ref;
int conc_array_length = Array.getLength(conc_array);
IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
return;
env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class HeapVM method SASTORE.
@Override
public void SASTORE(Object conc_array, int conc_index) {
// get symbolic arguments
IntegerValue symb_value = env.topFrame().operandStack.popBv32();
IntegerValue symb_index = env.topFrame().operandStack.popBv32();
ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
/* check reference initialization */
env.heap.initializeReference(conc_array, array_ref);
/* null-check */
if (nullReferenceViolation(array_ref, conc_array)) {
return;
}
/* negative index */
if (negativeIndexViolation(conc_index, symb_index)) {
return;
}
/* out of bound index */
ReferenceExpression symb_array = array_ref;
int conc_array_length = Array.getLength(conc_array);
IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
return;
env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class HeapVM method INSTANCEOF.
/**
* Dynamic type check:
*
* <pre>
* (variable instanceof TypeName)
* </pre>
*
* null is not treated as (is not an instance of) any reference type. This
* requires non-standard treatment of null. Note the different treatment in
* {@link #CHECKCAST}.
*
* <p>
* If the jvm has not loaded the class/interface named TypeName before, then
* we load it. TODO: Is this a problem?
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#instanceof
*/
@Override
public void INSTANCEOF(Object conc_ref, String typeName) {
/* pop symbolic arguments */
ReferenceExpression symb_ref = env.topFrame().operandStack.popRef();
/* check reference initialization */
env.heap.initializeReference(conc_ref, symb_ref);
Type type = Type.getType(typeName);
Class<?> myClazz = classLoader.getClassForType(type);
boolean instanceOf = myClazz.isInstance(conc_ref);
IntegerConstant ret;
if (instanceOf) {
ret = ExpressionFactory.ICONST_1;
} else {
ret = ExpressionFactory.ICONST_0;
}
/* push symbolic arguments */
env.topFrame().operandStack.pushBv32(ret);
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class HeapVM method AALOAD.
@Override
public void AALOAD(Object conc_array, int conc_index) {
// pop symbolic arguments
IntegerValue symb_index = env.topFrame().operandStack.popBv32();
ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
/* check reference initialization */
env.heap.initializeReference(conc_array, array_ref);
/* null-check */
if (nullReferenceViolation(array_ref, conc_array)) {
return;
}
/* negative index */
if (negativeIndexViolation(conc_index, symb_index)) {
return;
}
/* out of bound index */
ReferenceExpression symb_array = (ReferenceExpression) array_ref;
int conc_array_length = Array.getLength(conc_array);
IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
return;
Object conc_value = Array.get(conc_array, conc_index);
ReferenceExpression symb_value;
if (conc_value == null) {
symb_value = ExpressionFactory.buildNewNullExpression();
} else {
symb_value = env.heap.getReference(conc_value);
}
env.topFrame().operandStack.pushRef(symb_value);
}
Aggregations