List of usage examples for org.objectweb.asm Opcodes IFNONNULL
int IFNONNULL
To view the source code for org.objectweb.asm Opcodes IFNONNULL.
Click Source Link
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitJumpInsn(final int opcode, final Label label) { T t = null;//from ww w .j av a2 s . c om Object oValue = null; final int targetPc = getPc(label); switch (opcode) { /******** * GOTO * ********/ case Opcodes.GOTO: { final GOTO op = new GOTO(this.ops.size(), opcode, this.line); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } break; } /******** * JCMP * ********/ case Opcodes.IF_ACMPEQ: t = T.REF; oValue = CmpType.T_EQ; // fall through case Opcodes.IF_ACMPNE: if (t == null) { t = T.REF; oValue = CmpType.T_NE; } // fall through case Opcodes.IF_ICMPEQ: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_EQ; } // fall through case Opcodes.IF_ICMPGE: if (t == null) { t = T.INT; oValue = CmpType.T_GE; } // fall through case Opcodes.IF_ICMPGT: if (t == null) { t = T.INT; oValue = CmpType.T_GT; } // fall through case Opcodes.IF_ICMPLE: if (t == null) { t = T.INT; oValue = CmpType.T_LE; } // fall through case Opcodes.IF_ICMPLT: if (t == null) { t = T.INT; oValue = CmpType.T_LT; } // fall through case Opcodes.IF_ICMPNE: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_NE; } { assert oValue instanceof CmpType; final JCMP op = new JCMP(this.ops.size(), opcode, this.line, t, (CmpType) oValue); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } } break; /******** * JCND * ********/ case Opcodes.IFNULL: t = T.REF; oValue = CmpType.T_EQ; // fall through case Opcodes.IFNONNULL: if (t == null) { t = T.REF; oValue = CmpType.T_NE; } // fall through case Opcodes.IFEQ: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_EQ; } // fall through case Opcodes.IFGE: if (t == null) { t = T.INT; oValue = CmpType.T_GE; } // fall through case Opcodes.IFGT: if (t == null) { t = T.INT; oValue = CmpType.T_GT; } // fall through case Opcodes.IFLE: if (t == null) { t = T.INT; oValue = CmpType.T_LE; } // fall through case Opcodes.IFLT: if (t == null) { t = T.INT; oValue = CmpType.T_LT; } // fall through case Opcodes.IFNE: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_NE; } { assert oValue instanceof CmpType; final JCND op = new JCND(this.ops.size(), opcode, this.line, t, (CmpType) oValue); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } } break; /******* * JSR * *******/ case Opcodes.JSR: { final JSR op = new JSR(this.ops.size(), opcode, this.line); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } break; } default: log.warn(getM() + ": Unknown jump insn opcode '" + opcode + "'!"); } }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AbstractCreateDispatchCodeAdapter.java
License:Open Source License
protected InsnList createInstructionsToCheackTeams(MethodNode method) { // if (teams == null) { // break; // }//from w w w . j a v a 2s.c om InsnList instructions = new InsnList(); instructions.add(new InsnNode(Opcodes.DUP)); LabelNode label = new LabelNode(); instructions.add(new JumpInsnNode(Opcodes.IFNONNULL, label)); instructions.add(new InsnNode(Opcodes.POP)); instructions.add(new JumpInsnNode(Opcodes.GOTO, findBreakLabel(method.instructions))); instructions.add(label); return instructions; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateAddRemoveRoleMethod.java
License:Open Source License
void genGetInitializedRoleSet(InsnList instructions, int targetLocal) { // x = this._OT$roleSet instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); instructions.add(new FieldInsnNode(Opcodes.GETFIELD, name, ConstantMembers.OT_ROLE_SET, ConstantMembers.HASH_SET_FIELD_TYPE)); instructions.add(new IntInsnNode(Opcodes.ASTORE, targetLocal)); instructions.add(new IntInsnNode(Opcodes.ALOAD, targetLocal)); // if (x == null) { LabelNode skipInstantiation = new LabelNode(); instructions.add(new JumpInsnNode(Opcodes.IFNONNULL, skipInstantiation)); // this._OT$roleSet = new HashSet(); instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); instructions.add(new TypeInsnNode(Opcodes.NEW, ClassNames.HASH_SET_SLASH)); instructions.add(new InsnNode(Opcodes.DUP)); instructions// ww w . j a va2s . c om .add(new MethodInsnNode(Opcodes.INVOKESPECIAL, ClassNames.HASH_SET_SLASH, "<init>", "()V", false)); instructions.add(new IntInsnNode(Opcodes.ASTORE, targetLocal)); instructions.add(new IntInsnNode(Opcodes.ALOAD, targetLocal)); instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, name, ConstantMembers.OT_ROLE_SET, ConstantMembers.HASH_SET_FIELD_TYPE)); instructions.add(skipInstantiation); // } }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateDispatchCodeInOrgMethodAdapter.java
License:Open Source License
@Override protected InsnList createInstructionsToCheackTeams(MethodNode method) { InsnList instructions = new InsnList(); instructions.add(new InsnNode(Opcodes.DUP)); LabelNode label = new LabelNode(); //if (teams == null) { instructions.add(new JumpInsnNode(Opcodes.IFNONNULL, label)); instructions.add(new InsnNode(Opcodes.POP)); //put the boundMethodId on the stack instructions.add(createLoadIntConstant(boundMethodId)); Type[] args = Type.getArgumentTypes(method.desc); // box the arguments instructions.add(getBoxingInstructions(args, (method.access & Opcodes.ACC_STATIC) != 0)); //callOrigStatic(boundMethodId, args); instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, name, ConstantMembers.callOrigStatic.getName(), ConstantMembers.callOrigStatic.getSignature())); Type returnType = Type.getReturnType(method.desc); instructions.add(getUnboxingInstructionsForReturnValue(returnType)); instructions.add(label);// w ww . j a va 2 s .co m return instructions; }
From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java
License:Open Source License
/** * Determine how many bytes the current instruction occupies together with * its operands/*from ww w. j a v a2s . com*/ * * @return */ private int getBytecodeIncrement(AbstractInsnNode instructionNode) { int opcode = instructionNode.getOpcode(); switch (opcode) { case Opcodes.ALOAD: // index case Opcodes.ASTORE: // index case Opcodes.DLOAD: case Opcodes.DSTORE: case Opcodes.FLOAD: case Opcodes.FSTORE: case Opcodes.ILOAD: case Opcodes.ISTORE: case Opcodes.LLOAD: case Opcodes.LSTORE: VarInsnNode varNode = (VarInsnNode) instructionNode; if (varNode.var > 3) return 1; else return 0; case Opcodes.BIPUSH: // byte case Opcodes.NEWARRAY: case Opcodes.RET: return 1; case Opcodes.LDC: LdcInsnNode ldcNode = (LdcInsnNode) instructionNode; if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long) return 2; // LDC2_W else return 1; case 19: //LDC_W case 20: //LDC2_W return 2; case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2 case Opcodes.CHECKCAST: // indexbyte1, indexbyte2 case Opcodes.GETFIELD: case Opcodes.GETSTATIC: case Opcodes.GOTO: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ICMPLT: case Opcodes.IFLE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFNE: case Opcodes.IFEQ: case Opcodes.IFNONNULL: case Opcodes.IFNULL: case Opcodes.IINC: case Opcodes.INSTANCEOF: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: case Opcodes.JSR: case Opcodes.NEW: case Opcodes.PUTFIELD: case Opcodes.PUTSTATIC: case Opcodes.SIPUSH: // case Opcodes.LDC_W // case Opcodes.LDC2_W return 2; case Opcodes.MULTIANEWARRAY: return 3; case Opcodes.INVOKEDYNAMIC: case Opcodes.INVOKEINTERFACE: return 4; case Opcodes.LOOKUPSWITCH: case Opcodes.TABLESWITCH: // TODO: Could be more return 4; // case Opcodes.GOTO_W // case Opcodes.JSR_W } return 0; }
From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>//from www . ja v a 2 s.c o m * getInstrumentation * </p> * * @param instruction * a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @return a {@link org.objectweb.asm.tree.InsnList} object. */ protected InsnList getInstrumentation(BytecodeInstruction instruction) { if (instruction == null) throw new IllegalArgumentException("null given"); if (!instruction.isActualBranch()) throw new IllegalArgumentException("branch instruction expected"); if (!BranchPool.getInstance(classLoader).isKnownAsNormalBranchInstruction(instruction)) throw new IllegalArgumentException( "expect given instruction to be known by the BranchPool as a normal branch instruction"); int opcode = instruction.getASMNode().getOpcode(); int instructionId = instruction.getInstructionId(); int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(instruction); if (branchId < 0) throw new IllegalStateException("expect BranchPool to know branchId for all branch instructions"); InsnList instrumentation = new InsnList(); switch (opcode) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: instrumentation.add(new InsnNode(Opcodes.DUP)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add( new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false)); logger.debug("Adding passedBranch val=?, opcode=" + opcode + ", branch=" + branchId + ", bytecode_id=" + instructionId); break; case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: instrumentation.add(new InsnNode(Opcodes.DUP2)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add( new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false)); break; case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: instrumentation.add(new InsnNode(Opcodes.DUP2)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(Ljava/lang/Object;Ljava/lang/Object;III)V", false)); break; case Opcodes.IFNULL: case Opcodes.IFNONNULL: instrumentation.add(new InsnNode(Opcodes.DUP)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(Ljava/lang/Object;III)V", false)); break; } return instrumentation; }
From source file:org.evosuite.instrumentation.error.NullPointerExceptionInstrumentation.java
License:Open Source License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { // If non-static, add a null check // TODO: Do we need to also check INVOKESPECIAL? if (opcode == Opcodes.INVOKEVIRTUAL || opcode == Opcodes.INVOKEINTERFACE) { Type[] args = Type.getArgumentTypes(desc); Map<Integer, Integer> to = new HashMap<Integer, Integer>(); for (int i = args.length - 1; i >= 0; i--) { int loc = mv.newLocal(args[i]); mv.storeLocal(loc);//from w w w.j a va 2 s. c o m to.put(i, loc); } mv.dup();//callee insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException"); for (int i = 0; i < args.length; i++) { mv.loadLocal(to.get(i)); } } }
From source file:org.evosuite.instrumentation.error.NullPointerExceptionInstrumentation.java
License:Open Source License
@Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { // If non-static, add a null check if (opcode == Opcodes.GETFIELD) { mv.visitInsn(Opcodes.DUP);//w w w. j a v a 2 s . c o m insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException"); } else if (opcode == Opcodes.PUTFIELD && !methodName.equals("<init>")) { if (Type.getType(desc).getSize() == 2) { // 2 words // v1 v2 v3 mv.visitInsn(Opcodes.DUP2_X1); // v2 v3 v1 v2 v3 mv.visitInsn(Opcodes.POP2); // v2 v3 v1 mv.visitInsn(Opcodes.DUP_X2); // v1 v2 v3 v1 } else { // 1 word mv.visitInsn(Opcodes.DUP2); //mv.visitInsn(Opcodes.SWAP); mv.visitInsn(Opcodes.POP); } insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException"); } }
From source file:org.evosuite.instrumentation.mutation.ReplaceComparisonOperator.java
License:Open Source License
private String getOp(int opcode) { switch (opcode) { case Opcodes.IFEQ: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ICMPEQ: return "=="; case Opcodes.IFNE: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPNE: return "!="; case Opcodes.IFLT: case Opcodes.IF_ICMPLT: return "<"; case Opcodes.IFLE: case Opcodes.IF_ICMPLE: return "<="; case Opcodes.IFGT: case Opcodes.IF_ICMPGT: return ">"; case Opcodes.IFGE: case Opcodes.IF_ICMPGE: return ">="; case Opcodes.IFNULL: return "= null"; case Opcodes.IFNONNULL: return "!= null"; }/*w ww .j av a2s . c o m*/ throw new RuntimeException("Unknown opcode: " + opcode); }
From source file:org.evosuite.instrumentation.testability.transformer.BooleanDistanceTransformer.java
License:Open Source License
@Override protected AbstractInsnNode transformJumpInsnNode(MethodNode mn, JumpInsnNode jumpNode) { switch (jumpNode.getOpcode()) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPush(jumpNode.getOpcode(), jumpNode, mn.instructions); break;/*from w w w . ja va 2 s. com*/ case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPush2(jumpNode.getOpcode(), jumpNode, mn.instructions); break; case Opcodes.IFNULL: case Opcodes.IFNONNULL: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPushNull(jumpNode.getOpcode(), jumpNode, mn.instructions); break; case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: TransformationStatistics.insertPush(jumpNode.getOpcode()); this.booleanTestabilityTransformation.insertPushEquals(jumpNode.getOpcode(), jumpNode, mn.instructions); break; default: // GOTO, JSR: Do nothing } return jumpNode; }