Search in sources :

Example 21 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.

the class InsertUnaryOperator method isApplicable.

/* (non-Javadoc)
	 * @see org.evosuite.cfg.instrumentation.mutation.MutationOperator#isApplicable(org.evosuite.cfg.BytecodeInstruction)
	 */
/**
 * {@inheritDoc}
 */
@Override
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;
    }
}
Also used : Type(org.objectweb.asm.Type) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 22 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.

the class BytecodeInstructionPool method createFakeInstruction.

/**
 * <p>
 * createFakeInstruction
 * </p>
 *
 * @param className
 *            a {@link java.lang.String} object.
 * @param methodName
 *            a {@link java.lang.String} object.
 * @return a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 */
public BytecodeInstruction createFakeInstruction(String className, String methodName) {
    AbstractInsnNode fakeNode = new InsnNode(Opcodes.NOP);
    int instructionId = getInstructionsIn(className, methodName).size();
    BytecodeInstruction instruction = new BytecodeInstruction(classLoader, className, methodName, instructionId, -1, fakeNode);
    registerInstruction(instruction);
    return instruction;
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 23 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.

the class BytecodeInstructionPool method registerMethodNode.

// fill the pool
/**
 * Called by each CFGGenerator for it's corresponding method.
 *
 * The MethodNode contains all instructions within a method. A call to
 * registerMethodNode() fills the instructionMap of the
 * BytecodeInstructionPool with the instructions in that method and returns
 * a List containing the BytecodeInstructions within that method.
 *
 * While registering all instructions the lineNumber of each
 * BytecodeInstruction is set.
 *
 * @param node
 *            a {@link org.objectweb.asm.tree.MethodNode} object.
 * @param className
 *            a {@link java.lang.String} object.
 * @param methodName
 *            a {@link java.lang.String} object.
 * @return a {@link java.util.List} object.
 */
public List<BytecodeInstruction> registerMethodNode(MethodNode node, String className, String methodName) {
    registerMethodNode(node);
    int lastLineNumber = -1;
    int bytecodeOffset = 0;
    for (int instructionId = 0; instructionId < node.instructions.size(); instructionId++) {
        AbstractInsnNode instructionNode = node.instructions.get(instructionId);
        BytecodeInstruction instruction = BytecodeInstructionFactory.createBytecodeInstruction(classLoader, className, methodName, instructionId, bytecodeOffset, instructionNode);
        if (instruction.isLineNumber())
            lastLineNumber = instruction.getLineNumber();
        else if (lastLineNumber != -1)
            instruction.setLineNumber(lastLineNumber);
        bytecodeOffset += getBytecodeIncrement(instructionNode);
        if (!instruction.isLabel() && !instruction.isLineNumber() && !instruction.isFrame()) {
            bytecodeOffset++;
        }
        registerInstruction(instruction);
    }
    List<BytecodeInstruction> r = getInstructionsIn(className, methodName);
    if (r == null || r.size() == 0)
        throw new IllegalStateException("expect instruction pool to return non-null non-empty list of instructions for a previously registered method " + methodName);
    return r;
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 24 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.

the class NodeRegularExpression method matches.

/**
 * <p>matches</p>
 *
 * @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a boolean.
 */
public boolean matches(InsnList instructions) {
    int match = 0;
    AbstractInsnNode node = instructions.getFirst();
    while (node != instructions.getLast()) {
        if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL || node.getType() == AbstractInsnNode.LINE) {
            node = node.getNext();
            continue;
        } else {
            boolean found = false;
            for (int opcode : pattern[match]) {
                if (node.getOpcode() == opcode) {
                    match++;
                    found = true;
                    break;
                }
            }
            if (!found)
                match = 0;
        }
        if (match == pattern.length)
            return true;
        node = node.getNext();
    }
    return false;
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 25 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.

the class NodeRegularExpression method getNextMatch.

/**
 * <p>getNextMatch</p>
 *
 * @param start a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 * @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 */
public AbstractInsnNode getNextMatch(AbstractInsnNode start, InsnList instructions) {
    int match = 0;
    AbstractInsnNode node = start;
    AbstractInsnNode startNode = start;
    while (node != instructions.getLast()) {
        if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL || node.getType() == AbstractInsnNode.LINE) {
            node = node.getNext();
            continue;
        } else {
            boolean found = false;
            for (int opcode : pattern[match]) {
                if (node.getOpcode() == opcode) {
                    if (match == 0)
                        startNode = node;
                    match++;
                    found = true;
                    break;
                }
            }
            if (!found)
                match = 0;
        }
        if (match == pattern.length) {
            return startNode;
        }
        node = node.getNext();
    }
    return null;
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)185 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)68 MethodNode (org.objectweb.asm.tree.MethodNode)54 InsnList (org.objectweb.asm.tree.InsnList)53 InsnNode (org.objectweb.asm.tree.InsnNode)41 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)38 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)37 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)35 ClassNode (org.objectweb.asm.tree.ClassNode)33 LabelNode (org.objectweb.asm.tree.LabelNode)27 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)26 Test (org.junit.Test)25 Label (org.objectweb.asm.Label)25 ClassReader (org.objectweb.asm.ClassReader)23 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)23 HashSet (java.util.HashSet)16 Type (org.objectweb.asm.Type)15 Frame (org.objectweb.asm.tree.analysis.Frame)13 ArrayList (java.util.ArrayList)12 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)11