List of usage examples for org.objectweb.asm Opcodes DUP
int DUP
To view the source code for org.objectweb.asm Opcodes DUP.
Click Source Link
From source file:org.evosuite.instrumentation.ArrayAllocationLimitMethodAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w.ja v a2 s . c o m public void visitIntInsn(int opcode, int operand) { if (opcode == Opcodes.NEWARRAY) { Label origTarget = new Label(); visitInsn(Opcodes.DUP); visitFieldInsn(Opcodes.GETSTATIC, PackageInfo.getNameWithSlash(org.evosuite.Properties.class), "ARRAY_LIMIT", "I"); super.visitJumpInsn(Opcodes.IF_ICMPLT, origTarget); super.visitTypeInsn(Opcodes.NEW, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class)); super.visitInsn(Opcodes.DUP); super.visitMethodInsn(Opcodes.INVOKESPECIAL, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class), "<init>", "()V", false); super.visitInsn(Opcodes.ATHROW); super.visitLabel(origTarget); } super.visitIntInsn(opcode, operand); }
From source file:org.evosuite.instrumentation.ArrayAllocationLimitMethodAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w . j av a 2s . c o m*/ public void visitTypeInsn(int opcode, String type) { if (opcode == Opcodes.ANEWARRAY) { Label origTarget = new Label(); visitInsn(Opcodes.DUP); visitFieldInsn(Opcodes.GETSTATIC, PackageInfo.getNameWithSlash(org.evosuite.Properties.class), "ARRAY_LIMIT", "I"); super.visitJumpInsn(Opcodes.IF_ICMPLT, origTarget); super.visitTypeInsn(Opcodes.NEW, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class)); super.visitInsn(Opcodes.DUP); super.visitMethodInsn(Opcodes.INVOKESPECIAL, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class), "<init>", "()V", false); super.visitInsn(Opcodes.ATHROW); super.visitLabel(origTarget); } super.visitTypeInsn(opcode, type); }
From source file:org.evosuite.instrumentation.ArrayAllocationLimitMethodAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w. j a v a 2 s. c o m public void visitMultiANewArrayInsn(String desc, int dims) { Label origTarget = new Label(); Label errorTarget = new Label(); // Multidimensional arrays can only have max 256 dimensions if (Properties.ARRAY_LIMIT < 256) { push(dims); visitFieldInsn(Opcodes.GETSTATIC, PackageInfo.getNameWithSlash(org.evosuite.Properties.class), "ARRAY_LIMIT", "I"); super.visitJumpInsn(Opcodes.IF_ICMPGE, errorTarget); } // Check each of the dimensions Map<Integer, Integer> to = new HashMap<Integer, Integer>(); for (int i = dims - 1; i >= 0; i--) { int loc = newLocal(Type.INT_TYPE); storeLocal(loc); to.put(i, loc); } for (int i = 0; i < dims; i++) { loadLocal(to.get(i)); visitFieldInsn(Opcodes.GETSTATIC, "org/evosuite/Properties", "ARRAY_LIMIT", "I"); super.visitJumpInsn(Opcodes.IF_ICMPGE, errorTarget); } goTo(origTarget); super.visitLabel(errorTarget); super.visitTypeInsn(Opcodes.NEW, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class)); super.visitInsn(Opcodes.DUP); super.visitMethodInsn(Opcodes.INVOKESPECIAL, PackageInfo.getNameWithSlash(TestCaseExecutor.TimeoutExceeded.class), "<init>", "()V", false); super.visitInsn(Opcodes.ATHROW); super.visitLabel(origTarget); // Restore original dimensions for (int i = 0; i < dims; i++) { loadLocal(to.get(i)); } super.visitMultiANewArrayInsn(desc, dims); }
From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java
License:Open Source License
/** * Insert a call to the isNull helper function * /*from w w w . j av a 2s. co m*/ * @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 {} in method {}", branchId, 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 })); 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 })); list.insertBefore(position, push); }
From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java
License:Open Source License
/** * Insert a call to the distance function for unary comparison * //from www.j a va2s . co m * @param opcode * @param position * @param list */ public void insertPush(int opcode, JumpInsnNode position, InsnList list) { list.insertBefore(position, new InsnNode(Opcodes.DUP)); // TODO: We have to put a placeholder here instead of the actual branch ID // TODO: And then later add another transformation where we replace this with // actual branch IDs //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.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>/*from w ww . j av a 2s . 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.coverage.BranchInstrumentation.java
License:Open Source License
/** * For each actual case <key>: of a switch this method adds instrumentation * for the Branch corresponding to that case to the given instruction list. * * @param v//from w w w.j a v a 2 s. c o m * a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @param instrumentation * a {@link org.objectweb.asm.tree.InsnList} object. * @param className * a {@link java.lang.String} object. * @param methodName * a {@link java.lang.String} object. */ protected void addInstrumentationForSwitchCases(BytecodeInstruction v, InsnList instrumentation, String className, String methodName) { if (!v.isSwitch()) throw new IllegalArgumentException("switch instruction expected"); List<Branch> caseBranches = BranchPool.getInstance(classLoader).getCaseBranchesForSwitch(v); if (caseBranches == null || caseBranches.isEmpty()) throw new IllegalStateException( "expect BranchPool to know at least one Branch for each switch instruction"); for (Branch targetCaseBranch : caseBranches) { if (targetCaseBranch.isDefaultCase()) continue; // handled elsewhere Integer targetCaseValue = targetCaseBranch.getTargetCaseValue(); Integer targetCaseBranchId = targetCaseBranch.getActualBranchId(); instrumentation.add(new InsnNode(Opcodes.DUP)); instrumentation.add(new LdcInsnNode(targetCaseValue)); instrumentation.add(new LdcInsnNode(Opcodes.IF_ICMPEQ)); instrumentation.add(new LdcInsnNode(targetCaseBranchId)); instrumentation.add(new LdcInsnNode(v.getInstructionId())); instrumentation.add( new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false)); } }
From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>//from w w w . j av a2s .c om * 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); }
From source file:org.evosuite.instrumentation.coverage.DefUseInstrumentation.java
License:Open Source License
private void addObjectInstrumentation(BytecodeInstruction instruction, InsnList instrumentation, MethodNode mn) {//from w w w . j av a2 s .c om if (instruction.isLocalVariableDefinition()) { if (instruction.getASMNode().getOpcode() == Opcodes.ALOAD) { instrumentation.add(new InsnNode(Opcodes.DUP)); } else { instrumentation.add(new InsnNode(Opcodes.ACONST_NULL)); } } else if (instruction.isLocalVariableUse()) { if (instruction.getASMNode().getOpcode() == Opcodes.ASTORE) { instrumentation.add(new InsnNode(Opcodes.DUP)); } else { instrumentation.add(new InsnNode(Opcodes.ACONST_NULL)); } } else if (instruction.isArrayStoreInstruction()) { // Object, index, value instrumentation.add(new InsnNode(Opcodes.DUP)); // } else if(instruction.isArrayLoadInstruction()) { // instrumentation.add(new InsnNode(Opcodes.DUP)); } else if (instruction.isFieldNodeDU()) { // TODO: FieldNodeDU takes care of ArrayStore - why? Type type = Type.getType(instruction.getFieldType()); if (type.getSort() == Type.OBJECT) { instrumentation.add(new InsnNode(Opcodes.DUP)); } else { instrumentation.add(new InsnNode(Opcodes.ACONST_NULL)); } } else if (instruction.isMethodCall()) { Type type = Type.getReturnType(instruction.getMethodCallDescriptor()); if (type.getSort() == Type.OBJECT) { instrumentation.add(new InsnNode(Opcodes.DUP)); } else { instrumentation.add(new InsnNode(Opcodes.ACONST_NULL)); } } }
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); insertBranch(Opcodes.IFGE, "java/lang/ArrayIndexOutOfBoundsException"); mv.visitInsn(Opcodes.DUP2);/*from ww w . ja va2 s .co m*/ 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); } }