Search in sources :

Example 6 with JumpInsnNode

use of org.objectweb.asm.tree.JumpInsnNode in project jphp by jphp-compiler.

the class WhileCompiler method write.

@Override
public void write(WhileStmtToken token) {
    expr.writeDefineVariables(token.getLocal());
    LabelNode start = expr.writeLabel(node, token.getMeta().getStartLine());
    LabelNode end = new LabelNode();
    expr.writeConditional(token.getCondition(), end);
    method.pushJump(end, start);
    expr.write(BodyStmtToken.class, token.getBody());
    method.popJump();
    add(new JumpInsnNode(GOTO, start));
    add(end);
    add(new LineNumberNode(token.getMeta().getEndLine(), end));
    expr.writeUndefineVariables(token.getLocal());
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LineNumberNode(org.objectweb.asm.tree.LineNumberNode)

Example 7 with JumpInsnNode

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

the class BooleanTestabilityTransformation method insertPushNull.

/**
 * Insert a call to the isNull helper function
 *
 * @param opcode
 * @param position
 * @param list
 */
public void insertPushNull(int opcode, JumpInsnNode position, InsnList list) {
    int branchId = getBranchID(currentMethodNode, position);
    logger.info("Inserting instrumentation for NULL check at branch " + branchId + " in method " + currentMethodNode.name);
    MethodInsnNode nullCheck = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "isNull", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Object.class), Type.INT_TYPE }), false);
    list.insertBefore(position, new InsnNode(Opcodes.DUP));
    list.insertBefore(position, new LdcInsnNode(opcode));
    list.insertBefore(position, nullCheck);
    // list.insertBefore(position,
    // new LdcInsnNode(getBranchID(currentMethodNode, position)));
    insertBranchIdPlaceholder(currentMethodNode, position, branchId);
    MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, push);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 8 with JumpInsnNode

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

the class BooleanTestabilityTransformation method insertPush2.

/**
 * Insert a call to the distance function for binary comparison
 *
 * @param opcode
 * @param position
 * @param list
 */
public void insertPush2(int opcode, JumpInsnNode position, InsnList list) {
    list.insertBefore(position, new InsnNode(Opcodes.DUP2));
    // list.insertBefore(position, new InsnNode(Opcodes.ISUB));
    MethodInsnNode sub = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intSub", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, sub);
    insertBranchIdPlaceholder(currentMethodNode, position);
    // list.insertBefore(position,
    // new LdcInsnNode(getBranchID(currentMethodNode, position)));
    MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, push);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 9 with JumpInsnNode

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

the class BranchInstrumentation method addDefaultCaseInstrumentation.

/**
 * <p>
 * addDefaultCaseInstrumentation
 * </p>
 *
 * @param v
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @param instrumentation
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 * @param mySwitch
 *            a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 * @param defaultLabel
 *            a {@link org.objectweb.asm.tree.LabelNode} object.
 * @param caseLabel
 *            a {@link org.objectweb.asm.tree.LabelNode} object.
 * @param endLabel
 *            a {@link org.objectweb.asm.tree.LabelNode} object.
 */
protected void addDefaultCaseInstrumentation(BytecodeInstruction v, InsnList instrumentation, AbstractInsnNode mySwitch, LabelNode defaultLabel, LabelNode caseLabel, LabelNode endLabel) {
    int defaultCaseBranchId = BranchPool.getInstance(classLoader).getDefaultBranchForSwitch(v).getActualBranchId();
    // add helper switch
    instrumentation.add(new InsnNode(Opcodes.DUP));
    instrumentation.add(mySwitch);
    // add call for default case not covered
    instrumentation.add(caseLabel);
    addDefaultCaseNotCoveredCall(v, instrumentation, defaultCaseBranchId);
    // jump over default (break)
    instrumentation.add(new JumpInsnNode(Opcodes.GOTO, endLabel));
    // add call for default case covered
    instrumentation.add(defaultLabel);
    addDefaultCaseCoveredCall(v, instrumentation, defaultCaseBranchId);
    instrumentation.add(endLabel);
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode)

Example 10 with JumpInsnNode

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

the class NegateCondition method apply.

/* (non-Javadoc)
	 * @see org.evosuite.cfg.instrumentation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
	 */
/**
 * {@inheritDoc}
 */
@Override
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) {
    List<Mutation> mutations = new LinkedList<Mutation>();
    JumpInsnNode node = (JumpInsnNode) instruction.getASMNode();
    LabelNode target = node.label;
    // insert mutation into bytecode with conditional
    JumpInsnNode mutation = new JumpInsnNode(getOpposite(node.getOpcode()), target);
    // insert mutation into pool
    Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME, instruction, mutation, Mutation.getDefaultInfectionDistance());
    mutations.add(mutationObject);
    return mutations;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) LinkedList(java.util.LinkedList)

Aggregations

JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)49 LabelNode (org.objectweb.asm.tree.LabelNode)36 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)28 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)26 InsnNode (org.objectweb.asm.tree.InsnNode)25 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)24 InsnList (org.objectweb.asm.tree.InsnList)22 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)18 MethodNode (org.objectweb.asm.tree.MethodNode)18 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 Label (org.objectweb.asm.Label)11 Type (org.objectweb.asm.Type)9 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)6 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)4 LinkedList (java.util.LinkedList)3 Mutation (org.evosuite.coverage.mutation.Mutation)3 FieldNode (org.objectweb.asm.tree.FieldNode)3