Search in sources :

Example 46 with IntegerValue

use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.

the class HeapVM method FASTORE.

@Override
public void FASTORE(Object conc_array, int conc_index) {
    // get symbolic arguments
    RealValue symb_value = env.topFrame().operandStack.popFp32();
    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 : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 47 with IntegerValue

use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.

the class HeapVM method MULTIANEWARRAY.

/**
 * MULTIANEWARRAY
 *
 * <pre>
 * boolean[] b1 = new boolean[1]; // NEWARRAY T_BOOLEAN
 * Boolean[] B1 = new Boolean[1]; // ANEWARRAY java/lang/Boolean
 * boolean[][] b2 = new boolean[1][2]; // MULTIANEWARRAY [[Z 2
 * Boolean[][] B2 = new Boolean[1][2]; // MULTIANEWARRAY [[Ljava/lang/Boolean; 2
 * </pre>
 */
@Override
public void MULTIANEWARRAY(String arrayTypeDesc, int nrDimensions) {
    // push negartive length constraints
    for (int i = 0; i < nrDimensions; i++) {
        IntegerValue symb_length = env.topFrame().operandStack.popBv32();
        int conc_length = ((Long) symb_length.getConcreteValue()).intValue();
        if (negativeArrayLengthViolation(conc_length, symb_length)) {
            return;
        }
    }
    Type multiArrayType = Type.getType(arrayTypeDesc);
    // push delayed object
    ReferenceConstant newMultiArray = this.env.heap.buildNewReferenceConstant(// @FIXME
    multiArrayType);
    env.topFrame().operandStack.pushRef(newMultiArray);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 48 with IntegerValue

use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.

the class HeapVM method NEWARRAY.

/* Arrays */
/**
 * Create a (one-dimensional) array of primitive componenet type, e.g., new
 * int[3]
 *
 * Allocate space on the heap and push a reference ref to it onto the stack.
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc10.html#newarray
 */
@Override
public void NEWARRAY(int conc_array_length, Class<?> componentType) {
    /**
     * Since this callback is invoked before the actual array creation, we
     * can only add negative index constraints.
     *
     * PRE: int (length)
     *
     * POST: arrayref (delayed)
     */
    // discard symbolic arguments
    IntegerValue symb_array_length = env.topFrame().operandStack.popBv32();
    /* negative index */
    if (negativeArrayLengthViolation(conc_array_length, symb_array_length))
        return;
    // create array class
    int[] lenghts = new int[] { 0 };
    Class<?> array_class = Array.newInstance(componentType, lenghts).getClass();
    Type arrayType = Type.getType(array_class);
    ReferenceConstant symb_array_ref = this.env.heap.buildNewReferenceConstant(arrayType);
    env.heap.putField("", ARRAY_LENGTH, null, symb_array_ref, symb_array_length);
    env.topFrame().operandStack.pushRef(symb_array_ref);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 49 with IntegerValue

use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.

the class HeapVM method ANEWARRAY.

/**
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc
 * .html#anewarray
 */
@Override
public void ANEWARRAY(int conc_array_length, String componentTypeName) {
    /**
     * Since this callback is invoked before the actual array creation, we
     * can only add negative index constraints.
     *
     * PRE: int (length)
     *
     * POST: arrayref (delayed)
     */
    // discard symbolic arguments
    IntegerValue symb_array_length = env.topFrame().operandStack.popBv32();
    /* negative index */
    if (negativeArrayLengthViolation(conc_array_length, symb_array_length))
        return;
    // create array class
    Type componentType = Type.getType(componentTypeName.replace('/', '.'));
    Class<?> componentClass = classLoader.getClassForType(componentType);
    int[] lenghts = new int[] { 0 };
    Class<?> array_class = Array.newInstance(componentClass, lenghts).getClass();
    Type arrayType = Type.getType(array_class);
    ReferenceConstant symb_array_ref = env.heap.buildNewReferenceConstant(arrayType);
    env.heap.putField("", ARRAY_LENGTH, null, symb_array_ref, symb_array_length);
    env.topFrame().operandStack.pushRef(symb_array_ref);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 50 with IntegerValue

use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.

the class HeapVM method CALOAD.

@Override
public void CALOAD(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 = 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;
    char bv32 = Array.getChar(conc_array, conc_index);
    IntegerValue c = env.heap.array_load(symb_array, conc_index, (long) bv32);
    env.topFrame().operandStack.pushBv32(c);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Aggregations

IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)117 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)48 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)32 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)27 RealValue (org.evosuite.symbolic.expr.fp.RealValue)22 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)14 Expression (org.evosuite.symbolic.expr.Expression)8 StringValue (org.evosuite.symbolic.expr.str.StringValue)8 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)7 Type (org.objectweb.asm.Type)7 RealToIntegerCast (org.evosuite.symbolic.expr.bv.RealToIntegerCast)6 IntegerToRealCast (org.evosuite.symbolic.expr.fp.IntegerToRealCast)6 IntegerUnaryExpression (org.evosuite.symbolic.expr.bv.IntegerUnaryExpression)5 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)4 ArrayList (java.util.ArrayList)3 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)3 Field (java.lang.reflect.Field)2 BigInteger (java.math.BigInteger)2 Vector (java.util.Vector)2 Constraint (org.evosuite.symbolic.expr.Constraint)2