Search in sources :

Example 31 with ReferenceExpression

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);
}
Also used : Field(java.lang.reflect.Field) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 32 with ReferenceExpression

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);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 33 with ReferenceExpression

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);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 34 with ReferenceExpression

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);
}
Also used : Type(org.objectweb.asm.Type) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 35 with ReferenceExpression

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);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Aggregations

ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)73 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)19 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)18 StringValue (org.evosuite.symbolic.expr.str.StringValue)16 Expression (org.evosuite.symbolic.expr.Expression)13 RealValue (org.evosuite.symbolic.expr.fp.RealValue)13 VariableReference (org.evosuite.testcase.variable.VariableReference)11 Type (org.objectweb.asm.Type)9 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)6 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)5 Field (java.lang.reflect.Field)3 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)3 Method (java.lang.reflect.Method)2 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)2 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)2 ArrayReference (org.evosuite.testcase.variable.ArrayReference)2 BigInteger (java.math.BigInteger)1 Matcher (java.util.regex.Matcher)1 EvoSuiteFile (org.evosuite.runtime.testdata.EvoSuiteFile)1