List of usage examples for org.objectweb.asm Opcodes DUP2
int DUP2
To view the source code for org.objectweb.asm Opcodes DUP2.
Click Source Link
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitInsn(final int opcode) { T t = null;//from www. ja va 2 s. c om int iValue = Integer.MIN_VALUE; Object oValue = null; switch (opcode) { case Opcodes.NOP: // nothing to do, ignore break; /******* * ADD * *******/ case Opcodes.DADD: t = T.DOUBLE; // fall through case Opcodes.FADD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IADD: if (t == null) { t = T.INT; } // fall through case Opcodes.LADD: if (t == null) { t = T.LONG; } add(new ADD(this.ops.size(), opcode, this.line, t)); break; /********* * ALOAD * *********/ case Opcodes.AALOAD: t = T.REF; // fall through case Opcodes.BALOAD: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CALOAD: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DALOAD: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FALOAD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IALOAD: if (t == null) { t = T.INT; } // fall through case Opcodes.LALOAD: if (t == null) { t = T.LONG; } // fall through case Opcodes.SALOAD: if (t == null) { t = T.SHORT; } add(new ALOAD(this.ops.size(), opcode, this.line, t)); break; /******* * AND * *******/ case Opcodes.IAND: t = T.AINT; // fall through case Opcodes.LAND: if (t == null) { t = T.LONG; } add(new AND(this.ops.size(), opcode, this.line, t)); break; /*************** * ARRAYLENGTH * ***************/ case Opcodes.ARRAYLENGTH: add(new ARRAYLENGTH(this.ops.size(), opcode, this.line)); break; /********** * ASTORE * **********/ case Opcodes.AASTORE: t = T.REF; // fall through case Opcodes.BASTORE: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CASTORE: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DASTORE: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FASTORE: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IASTORE: if (t == null) { t = T.INT; } // fall through case Opcodes.LASTORE: if (t == null) { t = T.LONG; } // fall through case Opcodes.SASTORE: if (t == null) { t = T.SHORT; } add(new ASTORE(this.ops.size(), opcode, this.line, t)); break; /******** * CAST * ********/ case Opcodes.D2F: t = T.DOUBLE; oValue = T.FLOAT; // fall through case Opcodes.D2I: if (t == null) { t = T.DOUBLE; oValue = T.INT; } // fall through case Opcodes.D2L: if (t == null) { t = T.DOUBLE; oValue = T.LONG; } // fall through case Opcodes.F2D: if (t == null) { t = T.FLOAT; oValue = T.DOUBLE; } // fall through case Opcodes.F2I: if (t == null) { t = T.FLOAT; oValue = T.INT; } // fall through case Opcodes.F2L: if (t == null) { t = T.FLOAT; oValue = T.LONG; } // fall through case Opcodes.I2B: if (t == null) { t = T.INT; oValue = T.BYTE; } // fall through case Opcodes.I2C: if (t == null) { t = T.INT; oValue = T.CHAR; } // fall through case Opcodes.I2D: if (t == null) { t = T.INT; oValue = T.DOUBLE; } // fall through case Opcodes.I2F: if (t == null) { t = T.INT; oValue = T.FLOAT; } // fall through case Opcodes.I2L: if (t == null) { t = T.INT; oValue = T.LONG; } // fall through case Opcodes.I2S: if (t == null) { t = T.INT; oValue = T.SHORT; } // fall through case Opcodes.L2D: if (t == null) { t = T.LONG; oValue = T.DOUBLE; } // fall through case Opcodes.L2F: if (t == null) { t = T.LONG; oValue = T.FLOAT; } // fall through case Opcodes.L2I: if (t == null) { t = T.LONG; oValue = T.INT; } assert oValue instanceof T; add(new CAST(this.ops.size(), opcode, this.line, t, (T) oValue)); break; /******* * CMP * *******/ case Opcodes.DCMPG: t = T.DOUBLE; iValue = CMP.T_G; // fall through case Opcodes.DCMPL: if (t == null) { t = T.DOUBLE; iValue = CMP.T_L; } // fall through case Opcodes.FCMPG: if (t == null) { t = T.FLOAT; iValue = CMP.T_G; } // fall through case Opcodes.FCMPL: if (t == null) { t = T.FLOAT; iValue = CMP.T_L; } // fall through case Opcodes.LCMP: if (t == null) { t = T.LONG; iValue = CMP.T_0; } add(new CMP(this.ops.size(), opcode, this.line, t, iValue)); break; /******* * DIV * *******/ case Opcodes.DDIV: t = T.DOUBLE; // fall through case Opcodes.FDIV: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IDIV: if (t == null) { t = T.INT; } // fall through case Opcodes.LDIV: if (t == null) { t = T.LONG; } add(new DIV(this.ops.size(), opcode, this.line, t)); break; /******* * DUP * *******/ case Opcodes.DUP: oValue = DUP.Kind.DUP; // fall through case Opcodes.DUP_X1: if (oValue == null) { oValue = DUP.Kind.DUP_X1; } // fall through case Opcodes.DUP_X2: if (oValue == null) { oValue = DUP.Kind.DUP_X2; } // fall through case Opcodes.DUP2: if (oValue == null) { oValue = DUP.Kind.DUP2; } // fall through case Opcodes.DUP2_X1: if (oValue == null) { oValue = DUP.Kind.DUP2_X1; } // fall through case Opcodes.DUP2_X2: if (oValue == null) { oValue = DUP.Kind.DUP2_X2; } add(new DUP(this.ops.size(), opcode, this.line, (DUP.Kind) oValue)); break; /*********** * MONITOR * ***********/ case Opcodes.MONITORENTER: oValue = MONITOR.Kind.ENTER; // fall through case Opcodes.MONITOREXIT: if (oValue == null) { oValue = MONITOR.Kind.EXIT; } add(new MONITOR(this.ops.size(), opcode, this.line, (MONITOR.Kind) oValue)); break; /******* * MUL * *******/ case Opcodes.DMUL: t = T.DOUBLE; // fall through case Opcodes.FMUL: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IMUL: if (t == null) { t = T.INT; } // fall through case Opcodes.LMUL: if (t == null) { t = T.LONG; } add(new MUL(this.ops.size(), opcode, this.line, t)); break; /******* * NEG * *******/ case Opcodes.DNEG: t = T.DOUBLE; // fall through case Opcodes.FNEG: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.INEG: if (t == null) { t = T.INT; } // fall through case Opcodes.LNEG: if (t == null) { t = T.LONG; } add(new NEG(this.ops.size(), opcode, this.line, t)); break; /****** * OR * ******/ case Opcodes.IOR: t = T.AINT; // fall through case Opcodes.LOR: if (t == null) { t = T.LONG; } add(new OR(this.ops.size(), opcode, this.line, t)); break; /******* * POP * *******/ case Opcodes.POP: oValue = POP.Kind.POP; // fall through case Opcodes.POP2: if (oValue == null) { oValue = POP.Kind.POP2; } add(new POP(this.ops.size(), opcode, this.line, (POP.Kind) oValue)); break; /******** * PUSH * ********/ case Opcodes.ACONST_NULL: t = T.REF; // fall through case Opcodes.DCONST_0: if (t == null) { oValue = 0D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_0: if (t == null) { oValue = 0F; t = T.FLOAT; } // fall through case Opcodes.ICONST_0: if (t == null) { oValue = 0; t = T.getJvmIntT(0); } // fall through case Opcodes.LCONST_0: if (t == null) { oValue = 0L; t = T.LONG; } // fall through case Opcodes.DCONST_1: if (t == null) { oValue = 1D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_1: if (t == null) { oValue = 1F; t = T.FLOAT; } // fall through case Opcodes.ICONST_1: if (t == null) { oValue = 1; t = T.getJvmIntT(1); } // fall through case Opcodes.LCONST_1: if (t == null) { oValue = 1L; t = T.LONG; } // fall through case Opcodes.FCONST_2: if (t == null) { oValue = 2F; t = T.FLOAT; } // fall through case Opcodes.ICONST_2: if (t == null) { oValue = 2; t = T.getJvmIntT(2); } // fall through case Opcodes.ICONST_3: if (t == null) { oValue = 3; t = T.getJvmIntT(3); } // fall through case Opcodes.ICONST_4: if (t == null) { oValue = 4; t = T.getJvmIntT(4); } // fall through case Opcodes.ICONST_5: if (t == null) { oValue = 5; t = T.getJvmIntT(5); } // fall through case Opcodes.ICONST_M1: if (t == null) { oValue = -1; t = T.getJvmIntT(-1); } add(new PUSH(this.ops.size(), opcode, this.line, t, oValue)); break; /******* * REM * *******/ case Opcodes.DREM: t = T.DOUBLE; // fall through case Opcodes.FREM: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IREM: if (t == null) { t = T.INT; } // fall through case Opcodes.LREM: if (t == null) { t = T.LONG; } add(new REM(this.ops.size(), opcode, this.line, t)); break; /********** * RETURN * **********/ case Opcodes.ARETURN: t = T.REF; // fall through case Opcodes.DRETURN: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FRETURN: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IRETURN: if (t == null) { t = T.AINT; } // fall through case Opcodes.LRETURN: if (t == null) { t = T.LONG; } // fall through case Opcodes.RETURN: if (t == null) { t = T.VOID; } add(new RETURN(this.ops.size(), opcode, this.line, t)); break; /******* * SHL * *******/ case Opcodes.ISHL: t = T.INT; // fall through case Opcodes.LSHL: if (t == null) { t = T.LONG; } add(new SHL(this.ops.size(), opcode, this.line, t, T.INT)); break; /******* * SHR * *******/ case Opcodes.ISHR: case Opcodes.IUSHR: t = T.INT; // fall through case Opcodes.LSHR: case Opcodes.LUSHR: if (t == null) { t = T.LONG; } add(new SHR(this.ops.size(), opcode, this.line, t, T.INT, opcode == Opcodes.IUSHR || opcode == Opcodes.LUSHR)); break; /******* * SUB * *******/ case Opcodes.DSUB: t = T.DOUBLE; // fall through case Opcodes.FSUB: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.ISUB: if (t == null) { t = T.INT; } // fall through case Opcodes.LSUB: if (t == null) { t = T.LONG; } add(new SUB(this.ops.size(), opcode, this.line, t)); break; /******** * SWAP * ********/ case Opcodes.SWAP: add(new SWAP(this.ops.size(), opcode, this.line)); break; /********* * THROW * *********/ case Opcodes.ATHROW: add(new THROW(this.ops.size(), opcode, this.line)); break; /******* * XOR * *******/ case Opcodes.IXOR: t = T.AINT; // fall through case Opcodes.LXOR: { if (t == null) { t = T.LONG; } add(new XOR(this.ops.size(), opcode, this.line, t)); break; } default: log.warn(getM() + ": Unknown insn opcode '" + opcode + "'!"); } }
From source file:org.elasticsearch.plan.a.External.java
License:Apache License
private void variable(final ParserRuleContext source, final String name, final boolean last) { final Variable variable = adapter.getVariable(name); if (variable == null) { throw new IllegalArgumentException(error(source) + "Unknown variable [" + name + "]."); }/*from w w w.j a va 2 s .c om*/ final Type type = variable.type; if (last && write != null) { final ExpressionMetadata writeemd = adapter.createExpressionMetadata(write); if (token == CAT) { writeemd.promotion = caster.concat; analyzer.visit(write); writeemd.to = writeemd.from; caster.markCast(writeemd); final Cast cast = caster.getLegalCast(source, standard.stringType, type, false); segments.add(new VariableSegment(source, variable, false)); segments.add(new AppendStringsSegment(source, type, true)); segments.add(new NodeSegment(write)); segments.add(new AppendStringsSegment(write, writeemd.to, false)); segments.add(new ToStringsSegment(source)); segments.add(new CastSegment(source, cast)); if (read) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new VariableSegment(source, variable, true)); } else if (token > 0) { final boolean increment = type.metadata == TypeMetadata.INT && (token == ADD || token == SUB); current = type; final Cast[] casts = toNumericCasts(source); writeemd.to = current; analyzer.visit(write); if (increment && writeemd.postConst != null) { if (read && post) { segments.add(new VariableSegment(source, variable, false)); } final int value = token == SUB ? -1 * (int) writeemd.postConst : (int) writeemd.postConst; segments.add(new IncrementSegment(source, variable, value)); if (read && !post) { segments.add(new VariableSegment(source, variable, false)); } } else { segments.add(new VariableSegment(source, variable, false)); if (read && post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new CastSegment(source, casts[0])); segments.add(new NodeSegment(write)); segments.add(new TokenSegment(source, current, token)); segments.add(new CastSegment(source, casts[1])); if (read && !post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new VariableSegment(source, variable, true)); } } else { writeemd.to = type; analyzer.visit(write); segments.add(new NodeSegment(write)); if (read && !post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new VariableSegment(source, variable, true)); } current = read ? type : standard.voidType; } else { segments.add(new VariableSegment(source, variable, false)); current = variable.type; } }
From source file:org.elasticsearch.plan.a.External.java
License:Apache License
private void array(final ParserRuleContext source, final ExpressionContext exprctx, final boolean last) { if (current.dimensions == 0) { throw new IllegalArgumentException( error(source) + "Attempting to address a non-array type [" + current.name + "] as an array."); }//from w w w .j a va 2 s.c om final ExpressionMetadata expremd = adapter.createExpressionMetadata(exprctx); expremd.to = standard.intType; analyzer.visit(exprctx); segments.add(new NodeSegment(exprctx)); final Type type = getTypeWithArrayDimensions(current.struct, current.dimensions - 1); if (last && write != null) { final ExpressionMetadata writeemd = adapter.createExpressionMetadata(write); if (token == CAT) { writeemd.promotion = caster.concat; analyzer.visit(write); writeemd.to = writeemd.from; caster.markCast(writeemd); final Cast cast = caster.getLegalCast(source, standard.stringType, type, false); segments.add(new InstructionSegment(source, Opcodes.DUP2_X1)); segments.add(new ArraySegment(source, type, false)); segments.add(new AppendStringsSegment(source, type, true)); segments.add(new NodeSegment(write)); segments.add(new AppendStringsSegment(write, writeemd.to, false)); segments.add(new ToStringsSegment(source)); segments.add(new CastSegment(source, cast)); if (read) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new ArraySegment(source, type, true)); } else if (token > 0) { current = type; final Cast[] casts = toNumericCasts(source); writeemd.to = current; analyzer.visit(write); segments.add(new InstructionSegment(source, Opcodes.DUP2)); segments.add(new ArraySegment(source, type, false)); if (read && post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new CastSegment(source, casts[0])); segments.add(new NodeSegment(write)); segments.add(new TokenSegment(source, current, token)); segments.add(new CastSegment(source, casts[1])); if (read && !post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new ArraySegment(source, type, true)); } else { writeemd.to = type; analyzer.visit(write); segments.add(new NodeSegment(write)); if (read && !post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new ArraySegment(source, type, true)); } current = read ? type : standard.voidType; } else { segments.add(new ArraySegment(source, type, false)); current = type; } }
From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java
License:Open Source License
/** * Insert a call to the reference equality check helper function * //from w w w .j a v a 2s . c om * @param opcode * @param position * @param list */ public void insertPushEquals(int opcode, JumpInsnNode position, InsnList list) { MethodInsnNode equalCheck = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "isEqual", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Object.class), Type.getType(Object.class), Type.INT_TYPE })); list.insertBefore(position, new InsnNode(Opcodes.DUP2)); list.insertBefore(position, new LdcInsnNode(opcode)); list.insertBefore(position, equalCheck); //list.insertBefore(position, // new LdcInsnNode(getBranchID(currentMethodNode, position))); insertBranchIdPlaceholder(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 })); list.insertBefore(position, push); }
From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java
License:Open Source License
/** * Insert a call to the distance function for binary comparison * /*from ww w . j a v a2s .c o m*/ * @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 })); 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 })); list.insertBefore(position, push); }
From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>/*from ww w.jav a2s . 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.ArrayInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { // Check array accesses if (opcode == Opcodes.IALOAD || opcode == Opcodes.BALOAD || opcode == Opcodes.CALOAD || opcode == Opcodes.SALOAD || opcode == Opcodes.LALOAD || opcode == Opcodes.FALOAD || opcode == Opcodes.DALOAD || opcode == Opcodes.AALOAD) { mv.visitInsn(Opcodes.DUP);/*from w w w . j av a2 s . co m*/ insertBranch(Opcodes.IFGE, "java/lang/ArrayIndexOutOfBoundsException"); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.SWAP); //mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.ARRAYLENGTH); insertBranch(Opcodes.IF_ICMPLT, "java/lang/ArrayIndexOutOfBoundsException"); } else if (opcode == Opcodes.IASTORE || opcode == Opcodes.BASTORE || opcode == Opcodes.CASTORE || opcode == Opcodes.SASTORE || opcode == Opcodes.AASTORE || opcode == Opcodes.LASTORE || opcode == Opcodes.FASTORE || opcode == Opcodes.DASTORE) { int loc = 0; if (opcode == Opcodes.IASTORE) loc = mv.newLocal(Type.INT_TYPE); else if (opcode == Opcodes.BASTORE) loc = mv.newLocal(Type.BYTE_TYPE); else if (opcode == Opcodes.CASTORE) loc = mv.newLocal(Type.CHAR_TYPE); else if (opcode == Opcodes.SASTORE) loc = mv.newLocal(Type.SHORT_TYPE); else if (opcode == Opcodes.AASTORE) loc = mv.newLocal(Type.getType(Object.class)); else if (opcode == Opcodes.LASTORE) loc = mv.newLocal(Type.LONG_TYPE); else if (opcode == Opcodes.FASTORE) loc = mv.newLocal(Type.FLOAT_TYPE); else if (opcode == Opcodes.DASTORE) loc = mv.newLocal(Type.DOUBLE_TYPE); else throw new RuntimeException("Unknown type"); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP); insertBranch(Opcodes.IFGE, "java/lang/ArrayIndexOutOfBoundsException"); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.SWAP); //mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.ARRAYLENGTH); insertBranch(Opcodes.IF_ICMPLT, "java/lang/ArrayIndexOutOfBoundsException"); mv.loadLocal(loc); } }
From source file:org.evosuite.instrumentation.error.DivisionByZeroInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { // Check *DIV for divisonbyzero if (opcode == Opcodes.IDIV || opcode == Opcodes.IREM) { mv.visitInsn(Opcodes.DUP);//from www .ja v a2 s. co m insertBranch(Opcodes.IFNE, "java/lang/ArithmeticException"); } else if (opcode == Opcodes.LDIV || opcode == Opcodes.LREM) { mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(0L); mv.visitInsn(Opcodes.LCMP); insertBranch(Opcodes.IFNE, "java/lang/ArithmeticException"); } }
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 ava 2s . c om*/ 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.error.OverflowInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { // Overflow checks switch (opcode) { case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode);//from www .ja v a 2 s.c o m mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(III)I", false); insertBranchWithoutException(Opcodes.IFGT); case Opcodes.IDIV: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(III)I", false); insertBranchWithoutException(Opcodes.IFGT); break; case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(FFI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.FDIV: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(FFI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: int loc = mv.newLocal(Type.DOUBLE_TYPE); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(DDI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.DDIV: loc = mv.newLocal(Type.DOUBLE_TYPE); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(DDI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: int loc2 = mv.newLocal(Type.LONG_TYPE); mv.storeLocal(loc2); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc2); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(JJI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.LDIV: loc2 = mv.newLocal(Type.LONG_TYPE); mv.storeLocal(loc2); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc2); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(JJI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; } }