List of usage examples for org.objectweb.asm Opcodes INVOKESTATIC
int INVOKESTATIC
To view the source code for org.objectweb.asm Opcodes INVOKESTATIC.
Click Source Link
From source file:org.evosuite.instrumentation.ComparisonTransformation.java
License:Open Source License
private void insertDoubleComparison(AbstractInsnNode position, InsnList list) { MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "doubleSub", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.DOUBLE_TYPE })); list.insert(position, get);//from w ww. j ava 2 s. c o m list.remove(position); }
From source file:org.evosuite.instrumentation.ContainerBooleanInterpreter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from ww w . ja v a 2s .co m public BasicValue naryOperation(AbstractInsnNode insn, @SuppressWarnings("rawtypes") List values) throws AnalyzerException { if (insn.getOpcode() == Opcodes.INVOKESTATIC) { MethodInsnNode mn = (MethodInsnNode) insn; if (mn.owner.equals("org/evosuite/instrumentation/BooleanHelper") && (mn.name.startsWith("collection") || mn.name.startsWith("map"))) { return CONTAINER_BOOLEAN; } } return super.naryOperation(insn, values); }
From source file:org.evosuite.instrumentation.ContainerTransformation.java
License:Open Source License
/** * Replace boolean-returning method calls on Collection classes * /* w w w.ja v a2s .co m*/ * @param mn */ @SuppressWarnings("unchecked") public boolean transformMethod(MethodNode mn) { boolean changed = false; ListIterator<AbstractInsnNode> iterator = mn.instructions.iterator(); while (iterator.hasNext()) { AbstractInsnNode node = iterator.next(); if (node instanceof MethodInsnNode) { MethodInsnNode methodNode = (MethodInsnNode) node; if (methodNode.owner.equals("java/util/Collection") || methodNode.owner.equals("java/util/List") || methodNode.owner.equals("java/util/ArrayList") || methodNode.owner.equals("java/util/Set") || methodNode.owner.equals("java/util/Queue") || methodNode.owner.equals("java/util/SortedSet")) { if (methodNode.name.equals("isEmpty")) { logger.debug("Test Transformation of {}.{} -> {}.collectionIsEmpty", methodNode.owner, methodNode.name, Type.getInternalName(BooleanHelper.class)); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "collectionIsEmpty", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Collection.class) })); InsnList il = createNewIfThenElse(n); mn.instructions.insertBefore(node, il); mn.instructions.remove(node); TransformationStatistics.transformedContainerComparison(); changed = true; } else if (methodNode.name.equals("contains")) { logger.debug("Test Transformation of {}.{} -> {}.collectionContains", methodNode.owner, methodNode.name, Type.getInternalName(BooleanHelper.class)); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "collectionContains", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Collection.class), Type.getType(Object.class) })); InsnList il = createNewIfThenElse(n); mn.instructions.insertBefore(node, il); mn.instructions.remove(node); TransformationStatistics.transformedContainerComparison(); changed = true; } else if (methodNode.name.equals("containsAll")) { logger.debug("Test Transformation of {}.{} -> {}.collectionContainsAll", methodNode.owner, methodNode.name, Type.getInternalName(BooleanHelper.class)); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "collectionContainsAll", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Collection.class), Type.getType(Collection.class) })); InsnList il = createNewIfThenElse(n); mn.instructions.insertBefore(node, il); mn.instructions.remove(node); TransformationStatistics.transformedContainerComparison(); changed = true; } } else if (methodNode.owner.equals("java/util/Map")) { if (methodNode.name.equals("isEmpty")) { logger.debug("Test Transformation of {}.{} -> {}.mapIsEmpty", methodNode.owner, methodNode.name, Type.getInternalName(BooleanHelper.class)); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "mapIsEmpty", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Map.class) })); InsnList il = createNewIfThenElse(n); mn.instructions.insertBefore(node, il); mn.instructions.remove(node); TransformationStatistics.transformedContainerComparison(); changed = true; } else if (methodNode.name.equals("containsKey")) { logger.debug("Test Transformation of {}.{} -> {}.mapContainsKey", methodNode.owner, methodNode.name, Type.getInternalName(BooleanHelper.class)); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "mapContainsKey", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Map.class), Type.getType(Object.class) })); InsnList il = createNewIfThenElse(n); mn.instructions.insertBefore(node, il); mn.instructions.remove(node); TransformationStatistics.transformedContainerComparison(); changed = true; } else if (methodNode.name.equals("containsValue")) { logger.debug("Test Transformation of {}.{} -> {}.mapContainsValue", methodNode.owner, methodNode.name, Type.getInternalName(BooleanHelper.class)); MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "mapContainsValue", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Map.class), Type.getType(Object.class) })); InsnList il = createNewIfThenElse(n); mn.instructions.insertBefore(node, il); mn.instructions.remove(node); TransformationStatistics.transformedContainerComparison(); changed = true; } } } } return changed; }
From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>/*from w ww . j a 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.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/* www .j a v a 2s . c om*/ * 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 www . j a va2 s .c om * addDefaultCaseCoveredCall * </p> * * @param v * a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @param instrumentation * a {@link org.objectweb.asm.tree.InsnList} object. * @param defaultCaseBranchId * a int. */ protected void addDefaultCaseCoveredCall(BytecodeInstruction v, InsnList instrumentation, int defaultCaseBranchId) { instrumentation.add(new LdcInsnNode(0)); instrumentation.add(new LdcInsnNode(Opcodes.IFEQ)); instrumentation.add(new LdcInsnNode(defaultCaseBranchId)); instrumentation.add(new LdcInsnNode(v.getInstructionId())); instrumentation .add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false)); }
From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>/*from w w w.jav a 2s . co m*/ * addDefaultCaseNotCoveredCall * </p> * * @param v * a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @param instrumentation * a {@link org.objectweb.asm.tree.InsnList} object. * @param defaultCaseBranchId * a int. */ protected void addDefaultCaseNotCoveredCall(BytecodeInstruction v, InsnList instrumentation, int defaultCaseBranchId) { instrumentation.add(new LdcInsnNode(0)); instrumentation.add(new LdcInsnNode(Opcodes.IFNE)); instrumentation.add(new LdcInsnNode(defaultCaseBranchId)); instrumentation.add(new LdcInsnNode(v.getInstructionId())); instrumentation .add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false)); }
From source file:org.evosuite.instrumentation.coverage.DefUseInstrumentation.java
License:Open Source License
/** * Creates the instrumentation needed to track defs and uses * // w w w. j a v a 2 s . c o m */ private InsnList getInstrumentation(BytecodeInstruction v, boolean staticContext, String className, String methodName, MethodNode mn) { InsnList instrumentation = new InsnList(); if (!v.isDefUse()) { logger.warn("unexpected DefUseInstrumentation call for a non-DU-instruction"); return instrumentation; } if (DefUsePool.isKnownAsFieldMethodCall(v)) { return getMethodInstrumentation(v, staticContext, instrumentation, mn); } if (DefUsePool.isKnownAsUse(v)) { // The actual object that is defined is on the stack _after_ the load instruction addObjectInstrumentation(v, instrumentation, mn); addCallingObjectInstrumentation(staticContext, instrumentation); instrumentation.add(new LdcInsnNode(DefUsePool.getUseCounter())); instrumentation.add( new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "passedUse", "(Ljava/lang/Object;Ljava/lang/Object;I)V")); } if (DefUsePool.isKnownAsDefinition(v)) { // The actual object that is defined is on the stack _before_ the store instruction addObjectInstrumentation(v, instrumentation, mn); addCallingObjectInstrumentation(staticContext, instrumentation); instrumentation.add(new LdcInsnNode(DefUsePool.getDefCounter())); instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcase.execution.ExecutionTracer.class), "passedDefinition", "(Ljava/lang/Object;Ljava/lang/Object;I)V")); } return instrumentation; }
From source file:org.evosuite.instrumentation.coverage.DefUseInstrumentation.java
License:Open Source License
private InsnList getMethodInstrumentation(BytecodeInstruction call, boolean staticContext, InsnList instrumentation, MethodNode mn) { String descriptor = call.getMethodCallDescriptor(); Type[] args = Type.getArgumentTypes(descriptor); int loc = getNextLocalNum(mn); Map<Integer, Integer> to = new HashMap<Integer, Integer>(); for (int i = args.length - 1; i >= 0; i--) { Type type = args[i];/*from w ww.j av a2 s .com*/ instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ISTORE), loc)); to.put(i, loc); loc++; } // instrumentation.add(new InsnNode(Opcodes.DUP));//callee addObjectInstrumentation(call, instrumentation, mn); addCallingObjectInstrumentation(staticContext, instrumentation); // field method calls get special treatment: // during instrumentation it is not clear whether a field method // call constitutes a definition or a use. So the instrumentation // will call a special function of the ExecutionTracer which will // redirect the call to either passedUse() or passedDefinition() // using the information available during runtime (the CCFGs) instrumentation.add(new LdcInsnNode(DefUsePool.getDefUseCounter())); instrumentation .add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "passedFieldMethodCall", "(Ljava/lang/Object;Ljava/lang/Object;I)V")); for (int i = 0; i < args.length; i++) { Type type = args[i]; instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), to.get(i))); } return instrumentation; }
From source file:org.evosuite.instrumentation.coverage.LCSAJsInstrumentation.java
License:Open Source License
@SuppressWarnings("unchecked") private void addInstrumentation(ClassLoader classLoader, MethodNode mn, String className, String methodName) { RawControlFlowGraph graph = GraphPool.getInstance(classLoader).getRawCFG(className, methodName); Iterator<AbstractInsnNode> j = mn.instructions.iterator(); while (j.hasNext()) { AbstractInsnNode in = j.next();//from ww w. ja va 2 s .c o m for (BytecodeInstruction v : graph.vertexSet()) { // If this is in the CFG and it's a branch... if (in.equals(v.getASMNode())) { if (v.isForcedBranch()) { LCSAJPool.addLCSAJBranch(BranchPool.getInstance(classLoader).getBranchForInstruction(v)); int branchId = BranchPool.getInstance(classLoader) .getActualBranchIdForNormalBranchInstruction(v); InsnList instrumentation = new InsnList(); instrumentation.add(new LdcInsnNode(v.getASMNode().getOpcode())); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(v.getInstructionId())); instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/evosuite/testcase/ExecutionTracer", "passedUnconditionalBranch", "(III)V")); if (v.isLabel()) mn.instructions.insert(v.getASMNode(), instrumentation); else mn.instructions.insertBefore(v.getASMNode(), instrumentation); } } } } }