Example usage for org.objectweb.asm Opcodes GETSTATIC

List of usage examples for org.objectweb.asm Opcodes GETSTATIC

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes GETSTATIC.

Prototype

int GETSTATIC

To view the source code for org.objectweb.asm Opcodes GETSTATIC.

Click Source Link

Usage

From source file:org.evosuite.instrumentation.ArrayAllocationLimitMethodAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from w w w .java 2 s .  c om*/
public void visitTypeInsn(int opcode, String type) {

    if (opcode == Opcodes.ANEWARRAY) {
        Label origTarget = new Label();
        visitInsn(Opcodes.DUP);
        visitFieldInsn(Opcodes.GETSTATIC, PackageInfo.getNameWithSlash(org.evosuite.Properties.class),
                "ARRAY_LIMIT", "I");
        super.visitJumpInsn(Opcodes.IF_ICMPLT, origTarget);
        super.visitTypeInsn(Opcodes.NEW, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class));
        super.visitInsn(Opcodes.DUP);
        super.visitMethodInsn(Opcodes.INVOKESPECIAL,
                PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class), "<init>", "()V", false);
        super.visitInsn(Opcodes.ATHROW);
        super.visitLabel(origTarget);

    }
    super.visitTypeInsn(opcode, type);
}

From source file:org.evosuite.instrumentation.ArrayAllocationLimitMethodAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from ww  w  .jav  a2  s. c  o m*/
public void visitMultiANewArrayInsn(String desc, int dims) {

    Label origTarget = new Label();
    Label errorTarget = new Label();

    // Multidimensional arrays can only have max 256 dimensions
    if (Properties.ARRAY_LIMIT < 256) {
        push(dims);
        visitFieldInsn(Opcodes.GETSTATIC, PackageInfo.getNameWithSlash(org.evosuite.Properties.class),
                "ARRAY_LIMIT", "I");
        super.visitJumpInsn(Opcodes.IF_ICMPGE, errorTarget);
    }

    // Check each of the dimensions
    Map<Integer, Integer> to = new HashMap<Integer, Integer>();
    for (int i = dims - 1; i >= 0; i--) {
        int loc = newLocal(Type.INT_TYPE);
        storeLocal(loc);
        to.put(i, loc);
    }
    for (int i = 0; i < dims; i++) {
        loadLocal(to.get(i));
        visitFieldInsn(Opcodes.GETSTATIC, "org/evosuite/Properties", "ARRAY_LIMIT", "I");
        super.visitJumpInsn(Opcodes.IF_ICMPGE, errorTarget);
    }
    goTo(origTarget);
    super.visitLabel(errorTarget);
    super.visitTypeInsn(Opcodes.NEW, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class));
    super.visitInsn(Opcodes.DUP);
    super.visitMethodInsn(Opcodes.INVOKESPECIAL,
            PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class), "<init>", "()V", false);
    super.visitInsn(Opcodes.ATHROW);
    super.visitLabel(origTarget);

    // Restore original dimensions
    for (int i = 0; i < dims; i++) {
        loadLocal(to.get(i));
    }

    super.visitMultiANewArrayInsn(desc, dims);
}

From source file:org.evosuite.instrumentation.BooleanValueInterpreter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   w w  w. j  ava  2 s.c  o m
public BasicValue newOperation(AbstractInsnNode insn) throws AnalyzerException {
    if (insn.getOpcode() == ICONST_0) {
        return BOOLEAN_VALUE;
    } else if (insn.getOpcode() == ICONST_1) {
        return BOOLEAN_VALUE;
    } else if (insn.getOpcode() == Opcodes.GETSTATIC) {
        FieldInsnNode fieldNode = (FieldInsnNode) insn;
        if (BooleanTestabilityTransformation.isTransformedField(fieldNode.owner, fieldNode.name,
                fieldNode.desc))
            return BOOLEAN_VALUE;

    }
    return super.newOperation(insn);
}

From source file:org.evosuite.instrumentation.coverage.MutationInstrumentation.java

License:Open Source License

/**
 * <p>// w  w  w .  j  ava 2 s .co m
 * addInstrumentation
 * </p>
 * 
 * @param mn
 *            a {@link org.objectweb.asm.tree.MethodNode} object.
 * @param original
 *            a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 * @param mutations
 *            a {@link java.util.List} object.
 */
protected void addInstrumentation(MethodNode mn, AbstractInsnNode original, List<Mutation> mutations) {

    InsnList instructions = new InsnList();

    // call mutationTouched(mutationObject.getId());
    // TODO: All mutations in the id are touched, not just one!
    for (Mutation mutation : mutations) {
        instructions.add(mutation.getInfectionDistance());
        instructions.add(new LdcInsnNode(mutation.getId()));
        MethodInsnNode touched = new MethodInsnNode(Opcodes.INVOKESTATIC,
                Type.getInternalName(ExecutionTracer.class), "passedMutation",
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.INT_TYPE }),
                false);
        instructions.add(touched);
    }

    LabelNode endLabel = new LabelNode();
    for (Mutation mutation : mutations) {
        LabelNode nextLabel = new LabelNode();

        LdcInsnNode mutationId = new LdcInsnNode(mutation.getId());
        instructions.add(mutationId);
        FieldInsnNode activeId = new FieldInsnNode(Opcodes.GETSTATIC,
                Type.getInternalName(MutationObserver.class), "activeMutation", "I");
        instructions.add(activeId);
        instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, nextLabel));
        instructions.add(mutation.getMutation());
        instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabel));
        instructions.add(nextLabel);
    }

    mn.instructions.insertBefore(original, instructions);
    mn.instructions.insert(original, endLabel);
}

From source file:org.evosuite.instrumentation.mutation.DeleteField.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from   w w w.j  a va  2 s .c om*/
public boolean isApplicable(BytecodeInstruction instruction) {
    return instruction.getASMNode().getOpcode() == Opcodes.GETFIELD
            || instruction.getASMNode().getOpcode() == Opcodes.GETSTATIC;

}

From source file:org.evosuite.instrumentation.mutation.InsertUnaryOperator.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from  w  w  w  .  java2  s . c  om*/
public boolean isApplicable(BytecodeInstruction instruction) {
    AbstractInsnNode node = instruction.getASMNode();
    switch (node.getOpcode()) {
    case Opcodes.ILOAD:
    case Opcodes.LLOAD:
    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
        return true;
    case Opcodes.GETFIELD:
    case Opcodes.GETSTATIC:
        FieldInsnNode fieldNode = (FieldInsnNode) instruction.getASMNode();
        Type type = Type.getType(fieldNode.desc);
        if (type == Type.BYTE_TYPE || type == Type.SHORT_TYPE || type == Type.LONG_TYPE
                || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.BOOLEAN_TYPE
                || type == Type.INT_TYPE) {
            return true;
        }
    default:
        return false;
    }
}

From source file:org.evosuite.instrumentation.mutation.ReplaceVariable.java

License:Open Source License

private Map<String, InsnList> getFieldReplacements(MethodNode mn, String className, String desc,
        AbstractInsnNode node) {//www  .  j  av  a  2 s . com
    Map<String, InsnList> alternatives = new HashMap<String, InsnList>();

    boolean isStatic = (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC;

    String otherName = "";
    if (node instanceof FieldInsnNode) {
        FieldInsnNode fNode = (FieldInsnNode) node;
        otherName = fNode.name;
    }
    try {
        logger.info("Checking class " + className);
        Class<?> clazz = Class.forName(className, false, ReplaceVariable.class.getClassLoader());

        for (Field field : TestClusterUtils.getFields(clazz)) {
            // We have to use a special version of canUse to avoid
            // that we access the CUT before it is fully initialised
            if (!canUse(field))
                continue;

            Type type = Type.getType(field.getType());
            logger.info("Checking replacement field variable " + field.getName());

            if (field.getName().equals(otherName))
                continue;

            if (isStatic && !(Modifier.isStatic(field.getModifiers())))
                continue;

            if (type.getDescriptor().equals(desc)) {
                logger.info("Adding replacement field variable " + field.getName());
                InsnList list = new InsnList();
                if (node.getOpcode() == Opcodes.GETFIELD) {
                    list.add(new InsnNode(Opcodes.POP)); // Remove field owner from stack
                }

                // new fieldinsnnode
                if (Modifier.isStatic(field.getModifiers()))
                    list.add(new FieldInsnNode(Opcodes.GETSTATIC, className.replace('.', '/'), field.getName(),
                            type.getDescriptor()));
                else {
                    list.add(new VarInsnNode(Opcodes.ALOAD, 0)); // this
                    list.add(new FieldInsnNode(Opcodes.GETFIELD, className.replace('.', '/'), field.getName(),
                            type.getDescriptor()));
                }
                alternatives.put(field.getName(), list);
            } else {
                logger.info("Descriptor does not match: " + field.getName() + " - " + type.getDescriptor());
            }
        }
    } catch (Throwable t) {
        logger.info("Class not found: " + className);
        // TODO Auto-generated catch block
        //e.printStackTrace();
    }
    return alternatives;
}

From source file:org.evosuite.instrumentation.mutation.ReplaceVariable.java

License:Open Source License

/** {@inheritDoc} */
@Override//  w ww  .j a v  a2s.  c  o m
public boolean isApplicable(BytecodeInstruction instruction) {
    return instruction.isLocalVariableUse() || instruction.getASMNode().getOpcode() == Opcodes.GETSTATIC
            || instruction.getASMNode().getOpcode() == Opcodes.GETFIELD;
}

From source file:org.evosuite.instrumentation.StaticAccessMethodAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from   w ww  .j a v a2 s. co m*/
public void visitFieldInsn(int opcode, String owner, String name, String desc) {

    if ((opcode == Opcodes.PUTSTATIC || opcode == Opcodes.GETSTATIC)
            && !(className.equals(owner) && methodName.equals("<clinit>"))
            && !(className.equals(owner) && methodName.equals(ClassResetter.STATIC_RESET))) {

        String classNameWithDots = owner.replace('/', '.');
        if (RuntimeInstrumentation.checkIfCanInstrument(classNameWithDots)) {

            String executionTracerClassName = ExecutionTracer.class.getName().replace('.', '/');
            String executionTracerDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE,
                    Type.getType(String.class), Type.getType(String.class));

            super.visitLdcInsn(classNameWithDots);
            super.visitLdcInsn(name);
            if (opcode == Opcodes.PUTSTATIC)
                super.visitMethodInsn(INVOKESTATIC, executionTracerClassName, PASSED_PUT_STATIC,
                        executionTracerDescriptor, false);
            else
                super.visitMethodInsn(INVOKESTATIC, executionTracerClassName, PASSED_GET_STATIC,
                        executionTracerDescriptor, false);
        }
    }
    super.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.evosuite.instrumentation.testability.transformer.BooleanDefinitionTransformer.java

License:Open Source License

@Override
protected AbstractInsnNode transformFieldInsnNode(MethodNode mn, FieldInsnNode fieldNode) {
    // This handles the else branch for field assignments
    if (DescriptorMapping.getInstance().isTransformedOrBooleanField(
            this.booleanTestabilityTransformation.className, fieldNode.name, fieldNode.desc)) {
        if (fieldNode.getNext() instanceof FieldInsnNode) {
            FieldInsnNode other = (FieldInsnNode) fieldNode.getNext();
            if (fieldNode.owner.equals(other.owner) && fieldNode.name.equals(other.name)
                    && fieldNode.desc.equals(other.desc)) {
                if (fieldNode.getOpcode() == Opcodes.GETFIELD && other.getOpcode() == Opcodes.PUTFIELD) {
                    this.booleanTestabilityTransformation.insertGetBefore(other, mn.instructions);
                } else if (fieldNode.getOpcode() == Opcodes.GETSTATIC
                        && other.getOpcode() == Opcodes.PUTSTATIC) {
                    this.booleanTestabilityTransformation.insertGetBefore(other, mn.instructions);
                }//  www.  ja v  a 2  s . co m
            }
        }
    }
    return fieldNode;
}