Example usage for org.objectweb.asm Opcodes ICONST_1

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

Introduction

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

Prototype

int ICONST_1

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

Click Source Link

Usage

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

License:Open Source License

/**
 * <p>//w  ww.ja  v a2  s.co  m
 * transformMethod
 * </p>
 * 
 * @param mn
 *            a {@link org.objectweb.asm.tree.MethodNode} object.
 * @return a boolean.
 */
public boolean transformMethod(MethodNode mn) {
    boolean changed = transformStrings(mn);
    if (changed) {
        try {
            mn.maxStack++;
            Analyzer a = new Analyzer(new StringBooleanInterpreter());
            a.analyze(cn.name, mn);
            Frame[] frames = a.getFrames();
            AbstractInsnNode node = mn.instructions.getFirst();
            boolean done = false;
            while (!done) {
                if (node == mn.instructions.getLast())
                    done = true;
                AbstractInsnNode next = node.getNext();
                int index = mn.instructions.indexOf(node);
                if (index >= frames.length)
                    break;
                Frame current = frames[index];
                if (current == null)
                    break;
                int size = current.getStackSize();
                if (node.getOpcode() == Opcodes.IFNE) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious())) {
                        logger.info("IFNE -> IFGT");
                        branch.setOpcode(Opcodes.IFGT);
                        // branch.setOpcode(Opcodes.IFGE);
                    }
                } else if (node.getOpcode() == Opcodes.IFEQ) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious())) {
                        logger.info("IFEQ -> IFLE");
                        branch.setOpcode(Opcodes.IFLE);
                        // branch.setOpcode(Opcodes.IFNE);
                    }
                } else if (node.getOpcode() == Opcodes.IF_ICMPEQ) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious().getPrevious())) {
                        if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) {
                            branch.setOpcode(Opcodes.IFLE);
                            mn.instructions.remove(node.getPrevious());
                        } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) {
                            branch.setOpcode(Opcodes.IFGT);
                            mn.instructions.remove(node.getPrevious());
                        }
                    }
                } else if (node.getOpcode() == Opcodes.IF_ICMPNE) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious().getPrevious())) {
                        if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) {
                            branch.setOpcode(Opcodes.IFGT);
                            mn.instructions.remove(node.getPrevious());
                        } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) {
                            branch.setOpcode(Opcodes.IFLE);
                            mn.instructions.remove(node.getPrevious());
                        }
                    }
                } else if (node.getOpcode() == Opcodes.IRETURN) {
                    if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious())) {
                        logger.info("IFEQ -> IFLE");
                        MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                Type.getInternalName(BooleanHelper.class), "intToBoolean",
                                Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE }));

                        mn.instructions.insertBefore(node, n);
                    }
                }
                node = next;
            }
        } catch (Exception e) {
            logger.warn("EXCEPTION DURING STRING TRANSFORMATION: {}", e);
            e.printStackTrace();
            return changed;
        }
    }
    return changed;
}

From source file:org.evosuite.instrumentation.testability.BooleanTestabilityTransformation.java

License:Open Source License

/**
 * This helper function determines whether the boolean on the stack at the
 * current position will be stored in a Boolean variable
 * /*from ww  w .  jav a 2 s. c  o  m*/
 * @param position
 * @param mn
 * @return
 */
public boolean isBooleanAssignment(AbstractInsnNode position, MethodNode mn) {
    AbstractInsnNode node = position.getNext();
    logger.info("Checking for ISTORE after boolean");
    boolean done = false;
    while (!done) {

        if (node.getOpcode() == Opcodes.PUTFIELD || node.getOpcode() == Opcodes.PUTSTATIC) {
            // TODO: Check whether field is static
            logger.info("Checking field assignment");
            FieldInsnNode fn = (FieldInsnNode) node;
            if (Type.getType(DescriptorMapping.getInstance().getFieldDesc(fn.owner, fn.name,
                    fn.desc)) == Type.BOOLEAN_TYPE) {
                return true;
            } else {
                return false;
            }
        } else if (node.getOpcode() == Opcodes.ISTORE) {
            logger.info("Found ISTORE after boolean");

            VarInsnNode vn = (VarInsnNode) node;
            // TODO: Check whether variable at this position is a boolean
            if (isBooleanVariable(vn.var, mn)) {
                logger.info("Assigning boolean to variable ");
                return true;
            } else {
                logger.info("Variable is not a bool");
                return false;
            }
        } else if (node.getOpcode() == Opcodes.IRETURN) {
            logger.info("Checking return value of method " + cn.name + "." + mn.name);
            if (DescriptorMapping.getInstance().isTransformedOrBooleanMethod(cn.name, mn.name, mn.desc)) {
                logger.info("Method returns a bool");
                return true;
            } else {
                logger.info("Method does not return a bool");
                return false;
            }
        } else if (node.getOpcode() == Opcodes.BASTORE) {
            // We remove all bytes, so BASTORE is only used for booleans
            AbstractInsnNode start = position.getNext();
            boolean reassignment = false;
            while (start != node) {
                if (node instanceof InsnNode) {
                    reassignment = true;
                }
                start = start.getNext();
            }
            logger.info("Possible assignment to array?");
            if (reassignment)
                return false;
            else
                return true;

        } else if (node instanceof MethodInsnNode) {
            // if it is a boolean parameter of a converted method, then it needs to be converted
            // Problem: How do we know which parameter it represents?
            MethodInsnNode methodNode = (MethodInsnNode) node;
            String desc = DescriptorMapping.getInstance().getMethodDesc(methodNode.owner, methodNode.name,
                    methodNode.desc);
            Type[] types = Type.getArgumentTypes(desc);
            if (types.length > 0 && types[types.length - 1] == Type.BOOLEAN_TYPE) {
                return true;
            } else {
                return false;
            }

        } else if (node.getOpcode() == Opcodes.GOTO || node.getOpcode() == Opcodes.ICONST_0
                || node.getOpcode() == Opcodes.ICONST_1 || node.getOpcode() == -1) {
            logger.info("Continuing search");

            // continue search
        } else if (!(node instanceof LineNumberNode || node instanceof FrameNode)) {
            logger.info("Search ended with opcode " + node.getOpcode());

            return false;
        }
        if (node != mn.instructions.getLast())
            node = node.getNext();
        else
            done = true;
    }

    return false;
}

From source file:org.evosuite.instrumentation.testability.StringTransformation.java

License:Open Source License

/**
 * <p>//w  w  w  .ja  v  a  2s  .  c  om
 * transformMethod
 * </p>
 * 
 * @param mn
 *            a {@link org.objectweb.asm.tree.MethodNode} object.
 * @return a boolean.
 */
public boolean transformMethod(MethodNode mn) {
    boolean changed = transformStrings(mn);
    if (changed) {
        try {
            mn.maxStack++;
            Analyzer a = new Analyzer(new StringBooleanInterpreter());
            a.analyze(cn.name, mn);
            Frame[] frames = a.getFrames();
            AbstractInsnNode node = mn.instructions.getFirst();
            boolean done = false;
            while (!done) {
                if (node == mn.instructions.getLast())
                    done = true;
                AbstractInsnNode next = node.getNext();
                int index = mn.instructions.indexOf(node);
                if (index >= frames.length)
                    break;
                Frame current = frames[index];
                if (current == null)
                    break;
                int size = current.getStackSize();
                if (node.getOpcode() == Opcodes.IFNE) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious())) {
                        logger.info("IFNE -> IFGT");
                        branch.setOpcode(Opcodes.IFGT);
                    }
                } else if (node.getOpcode() == Opcodes.IFEQ) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious())) {
                        logger.info("IFEQ -> IFLE");
                        branch.setOpcode(Opcodes.IFLE);
                    }
                } else if (node.getOpcode() == Opcodes.IF_ICMPEQ) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious().getPrevious())) {
                        if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) {
                            branch.setOpcode(Opcodes.IFLE);
                            mn.instructions.remove(node.getPrevious());
                        } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) {
                            branch.setOpcode(Opcodes.IFGT);
                            mn.instructions.remove(node.getPrevious());
                        }
                    }
                } else if (node.getOpcode() == Opcodes.IF_ICMPNE) {
                    JumpInsnNode branch = (JumpInsnNode) node;
                    if (current.getStack(size - 2) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious().getPrevious())) {
                        if (node.getPrevious().getOpcode() == Opcodes.ICONST_0) {
                            branch.setOpcode(Opcodes.IFGT);
                            mn.instructions.remove(node.getPrevious());
                        } else if (node.getPrevious().getOpcode() == Opcodes.ICONST_1) {
                            branch.setOpcode(Opcodes.IFLE);
                            mn.instructions.remove(node.getPrevious());
                        }
                    }
                } else if (node.getOpcode() == Opcodes.IRETURN) {
                    if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
                            || isStringMethod(node.getPrevious())) {
                        logger.info("IFEQ -> IFLE");
                        MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                Type.getInternalName(BooleanHelper.class), "intToBoolean",
                                Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE }),
                                false);

                        mn.instructions.insertBefore(node, n);
                    }
                }
                node = next;
            }
        } catch (Exception e) {
            logger.warn("EXCEPTION DURING STRING TRANSFORMATION: " + e);
            return changed;
        }
    }
    return changed;
}

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

License:Open Source License

@Override
protected AbstractInsnNode transformMethodInsnNode(MethodNode mn, MethodInsnNode methodNode) {
    if (methodNode.owner.equals(Type.getInternalName(BooleanHelper.class)))
        return methodNode;

    methodNode.desc = this.booleanTestabilityTransformation.transformMethodDescriptor(methodNode.owner,
            methodNode.name, methodNode.desc);
    methodNode.name = DescriptorMapping.getInstance().getMethodName(methodNode.owner, methodNode.name,
            methodNode.desc);/*from   www.j  ava 2 s . c o m*/
    if (DescriptorMapping.getInstance().isBooleanMethod(methodNode.desc)) {
        BooleanTestabilityTransformation.logger.info("Method needs value transformation: " + methodNode.name);
        if (DescriptorMapping.getInstance().hasBooleanParameters(methodNode.desc)) {
            BooleanTestabilityTransformation.logger
                    .info("Method needs parameter transformation: " + methodNode.name);
            TransformationStatistics.transformBackToBooleanParameter();
            int firstBooleanParameterIndex = -1;
            Type[] types = Type.getArgumentTypes(methodNode.desc);
            for (int i = 0; i < types.length; i++) {
                if (types[i].getDescriptor().equals("Z")) {
                    if (firstBooleanParameterIndex == -1) {
                        firstBooleanParameterIndex = i;
                        break;
                    }
                }
            }
            if (firstBooleanParameterIndex != -1) {
                int numOfPushs = types.length - 1 - firstBooleanParameterIndex;
                //                        int numOfPushs = types.length - firstBooleanParameterIndex;

                if (numOfPushs == 0) {
                    if (!(methodNode.getPrevious().getOpcode() == Opcodes.ICONST_1
                            || methodNode.getPrevious().getOpcode() == Opcodes.ICONST_0)) {

                        //the boolean parameter is the last parameter
                        MethodInsnNode booleanHelperInvoke = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                Type.getInternalName(BooleanHelper.class), "intToBoolean",
                                Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE }));
                        mn.instructions.insertBefore(methodNode, booleanHelperInvoke);
                    }
                } else {
                    InsnList insnlist = new InsnList();

                    for (int i = 0; i < numOfPushs; i++) {
                        MethodInsnNode booleanHelperPushParameter;
                        if (types[types.length - 1 - i] == Type.BOOLEAN_TYPE
                                || types[types.length - 1 - i] == Type.CHAR_TYPE
                                || types[types.length - 1 - i] == Type.BYTE_TYPE
                                || types[types.length - 1 - i] == Type.SHORT_TYPE
                                || types[types.length - 1 - i] == Type.INT_TYPE
                                || types[types.length - 1 - i] == Type.FLOAT_TYPE
                                || types[types.length - 1 - i] == Type.LONG_TYPE
                                || types[types.length - 1 - i] == Type.DOUBLE_TYPE) {
                            if (types[types.length - 1 - i] == Type.BOOLEAN_TYPE) {
                                booleanHelperPushParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "pushParameter",
                                        Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE }));
                            } else {
                                booleanHelperPushParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "pushParameter",
                                        Type.getMethodDescriptor(Type.VOID_TYPE,
                                                new Type[] { types[types.length - 1 - i] }));
                            }
                        } else {
                            booleanHelperPushParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                    Type.getInternalName(BooleanHelper.class), "pushParameter",
                                    Type.getMethodDescriptor(Type.VOID_TYPE,
                                            new Type[] { Type.getType(Object.class) }));
                        }

                        insnlist.add(booleanHelperPushParameter);
                    }
                    for (int i = firstBooleanParameterIndex; i < types.length; i++) {
                        if (i == firstBooleanParameterIndex) {
                            MethodInsnNode booleanHelperInvoke = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                    Type.getInternalName(BooleanHelper.class), "intToBoolean",
                                    Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE }));
                            insnlist.add(booleanHelperInvoke);
                        } else {
                            MethodInsnNode booleanHelperPopParameter;
                            boolean objectNeedCast = false;
                            if (types[i] == Type.BOOLEAN_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterBooleanFromInt",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else if (types[i] == Type.CHAR_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterChar",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else if (types[i] == Type.BYTE_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterByte",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else if (types[i] == Type.SHORT_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterShort",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else if (types[i] == Type.INT_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterInt",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else if (types[i] == Type.FLOAT_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterFloat",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else if (types[i] == Type.LONG_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterLong",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else if (types[i] == Type.DOUBLE_TYPE) {
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterDouble",
                                        Type.getMethodDescriptor(types[i], new Type[] {}));
                            } else {
                                objectNeedCast = true;
                                booleanHelperPopParameter = new MethodInsnNode(Opcodes.INVOKESTATIC,
                                        Type.getInternalName(BooleanHelper.class), "popParameterObject",
                                        Type.getMethodDescriptor(Type.getType(Object.class), new Type[] {}));
                            }

                            insnlist.add(booleanHelperPopParameter);
                            if (objectNeedCast) {
                                TypeInsnNode tin = new TypeInsnNode(Opcodes.CHECKCAST,
                                        types[i].getInternalName());
                                insnlist.add(tin);
                            }
                        }

                    }
                    mn.instructions.insertBefore(methodNode, insnlist);
                }
            }
        }
        if (Type.getReturnType(methodNode.desc).equals(Type.BOOLEAN_TYPE)) {
            BooleanTestabilityTransformation.logger
                    .info("Method needs return transformation: " + methodNode.name);
            TransformationStatistics.transformBackToBooleanParameter();
            MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC,
                    Type.getInternalName(BooleanHelper.class), "booleanToInt",
                    Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.BOOLEAN_TYPE }));
            mn.instructions.insert(methodNode, n);
            return n;
        }
    } else {
        BooleanTestabilityTransformation.logger.info("Method needs no transformation: " + methodNode.name);
    }

    // TODO: If this is a method that is not transformed, and it requires a Boolean parameter
    // then we need to convert this boolean back to an int
    // For example, we could use flow analysis to determine the point where the value is added to the stack
    // and insert a conversion function there
    return methodNode;
}

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

License:Open Source License

@Override
protected AbstractInsnNode transformInsnNode(MethodNode mn, InsnNode insnNode) {
    BooleanTestabilityTransformation.logger.info("Checking transformation of InsnNode ");
    if (insnNode.getOpcode() == Opcodes.ICONST_0
            && this.booleanTestabilityTransformation.isBooleanAssignment(insnNode, mn)) {
        TransformationStatistics.insertedGet();
        this.booleanTestabilityTransformation.insertGet(insnNode, mn.instructions);
    } else if (insnNode.getOpcode() == Opcodes.ICONST_1
            && this.booleanTestabilityTransformation.isBooleanAssignment(insnNode, mn)) {
        TransformationStatistics.insertedGet();
        this.booleanTestabilityTransformation.insertGet(insnNode, mn.instructions);
        //} else if (insnNode.getOpcode() == Opcodes.IRETURN
        //        && isBooleanAssignment(insnNode, mn)) {
        //   TransformationStatistics.insertedGet();
        //   insertGetBefore(insnNode, mn.instructions);
    }/* ww  w  .  j av  a  2 s  . co m*/
    return insnNode;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  w w.j av a  2s . c  o m
protected AbstractInsnNode transformFieldInsnNode(MethodNode mn, FieldInsnNode fieldNode) {

    if ((fieldNode.getOpcode() == Opcodes.PUTFIELD || fieldNode.getOpcode() == Opcodes.PUTSTATIC)
            && DescriptorMapping.getInstance().isTransformedOrBooleanField(fieldNode.owner, fieldNode.name,
                    fieldNode.desc)) {

        if (addedInsns.contains(fieldNode))
            return fieldNode;

        // Can only handle cases where the field owner is loaded directly before the field
        // TODO: We could pop the top of the stack and DUP the owner, but would need to take care
        // whether we need to pop one or two words
        if (fieldNode.getOpcode() == Opcodes.PUTFIELD) {
            AbstractInsnNode previous = fieldNode.getPrevious();
            while (previous instanceof LineNumberNode || previous instanceof FrameNode
                    || previous.getOpcode() == Opcodes.ICONST_0 || previous.getOpcode() == Opcodes.ICONST_1)
                previous = previous.getPrevious();
            if (previous.getOpcode() != Opcodes.ALOAD) {
                BooleanTestabilityTransformation.logger.info("Can't handle case of " + previous);
                return fieldNode;
            }
            VarInsnNode varNode = (VarInsnNode) previous;
            if (varNode.var != 0) {
                BooleanTestabilityTransformation.logger.info("Can't handle case of " + previous);
                return fieldNode;
            }
        }
        BooleanTestabilityTransformation.logger.info("Handling PUTFIELD case!");

        // Check if ICONST_0 or ICONST_1 are on the stack
        ControlDependenceGraph cdg = GraphPool.getInstance(this.booleanTestabilityTransformation.classLoader)
                .getCDG(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc);
        int index = mn.instructions.indexOf(fieldNode);
        BooleanTestabilityTransformation.logger.info("Getting bytecode instruction for " + fieldNode.name + "/"
                + ((FieldInsnNode) mn.instructions.get(index)).name);
        InsnList nodes = mn.instructions;
        ListIterator<AbstractInsnNode> it = nodes.iterator();
        while (it.hasNext()) {
            BytecodeInstruction in = new BytecodeInstruction(this.booleanTestabilityTransformation.classLoader,
                    this.booleanTestabilityTransformation.className, mn.name, 0, 0, it.next());
            BooleanTestabilityTransformation.logger.info(in.toString());
        }
        BytecodeInstruction insn = BytecodeInstructionPool
                .getInstance(this.booleanTestabilityTransformation.classLoader)
                .getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."),
                        mn.name + mn.desc, index);
        if (insn == null)
            insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader)
                    .getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."),
                            mn.name + mn.desc, fieldNode);
        //varNode);
        if (insn == null) {
            // TODO: Find out why
            BooleanTestabilityTransformation.logger.info("ERROR: Could not find node");
            return fieldNode;
        }
        if (insn.getASMNode().getOpcode() != fieldNode.getOpcode()) {
            BooleanTestabilityTransformation.logger.info("Found wrong bytecode instruction at this index!");
            BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader)
                    .getInstruction(this.booleanTestabilityTransformation.className, mn.name + mn.desc,
                            fieldNode);
        }
        if (insn.getBasicBlock() == null) {
            BooleanTestabilityTransformation.logger.info("ERROR: Problematic node found");
            return fieldNode;
        }
        Set<ControlDependency> dependencies = insn.getControlDependencies();
        BooleanTestabilityTransformation.logger.info("Found flag assignment: " + insn + ", checking "
                + dependencies.size() + " control dependencies");

        for (ControlDependency dep : dependencies) {
            if (!addedNodes.contains(dep))
                handleDependency(dep, cdg, mn, fieldNode, insn);
        }
    }
    return fieldNode;
}

From source file:org.evosuite.seeding.PrimitivePoolMethodAdapter.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    Object constant = null;/*from  w w  w. j  av a  2  s . c  o  m*/
    switch (opcode) {
    case Opcodes.ICONST_0:
        constant = 0;
        break;
    case Opcodes.ICONST_1:
        constant = 1;
        break;
    case Opcodes.ICONST_2:
        constant = 2;
        break;
    case Opcodes.ICONST_3:
        constant = 3;
        break;
    case Opcodes.ICONST_4:
        constant = 4;
        break;
    case Opcodes.ICONST_5:
        constant = 5;
        break;
    case Opcodes.ICONST_M1:
        constant = -1;
        break;
    case Opcodes.LCONST_0:
        constant = 0L;
        break;
    case Opcodes.LCONST_1:
        constant = 1L;
        break;
    case Opcodes.DCONST_0:
        constant = 0.0;
        break;
    case Opcodes.DCONST_1:
        constant = 1.0;
        break;
    case Opcodes.FCONST_0:
        constant = 0f;
        break;
    case Opcodes.FCONST_1:
        constant = 1f;
        break;
    case Opcodes.FCONST_2:
        constant = 2f;
        break;
    }
    if (constant != null) {
        if (DependencyAnalysis.isTargetClassName(className)) {
            poolManager.addSUTConstant(constant);
        } else {
            poolManager.addNonSUTConstant(constant);
        }
    }
    super.visitInsn(opcode);
}

From source file:org.friz.bytecode.insn.InsnNodeUtility.java

License:Open Source License

/**
 * Creates a numeric push instruction./*from   w w  w  . j  av  a  2s . com*/
 * @param num The number to push.
 * @return The instruction node.
 */
public static AbstractInsnNode createNumericPushInsn(Number num) {
    long value = num.longValue();
    if (value == -1) {
        return new InsnNode(Opcodes.ICONST_M1);
    } else if (value == 0) {
        return new InsnNode(Opcodes.ICONST_0);
    } else if (value == 1) {
        return new InsnNode(Opcodes.ICONST_1);
    } else if (value == 2) {
        return new InsnNode(Opcodes.ICONST_2);
    } else if (value == 3) {
        return new InsnNode(Opcodes.ICONST_3);
    } else if (value == 4) {
        return new InsnNode(Opcodes.ICONST_4);
    } else if (value == 5) {
        return new InsnNode(Opcodes.ICONST_5);
    } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
        return new IntInsnNode(Opcodes.BIPUSH, (int) value);
    } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
        return new IntInsnNode(Opcodes.SIPUSH, (int) value);
    } else if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
        return new LdcInsnNode((int) value);
    } else {
        return new LdcInsnNode(/*(long)*/ value);
    }
}

From source file:org.friz.bytecode.insn.InsnNodeUtility.java

License:Open Source License

/**
 * Reads the value of a numeric push instruction (which can be an
 * {@code ICONST_*} instruction, an {@code BIPUSH} instruction, an
 * {@code SIPUSH} instruction or a {@code LDC_*} instruction.
 * @param push The instruction node./*from   ww w  . j ava  2 s.  c  o  m*/
 * @return The numeric value.
 */
public static long getNumericPushValue(AbstractInsnNode push) {
    if (push instanceof InsnNode) {
        switch (push.getOpcode()) {
        case Opcodes.ICONST_M1:
            return -1;
        case Opcodes.ICONST_0:
            return 0;
        case Opcodes.ICONST_1:
            return 1;
        case Opcodes.ICONST_2:
            return 2;
        case Opcodes.ICONST_3:
            return 3;
        case Opcodes.ICONST_4:
            return 4;
        case Opcodes.ICONST_5:
            return 5;
        default:
            throw new AssertionError();
        }
    } else if (push instanceof IntInsnNode) {
        return ((IntInsnNode) push).operand;
    } else {
        return ((Number) ((LdcInsnNode) push).cst).longValue();
    }
}

From source file:org.glassfish.pfl.tf.spi.Util.java

License:Open Source License

public void emitIntConstant(MethodVisitor mv, int val) {
    info(2, "Emitting constant " + val);
    if (val <= 5) {
        switch (val) {
        case 0:/* www .  ja v a 2 s. co  m*/
            mv.visitInsn(Opcodes.ICONST_0);
            break;
        case 1:
            mv.visitInsn(Opcodes.ICONST_1);
            break;
        case 2:
            mv.visitInsn(Opcodes.ICONST_2);
            break;
        case 3:
            mv.visitInsn(Opcodes.ICONST_3);
            break;
        case 4:
            mv.visitInsn(Opcodes.ICONST_4);
            break;
        case 5:
            mv.visitInsn(Opcodes.ICONST_5);
            break;
        }
    } else {
        mv.visitLdcInsn(val);
    }
}