List of usage examples for org.objectweb.asm Opcodes INVOKESPECIAL
int INVOKESPECIAL
To view the source code for org.objectweb.asm Opcodes INVOKESPECIAL.
Click Source Link
From source file:org.evosuite.instrumentation.error.CastErrorInstrumentation.java
License:Open Source License
@Override public void visitTypeInsn(int opcode, String type) { if (opcode == Opcodes.CHECKCAST) { Label origTarget = new Label(); // Label origTarget = new AnnotatedLabel(); // origTarget.info = Boolean.FALSE; mv.visitInsn(Opcodes.DUP);//from w ww . jav a2s.c om mv.tagBranch(); mv.visitJumpInsn(Opcodes.IFNULL, origTarget); mv.visitInsn(Opcodes.DUP); mv.visitTypeInsn(Opcodes.INSTANCEOF, type); mv.tagBranch(); mv.visitJumpInsn(Opcodes.IFNE, origTarget); mv.visitTypeInsn(Opcodes.NEW, "java/lang/ClassCastException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/ClassCastException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(origTarget); mv.tagBranchExit(); } }
From source file:org.evosuite.instrumentation.error.ErrorBranchInstrumenter.java
License:Open Source License
protected void insertBranch(int opcode, String exception) { Label origTarget = new Label(); mv.tagBranch();//from w ww.j a va2s. c om mv.visitJumpInsn(opcode, origTarget); mv.visitTypeInsn(Opcodes.NEW, exception); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, exception, "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(origTarget); mv.tagBranchExit(); }
From source file:org.evosuite.instrumentation.error.ErrorBranchInstrumenter.java
License:Open Source License
protected void insertBranchWithoutTag(int opcode, String exception) { Label origTarget = new Label(); mv.visitJumpInsn(opcode, origTarget); mv.visitTypeInsn(Opcodes.NEW, exception); mv.visitInsn(Opcodes.DUP);/*w w w . java 2 s.c o m*/ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, exception, "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(origTarget); }
From source file:org.evosuite.instrumentation.JUnitCoverageMethodAdapter.java
License:Open Source License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { if (!isJUnitTest) { super.visitMethodInsn(opcode, owner, name, desc, itf); return;//from w w w .j a v a 2s.c o m } String classNameWithDots = owner.replace('/', '.'); String instrumentedOwner = owner; if (!DependencyAnalysis.shouldAnalyze(classNameWithDots)) { if (subClasses.contains(classNameWithDots)) { logger.info("Using target class instead of subclass"); // The reason for this hack is that manually written tests often use dummy-subclasses and then we would miss coverage instrumentedOwner = Properties.TARGET_CLASS.replace('.', '/'); } else if (superClasses.contains(classNameWithDots)) { // Can be a virtual call, so is ok instrumentedOwner = Properties.TARGET_CLASS.replace('.', '/'); } else { super.visitMethodInsn(opcode, owner, name, desc, itf); return; } } Label startLabel = mark(); Type[] argumentTypes = Type.getArgumentTypes(desc); int[] locals = new int[argumentTypes.length]; for (int i = argumentTypes.length - 1; i >= 0; i--) { int local = newLocal(argumentTypes[i]); storeLocal(local, argumentTypes[i]); locals[i] = local; } if (opcode == Opcodes.INVOKESPECIAL) { // dup(); // for return value push((String) null); } else if (opcode == Opcodes.INVOKESTATIC) { push((String) null); } else { dup(); // Callee } push(opcode); push(instrumentedOwner); push(name); push(desc); push(argumentTypes.length); Type objectType = Type.getObjectType("java/lang/Object"); newArray(objectType); for (int i = 0; i < argumentTypes.length; i++) { dup(); push(i); loadLocal(locals[i]); box(argumentTypes[i]); arrayStore(objectType); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(JUnitObserver.class), "methodCalled", "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V", false); for (int i = 0; i < argumentTypes.length; i++) { loadLocal(locals[i]); } super.visitMethodInsn(opcode, owner, name, desc, itf); Label l = newLabel(); goTo(l); Label endLabel = mark(); TryCatchBlock block = new TryCatchBlock(startLabel, endLabel, endLabel, Type.getType(Throwable.class).getInternalName()); instrumentedTryCatchBlocks.add(block); // catchException(startLabel, endLabel, Type.getType(Throwable.class)); dup(); // Exception push(instrumentedOwner); push(name); push(desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(JUnitObserver.class), "methodException", "(Ljava/lang/Throwable;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false); throwException(); // re-throw mark(l); Type returnType = Type.getReturnType(desc); if (opcode == Opcodes.INVOKESPECIAL) { // dup(); push((String) null); } else if (returnType == Type.VOID_TYPE) { push((String) null); } else { if (returnType.getSize() == 1) dup(); else if (returnType.getSize() == 2) dup2(); else assert (false); // Cannot happen box(Type.getReturnType(desc)); } push(instrumentedOwner); push(name); push(desc); // if ((opcode & Opcodes.INVOKESTATIC) > 0) { // mv.visitInsn(Opcodes.ACONST_NULL); // } else { // mv.visitVarInsn(Opcodes.ALOAD, 0); // } mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(JUnitObserver.class), "methodReturned", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false); }
From source file:org.evosuite.instrumentation.LineNumberMethodAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w ww. j av a2 s. co m public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { super.visitMethodInsn(opcode, owner, name, desc, itf); if (opcode == Opcodes.INVOKESPECIAL) { if (methodName.equals("<init>")) { hadInvokeSpecial = true; for (int line : skippedLines) { addLineNumberInstrumentation(line); } skippedLines.clear(); } } }
From source file:org.evosuite.instrumentation.MethodCallReplacementMethodAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w .ja v a 2 s . c o m*/ public void visitMethodInsn(int opcode, String owner, String name, String desc) { boolean isReplaced = false; // static replacement methods for (MethodCallReplacement replacement : replacementCalls) { if (replacement.isTarget(owner, name, desc)) { isReplaced = true; replacement.insertMethodCall(this, Opcodes.INVOKESTATIC); break; } } // for constructors if (!isReplaced) { for (MethodCallReplacement replacement : specialReplacementCalls) { if (replacement.isTarget(owner, name, desc) && opcode == Opcodes.INVOKESPECIAL) { isReplaced = true; boolean isSelf = false; if (needToWaitForSuperConstructor) { String originalClassNameWithDots = owner.replace('/', '.'); if (originalClassNameWithDots.equals(superClassName)) { isSelf = true; } } if (replacement.methodName.equals("<init>")) replacement.insertConstructorCall(this, replacement, isSelf); else replacement.insertMethodCall(this, Opcodes.INVOKESPECIAL); break; } } } // non-static replacement methods if (!isReplaced) { for (MethodCallReplacement replacement : virtualReplacementCalls) { if (replacement.isTarget(owner, name, desc)) { isReplaced = true; replacement.insertMethodCall(this, Opcodes.INVOKEVIRTUAL); break; } } } if (!isReplaced) { super.visitMethodInsn(opcode, owner, name, desc); } if (needToWaitForSuperConstructor) { if (opcode == Opcodes.INVOKESPECIAL) { String originalClassNameWithDots = owner.replace('/', '.'); if (originalClassNameWithDots.equals(superClassName)) { needToWaitForSuperConstructor = false; } } } }
From source file:org.evosuite.instrumentation.mutation.DeleteStatement.java
License:Open Source License
/** {@inheritDoc} */ @Override//from www.jav a 2 s .c o m public boolean isApplicable(BytecodeInstruction instruction) { return instruction.isMethodCall() && instruction.getASMNode().getOpcode() != Opcodes.INVOKESPECIAL; }
From source file:org.evosuite.instrumentation.PurityAnalysisMethodVisitor.java
License:Open Source License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { String targetClassName = owner.replace('/', '.'); if (targetClassName.equals(org.evosuite.runtime.Random.class.getCanonicalName()) || !BytecodeInstrumentation.checkIfEvoSuitePackage(targetClassName)) { //Only ignore EvoSuite callbacks if (opcode == Opcodes.INVOKESTATIC) { this.purityAnalyzer.addStaticCall(classNameWithDots, methodName, descriptor, targetClassName, name, desc);/*from w ww . java 2 s .com*/ } else if (opcode == Opcodes.INVOKEVIRTUAL) { this.purityAnalyzer.addVirtualCall(classNameWithDots, methodName, descriptor, targetClassName, name, desc); } else if (opcode == Opcodes.INVOKEINTERFACE) { this.purityAnalyzer.addInterfaceCall(classNameWithDots, methodName, descriptor, targetClassName, name, desc); } else if (opcode == Opcodes.INVOKESPECIAL) { this.purityAnalyzer.addSpecialCall(classNameWithDots, methodName, descriptor, targetClassName, name, desc); } } super.visitMethodInsn(opcode, owner, name, desc, itf); }
From source file:org.evosuite.instrumentation.YieldAtLineNumberMethodAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . j a v a 2 s. c om public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { if (opcode == Opcodes.INVOKESPECIAL) { if (methodName.equals("<init>")) hadInvokeSpecial = true; } super.visitMethodInsn(opcode, owner, name, desc, itf); }
From source file:org.evosuite.runtime.instrumentation.MethodCallReplacement.java
License:Open Source License
public void insertMethodCall(MethodCallReplacementMethodAdapter mv, int opcode) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, MockFramework.class.getCanonicalName().replace('.', '/'), "isEnabled", "()Z", false); Label origCallLabel = new Label(); Label afterOrigCallLabel = new Label(); Label annotationStartTag = new AnnotatedLabel(true, true); annotationStartTag.info = Boolean.TRUE; mv.visitLabel(annotationStartTag);// ww w . ja va 2 s . c om mv.visitJumpInsn(Opcodes.IFEQ, origCallLabel); Label annotationEndTag = new AnnotatedLabel(true, false); annotationEndTag.info = Boolean.FALSE; mv.visitLabel(annotationEndTag); if (popCallee) { 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); to.put(i, loc); } mv.pop();//callee if (popUninitialisedReference) mv.pop(); for (int i = 0; i < args.length; i++) { mv.loadLocal(to.get(i)); } } if (opcode == Opcodes.INVOKESPECIAL && MockList.shouldBeMocked(className.replace('/', '.'))) { insertInvokeSpecialForMockedSuperclass(mv); } else { if (opcode == Opcodes.INVOKESPECIAL) { logger.info("Not mocking invokespecial: " + replacementMethodName + " for class " + className); } mv.visitMethodInsn(opcode, replacementClassName, replacementMethodName, replacementDesc, false); } mv.visitJumpInsn(Opcodes.GOTO, afterOrigCallLabel); mv.visitLabel(origCallLabel); mv.getNextVisitor().visitMethodInsn(origOpcode, className, methodName, desc, false); // TODO: What is itf here? mv.visitLabel(afterOrigCallLabel); }