Example usage for org.objectweb.asm.commons JSRInlinerAdapter JSRInlinerAdapter

List of usage examples for org.objectweb.asm.commons JSRInlinerAdapter JSRInlinerAdapter

Introduction

In this page you can find the example usage for org.objectweb.asm.commons JSRInlinerAdapter JSRInlinerAdapter.

Prototype

public JSRInlinerAdapter(final MethodVisitor methodVisitor, final int access, final String name,
        final String descriptor, final String signature, final String[] exceptions) 

Source Link

Document

Constructs a new JSRInlinerAdapter .

Usage

From source file:blue.origami.asm.OClassWriter.java

License:Apache License

public final OGeneratorAdapter newGeneratorAdapter(OAnno anno, OType returnType, String name, String signature,
        OType... paramTypes) {//from  w  ww.j a  v a2 s .  co m
    // String desc = (new MethodDeclSignatureWriter(returnType,
    // paramTypes)).getDesc();
    String desc = getDesc(returnType, paramTypes);
    MethodVisitor mv = this.visitMethod(anno.acc(), name, desc, signature, null);
    // ODebug.trace("descriptor = %s\n", desc);
    // ODebug.trace("signature = %s\n", signature);
    JSRInlinerAdapter inlinerAdapter = new JSRInlinerAdapter(mv, anno.acc(), name, desc, signature, null);
    OGeneratorAdapter asapter = new OGeneratorAdapter(inlinerAdapter, anno.acc(), name, desc);
    anno.asm(asapter);
    return asapter;
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentClass.java

License:Open Source License

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {
    SuspendableType markedSuspendable = null;
    if (suspendableInterface)
        markedSuspendable = SuspendableType.SUSPENDABLE_SUPER;
    if (markedSuspendable == null)
        markedSuspendable = classifier.isSuspendable(db, className, classEntry.getSuperName(),
                classEntry.getInterfaces(), name, desc, signature, exceptions);
    final SuspendableType setSuspendable = classEntry.check(name, desc);

    if (setSuspendable == null)
        classEntry.set(name, desc,/*from  www  . j a v a2 s.  c  om*/
                markedSuspendable != null ? markedSuspendable : SuspendableType.NON_SUSPENDABLE);

    final boolean suspendable = markedSuspendable == SuspendableType.SUSPENDABLE
            | setSuspendable == SuspendableType.SUSPENDABLE;

    if (checkAccess(access) && !isYieldMethod(className, name)) {
        if (isSynchronized(access)) {
            if (!db.isAllowMonitors())
                throw new UnableToInstrumentException("synchronization", className, name, desc);
            else
                db.log(LogLevel.WARNING, "Method %s#%s%s is synchronized", className, name, desc);
        }

        if (methods == null)
            methods = new ArrayList<MethodNode>();
        final MethodNode mn = new MethodNode(access, name, desc, signature, exceptions);

        //            if (suspendable) {
        //                if (db.isDebug())
        //                    db.log(LogLevel.INFO, "Method %s#%s suspendable: %s (markedSuspendable: %s setSuspendable: %s)", className, name, suspendable, markedSuspendable, setSuspendable);
        //
        //                methods.add(mn);
        //                return mn; // this causes the mn to be initialized
        //            } else { // look for @Suspendable or @DontInstrument annotation
        return new MethodVisitor(Opcodes.ASM4, mn) {
            private boolean susp = suspendable;
            private boolean commited = false;

            @Override
            public AnnotationVisitor visitAnnotation(String adesc, boolean visible) {
                if (adesc.equals(ANNOTATION_DESC))
                    susp = true;
                else if (adesc.equals(DONT_INSTRUMENT_ANNOTATION_DESC))
                    susp = false;

                return super.visitAnnotation(adesc, visible);
            }

            @Override
            public void visitCode() {
                commit();
                super.visitCode();
            }

            @Override
            public void visitEnd() {
                if (exception != null)
                    return;

                commit();
                try {
                    super.visitEnd();
                } catch (RuntimeException e) {
                    exception = e;
                }
            }

            private void commit() {
                if (commited)
                    return;
                commited = true;

                if (db.isDebug())
                    db.log(LogLevel.INFO,
                            "Method %s#%s suspendable: %s (markedSuspendable: %s setSuspendable: %s)",
                            className, name, susp, susp, setSuspendable);
                classEntry.set(name, desc,
                        susp ? SuspendableType.SUSPENDABLE : SuspendableType.NON_SUSPENDABLE);

                if (susp)
                    methods.add(mn);
                else {
                    MethodVisitor _mv = makeOutMV(mn);
                    _mv = new JSRInlinerAdapter(_mv, access, name, desc, signature, exceptions);
                    mn.accept(new MethodVisitor(Opcodes.ASM4, _mv) {
                        @Override
                        public void visitEnd() {
                            // don't call visitEnd on MV
                        }
                    }); // write method as-is
                    this.mv = _mv;
                }
            }
        };
        //            }
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}

From source file:com.android.build.gradle.internal.incremental.IncrementalChangeVisitor.java

License:Apache License

/**
 * Creates a method adapter that will instrument to original code in such a way that it can
 * patch live code./*from w w w.j ava2  s.c  o m*/
 * @param access the method access flags.
 * @param name the method name
 * @param originalDesc the original description.
 * @param newDesc the modified method description that suits the InstantRun patching algorithms
 * @param signature the method signature.
 * @param exceptions the exceptions thrown by the method
 * @param isStatic true if the method is static, false otherwise.
 * @param isConstructor true if a constructor. false otherwise.
 * @return the method adapter visitor.
 */
private MethodVisitor createMethodAdapter(int access, String name, String originalDesc, String newDesc,
        String signature, String[] exceptions, boolean isStatic, boolean isConstructor) {

    MethodVisitor methodVisitor = super.visitMethod(access, name, originalDesc, signature, exceptions);
    methodVisitor = new ISVisitor(methodVisitor, access, name, newDesc, isStatic, isConstructor);
    // 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
    return new JSRInlinerAdapter(methodVisitor, access, name, newDesc, signature, exceptions);
}

From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java

License:Apache License

/**
 * Insert Constructor specific logic({@link ConstructorRedirection} and
 * {@link ConstructorBuilder}) for constructor redirecting or
 * normal method redirecting ({@link MethodRedirection}) for other methods.
 *///w  w w.  j  av  a2 s.  c om
@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.");

    // does the method use blacklisted APIs.
    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)) {
            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 ConstructorRedirection(start, constructor, args));
        } else {
            mv.addRedirection(new MethodRedirection(new LabelNode(mv.getStartLabel()), name + "." + desc, args,
                    Type.getReturnType(desc)));
        }
        method.accept(mv);
        return null;
    }
}

From source file:com.codename1.tools.translator.Parser.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    BytecodeMethod mtd = new BytecodeMethod(clsName, access, name, desc, signature, exceptions);
    cls.addMethod(mtd);// w ww.  j  av  a 2  s .c o m
    JSRInlinerAdapter a = new JSRInlinerAdapter(
            new MethodVisitorWrapper(super.visitMethod(access, name, desc, signature, exceptions), mtd), access,
            name, desc, signature, exceptions);
    return a;
}

From source file:com.geeksaga.light.profiler.util.ASMUtil.java

License:Apache License

private static ClassVisitor useJSRInlinerAdapter(ClassVisitor visitor) {
    return new ClassVisitor(Opcodes.ASM5, visitor) {
        @Override//  w  w w .ja va 2  s  .c o m
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access,
                    name, desc, signature, exceptions);
        }
    };
}

From source file:com.github.malamut2.low.AllocationClassAdapter.java

License:Apache License

/**
 * For each method in the class being instrumented, <code>visitMethod</code>
 * is called and the returned MethodVisitor is used to visit the method.
 * Note that a new MethodVisitor is constructed for each method.
 *///w  w w.  j  a  v a2  s  . c  om
@Override
public MethodVisitor visitMethod(int access, String base, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access, base, desc, signature, exceptions);

    if (mv != null) {
        // We need to compute stackmaps (see
        // AllocationInstrumenter#instrument).  This can't really be
        // done for old bytecode that contains JSR and RET instructions.
        // So, we remove JSRs and RETs.
        JSRInlinerAdapter jsria = new JSRInlinerAdapter(mv, access, base, desc, signature, exceptions);
        AllocationMethodAdapter aimv = new AllocationMethodAdapter(jsria, recorderClass, recorderMethod);
        LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, aimv);
        aimv.lvs = lvs;
        mv = lvs;
    }
    return mv;
}

From source file:com.google.monitoring.runtime.instrumentation.adapters.AllocationClassAdapter.java

License:Apache License

/**
 * For each method in the class being instrumented, <code>visitMethod</code>
 * is called and the returned MethodVisitor is used to visit the method.
 * Note that a new MethodVisitor is constructed for each method.
 *///from   w w w .  jav  a2 s  .c  o m
@Override
public MethodVisitor visitMethod(final int access, final String base, final String desc, final String signature,
        final String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access, base, desc, signature, exceptions);
    if (mv != null) {
        // We need to compute stackmaps (see
        // AllocationInstrumenter#instrument).  This can't really be
        // done for old bytecode that contains JSR and RET instructions.
        // So, we remove JSRs and RETs.
        final JSRInlinerAdapter jsria = new JSRInlinerAdapter(mv, access, base, desc, signature, exceptions);
        final AllocationMethodAdapter aimv = new AllocationMethodAdapter(jsria, recorderClass, recorderMethod);
        final LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, aimv);
        aimv.lvs = lvs;
        mv = lvs;
    }
    return mv;
}

From source file:com.offbynull.coroutines.instrumenter.asm.SimpleClassNode.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor origVisitor = super.visitMethod(access, name, desc, signature, exceptions);
    return new JSRInlinerAdapter(origVisitor, access, name, desc, signature, exceptions);
}

From source file:de.unisb.cs.st.javaslicer.tracer.instrumentation.JSRInliner.java

License:Open Source License

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {
    final MethodVisitor visitor = super.visitMethod(access, name, desc, signature, exceptions);
    return visitor == null ? null : new JSRInlinerAdapter(visitor, access, name, desc, signature, exceptions);
}