} else if (n instanceof InsnNode) { InsnNode insn = (InsnNode) n; switch (insn.getOpcode()) { case Opcodes.ICONST_0: return 0;
private void convertConstInsn(InsnNode insn) { int op = insn.getOpcode(); StackFrame frame = getFrame(insn); Operand[] out = frame.out();
private void convertReturnInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LRETURN || op == DRETURN; StackFrame frame = getFrame(insn); if (!units.containsKey(insn)) { Operand val = dword ? popImmediateDual() : popImmediate(); ReturnStmt ret = Jimple.v().newReturnStmt(val.stackOrValue()); val.addBox(ret.getOpBox()); frame.in(val); frame.boxes(ret.getOpBox()); setUnit(insn, ret); } else { frame.mergeIn(dword ? popDual() : pop()); } }
private void convertUnopInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LNEG || op == DNEG; StackFrame frame = getFrame(insn);
private void convertArrayStoreInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LASTORE || op == DASTORE; StackFrame frame = getFrame(insn); if (!units.containsKey(insn)) { Operand valu = dword ? popImmediateDual() : popImmediate(); Operand indx = popImmediate(); Operand base = popLocal(); ArrayRef ar = Jimple.v().newArrayRef(base.stackOrValue(), indx.stackOrValue()); indx.addBox(ar.getIndexBox()); base.addBox(ar.getBaseBox()); AssignStmt as = Jimple.v().newAssignStmt(ar, valu.stackOrValue()); valu.addBox(as.getRightOpBox()); frame.in(valu, indx, base); frame.boxes(as.getRightOpBox(), ar.getIndexBox(), ar.getBaseBox()); setUnit(insn, as); } else { frame.mergeIn(dword ? popDual() : pop(), pop(), pop()); } }
private void convertInsn(InsnNode insn) { int op = insn.getOpcode(); if (op == NOP) {
private void convertPrimCastInsn(InsnNode insn) { int op = insn.getOpcode(); boolean tod = op == I2L || op == I2D || op == F2L || op == F2D || op == D2L || op == L2D; boolean fromd = op == D2L || op == L2D || op == D2I || op == L2I || op == D2F || op == L2F;
private void convertArrayLoadInsn(InsnNode insn) { StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Operand indx = popImmediate(); Operand base = popImmediate(); ArrayRef ar = Jimple.v().newArrayRef(base.stackOrValue(), indx.stackOrValue()); indx.addBox(ar.getIndexBox()); base.addBox(ar.getBaseBox()); opr = new Operand(insn, ar); frame.in(indx, base); frame.boxes(ar.getIndexBox(), ar.getBaseBox()); frame.out(opr); } else { opr = out[0]; frame.mergeIn(pop(), pop()); } int op = insn.getOpcode(); if (op == DALOAD || op == LALOAD) { pushDual(opr); } else { push(opr); } }
private void convertDupInsn(InsnNode insn) { int op = insn.getOpcode();
private void convertBinopInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == DADD || op == LADD || op == DSUB || op == LSUB || op == DMUL || op == LMUL || op == DDIV || op == LDIV || op == DREM || op == LREM || op == LSHL || op == LSHR || op == LUSHR || op == LAND || op == LOR
/** * We try to detect such a last 2 instructions and extract the enum signature. */ private String tryToFindSignatureOfConditionEnum() { // mv.visitMethodInsn(INVOKESTATIC, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter", "$SWITCH_TABLE$net$sourceforge$cobertura$instrument$FindTouchPointsMethodAdapter$Abc", "()[I"); // mv.visitVarInsn(ALOAD, 1); // mv.visitMethodInsn(INVOKEVIRTUAL, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter$Abc", "ordinal", "()I"); // mv.visitInsn(IALOAD); if (backlog == null || backlog.size() < 4) return null; int last = backlog.size() - 1; if ((backlog.get(last) instanceof InsnNode) && (backlog.get(last - 1) instanceof MethodInsnNode) && (backlog.get(last - 2) instanceof VarInsnNode)) { VarInsnNode i2 = (VarInsnNode) backlog.get(last - 2); MethodInsnNode i3 = (MethodInsnNode) backlog.get(last - 1); InsnNode i4 = (InsnNode) backlog.get(last); if ((i2.getOpcode() == Opcodes.ALOAD) && (i3.getOpcode() == Opcodes.INVOKEVIRTUAL && i3.name .equals("ordinal")) && (i4.getOpcode() == Opcodes.IALOAD)) { return i3.owner; } } return null; }
if (opcodesInt.contains(node.getOpcode())) replacement.addAll(opcodesInt); else if (opcodesIntShift.contains(node.getOpcode())) replacement.addAll(opcodesIntShift); else if (opcodesLong.contains(node.getOpcode())) replacement.addAll(opcodesLong); else if (opcodesLongShift.contains(node.getOpcode())) replacement.addAll(opcodesLongShift); replacement.remove(node.getOpcode()); methodName, NAME + " " + getOp(node.getOpcode()) + " -> " + getOp(opcode), instruction, mutation, getInfectionDistance(node.getOpcode(), opcode)); mutations.add(mutationObject);
/** * We try to detect such a last 2 instructions and extract the enum signature. */ private String tryToFindSignatureOfConditionEnum() { // mv.visitMethodInsn(INVOKESTATIC, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter", "$SWITCH_TABLE$net$sourceforge$cobertura$instrument$FindTouchPointsMethodAdapter$Abc", "()[I"); // mv.visitVarInsn(ALOAD, 1); // mv.visitMethodInsn(INVOKEVIRTUAL, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter$Abc", "ordinal", "()I"); // mv.visitInsn(IALOAD); if (backlog == null || backlog.size() < 4) return null; int last = backlog.size() - 1; if ((backlog.get(last) instanceof InsnNode) && (backlog.get(last - 1) instanceof MethodInsnNode) && (backlog.get(last - 2) instanceof VarInsnNode)) { VarInsnNode i2 = (VarInsnNode) backlog.get(last - 2); MethodInsnNode i3 = (MethodInsnNode) backlog.get(last - 1); InsnNode i4 = (InsnNode) backlog.get(last); if ((i2.getOpcode() == Opcodes.ALOAD) && (i3.getOpcode() == Opcodes.INVOKEVIRTUAL && i3.name .equals("ordinal")) && (i4.getOpcode() == Opcodes.IALOAD)) { return i3.owner; } } return null; }
@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); } return insnNode; }
/** {@inheritDoc} */ @Override public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) { numVariable = getNextIndex(mn); List<Mutation> mutations = new LinkedList<Mutation>(); InsnNode node = (InsnNode) instruction.getASMNode(); for (int opcode : getMutations(node.getOpcode())) { InsnNode mutation = new InsnNode(opcode); // insert mutation into pool Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME + " " + getOp(node.getOpcode()) + " -> " + getOp(opcode), instruction, mutation, getInfectionDistance(node.getOpcode(), opcode)); mutations.add(mutationObject); } return mutations; }
@Override protected AbstractInsnNode transformInsnNode(MethodNode mn, InsnNode insnNode) { //String desc = DescriptorMapping.getInstance().getMethodDesc(className, mn.name, mn.desc); Type returnType = Type.getReturnType(mn.desc); if (!returnType.equals(Type.BOOLEAN_TYPE)) { return insnNode; } if (insnNode.getOpcode() == Opcodes.IRETURN) { BooleanTestabilityTransformation.logger.debug("Inserting conversion before IRETURN of " + this.booleanTestabilityTransformation.className + "." + mn.name); // If this function cannot be transformed, add a call to convert the value to a proper Boolean MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intToBoolean", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { Type.INT_TYPE })); mn.instructions.insertBefore(insnNode, n); } return insnNode; } }
if (node instanceof InsnNode) { InsnNode in = (InsnNode) node; if (in.getOpcode() == Opcodes.LCMP) { insertLongComparison(in, mn.instructions); TransformationStatistics.transformedComparison(); } else if (in.getOpcode() == Opcodes.DCMPG) { TransformationStatistics.transformedComparison(); insertDoubleComparisonG(in, mn.instructions); } else if (in.getOpcode() == Opcodes.DCMPL) { TransformationStatistics.transformedComparison(); insertDoubleComparisonL(in, mn.instructions); } else if (in.getOpcode() == Opcodes.FCMPG) { TransformationStatistics.transformedComparison(); insertFloatComparisonG(in, mn.instructions); } else if (in.getOpcode() == Opcodes.FCMPL) { TransformationStatistics.transformedComparison(); insertFloatComparisonL(in, mn.instructions);
@Override protected AbstractInsnNode transformInsnNode(MethodNode mn, InsnNode insnNode) { if (insnNode.getOpcode() == Opcodes.IOR || insnNode.getOpcode() == Opcodes.IAND || insnNode.getOpcode() == Opcodes.IXOR) { if (insnNode.getOpcode() == Opcodes.IOR) { MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "IOR", TransformationStatistics.transformedBitwise(); return push; } else if (insnNode.getOpcode() == Opcodes.IAND) { MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "IAND", return push; } else if (insnNode.getOpcode() == Opcodes.IXOR) { MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "IXOR",
} else if (ai instanceof InsnNode) { InsnNode n = ((InsnNode)ai); writer.write("\n\t\t\t\tinstruction(" + n.getOpcode() + ")"); } else if (ai instanceof IntInsnNode) { IntInsnNode n = ((IntInsnNode)ai);
@Override protected AbstractInsnNode transformInsnNode(MethodNode mn, InsnNode insnNode) { if (frames == null) { return insnNode; } if (insnNode.getOpcode() == Opcodes.BALOAD) { Frame current = frames[mn.instructions.indexOf(insnNode)]; int size = current.getStackSize(); if (current.getStack(size - 2) == BooleanArrayInterpreter.INT_ARRAY) { BooleanTestabilityTransformation.logger.info("Array is of boolean type, changing BALOAD to IALOAD"); InsnNode replacement = new InsnNode(Opcodes.IALOAD); mn.instructions.insertBefore(insnNode, replacement); mn.instructions.remove(insnNode); return replacement; } } else if (insnNode.getOpcode() == Opcodes.BASTORE) { Frame current = frames[mn.instructions.indexOf(insnNode)]; int size = current.getStackSize(); if (current.getStack(size - 3) == BooleanArrayInterpreter.INT_ARRAY) { BooleanTestabilityTransformation.logger.info("Array is of boolean type, changing BASTORE to IASTORE"); InsnNode replacement = new InsnNode(Opcodes.IASTORE); mn.instructions.insertBefore(insnNode, replacement); mn.instructions.remove(insnNode); return replacement; } } return insnNode; }