Search in sources :

Example 11 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project evosuite by EvoSuite.

the class ConcolicClassAdapter method visitMethod.

@Override
public MethodVisitor visitMethod(int access, String methName, String methDesc, String methSignGeneric, String[] exceptions) {
    MethodVisitor mv;
    mv = cv.visitMethod(access, methName, methDesc, methSignGeneric, exceptions);
    // Added to handle Java 7
    mv = new JSRInlinerAdapter(mv, access, methName, methDesc, methSignGeneric, exceptions);
    if (mv != null) {
        mv = new ConcolicMethodAdapter(mv, access, className, methName, methDesc);
    }
    return mv;
}
Also used : JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 12 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project atlas by alibaba.

the class TBIncrementalSupportVisitor method visitMethod.

/**
 * Insert Constructor specific logic({@link ConstructorRedirection} and
 * {@link ConstructorBuilder}) for constructor redirecting or
 * normal method redirecting ({@link MethodRedirection}) for other methods.
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    access = transformAccessForInstantRun(access);
    MethodVisitor defaultVisitor = super.visitMethod(access, name, desc, signature, exceptions);
    MethodNode method = checkNotNull(getMethodByNameInClass(name, desc, classNode), "Method found by visitor but not in the pre-parsed class node.");
    if (!supportAddCallSuper) {
        method.instructions.accept(new MethodVisitor(api) {

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
                if (opcode == Opcodes.INVOKESPECIAL && !owner.equals(visitedClassName)) {
                    visitSuperMethods.add(name + "." + desc);
                }
                super.visitMethodInsn(opcode, owner, name, desc, itf);
            }
        });
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        return defaultVisitor;
    }
    boolean hasIncompatibleChange = InstantRunMethodVerifier.verifyMethod(method) != InstantRunVerifierStatus.COMPATIBLE;
    if (hasIncompatibleChange || disableRedirectionForClass || !isAccessCompatibleWithInstantRun(access) || name.equals(ByteCodeUtils.CLASS_INITIALIZER)) {
        return defaultVisitor;
    } else {
        ArrayList<Type> args = new ArrayList<>(Arrays.asList(Type.getArgumentTypes(desc)));
        boolean isStatic = (access & Opcodes.ACC_STATIC) != 0;
        if (!isStatic) {
            args.add(0, Type.getType(Object.class));
        }
        // Install the Jsr/Ret inliner adapter, we have had reports of code still using the
        // Jsr/Ret deprecated byte codes.
        // see https://code.google.com/p/android/issues/detail?id=220019
        JSRInlinerAdapter jsrInlinerAdapter = new JSRInlinerAdapter(defaultVisitor, access, name, desc, signature, exceptions);
        ISMethodVisitor mv = new ISMethodVisitor(jsrInlinerAdapter, access, name, desc);
        if (name.equals(ByteCodeUtils.CONSTRUCTOR)) {
            if (patchInitMethod) {
                Constructor constructor = ConstructorBuilder.build(visitedClassName, method);
                LabelNode start = new LabelNode();
                method.instructions.insert(constructor.loadThis, start);
                if (constructor.lineForLoad != -1) {
                    // Record the line number from the start of LOAD_0 for uninitialized 'this'.
                    // This allows a breakpoint to be set at the line with this(...) or super(...)
                    // call in the constructor.
                    method.instructions.insert(constructor.loadThis, new LineNumberNode(constructor.lineForLoad, start));
                }
                mv.addRedirection(new TBConstructorRedirection(start, constructor, args));
            } else {
                return defaultVisitor;
            }
        } else {
            mv.addRedirection(new TBMethodRedirection(new LabelNode(mv.getStartLabel()), name + "." + desc, args, Type.getReturnType(desc)));
        }
        method.accept(mv);
        return null;
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodNode(org.objectweb.asm.tree.MethodNode)

Aggregations

JSRInlinerAdapter (org.objectweb.asm.commons.JSRInlinerAdapter)12 MethodVisitor (org.objectweb.asm.MethodVisitor)9 ClassReader (org.objectweb.asm.ClassReader)5 ClassVisitor (org.objectweb.asm.ClassVisitor)3 ClassWriter (org.objectweb.asm.ClassWriter)3 NeverNullArgAnalyzerAdapter (edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter)2 FileInputStream (java.io.FileInputStream)2 PrintWriter (java.io.PrintWriter)2 ClassNode (org.objectweb.asm.tree.ClassNode)2 MethodNode (org.objectweb.asm.tree.MethodNode)2 TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)2 SuspendableType (co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType)1 PrimitiveArrayAnalyzer (edu.columbia.cs.psl.phosphor.instrumenter.PrimitiveArrayAnalyzer)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FieldNode (org.objectweb.asm.tree.FieldNode)1 LabelNode (org.objectweb.asm.tree.LabelNode)1