Search in sources :

Example 1 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project lombok by rzwitserloot.

the class AsmUtil method fixJSRInlining.

static byte[] fixJSRInlining(byte[] byteCode) {
    ClassReader reader = new ClassReader(byteCode);
    ClassWriter writer = new FixedClassWriter(reader, 0);
    ClassVisitor visitor = new ClassVisitor(Opcodes.ASM6, writer) {

        @Override
        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);
        }
    };
    reader.accept(visitor, 0);
    return writer.toByteArray();
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter)

Example 2 with JSRInlinerAdapter

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

the class JSRInlinerClassVisitor method visitMethod.

/**
 * {@inheritDoc}
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, final String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    mv = new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions);
    return mv;
}
Also used : JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 3 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project CodenameOne by codenameone.

the class Parser method visitMethod.

@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);
    JSRInlinerAdapter a = new JSRInlinerAdapter(new MethodVisitorWrapper(super.visitMethod(access, name, desc, signature, exceptions), mtd), access, name, desc, signature, exceptions);
    return a;
}
Also used : JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter)

Example 4 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project robolectric by robolectric.

the class ClassInstrumentor method analyzeClass.

private MutableClass analyzeClass(byte[] origClassBytes, final InstrumentationConfiguration config, ClassNodeProvider classNodeProvider) {
    ClassNode classNode = new ClassNode(Opcodes.ASM4) {

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            MethodVisitor methodVisitor = super.visitMethod(access, name, config.remapParams(desc), signature, exceptions);
            return new JSRInlinerAdapter(methodVisitor, access, name, desc, signature, exceptions);
        }
    };
    final ClassReader classReader = new ClassReader(origClassBytes);
    classReader.accept(classNode, 0);
    return new MutableClass(classNode, config, classNodeProvider);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ClassReader(org.objectweb.asm.ClassReader) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 5 with JSRInlinerAdapter

use of org.objectweb.asm.commons.JSRInlinerAdapter in project quasar by puniverse.

the class InstrumentClass method visitMethod.

@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, sourceName, sourceDebugInfo, isInterface, className, classEntry.getSuperName(), classEntry.getInterfaces(), name, desc, signature, exceptions);
    final SuspendableType setSuspendable = classEntry.check(name, desc);
    if (setSuspendable == null)
        classEntry.set(name, desc, markedSuspendable != null ? markedSuspendable : SuspendableType.NON_SUSPENDABLE);
    final SuspendableType suspendable = max(markedSuspendable, setSuspendable, SuspendableType.NON_SUSPENDABLE);
    if (checkAccessForMethodVisitor(access) && !isYieldMethod(className, name)) {
        if (methods == null)
            methods = new ArrayList<>();
        final MethodNode mn = new MethodNode(access, name, desc, signature, exceptions);
        return new MethodVisitor(ASMAPI, mn) {

            private SuspendableType susp = suspendable;

            private boolean commited = false;

            @Override
            public AnnotationVisitor visitAnnotation(String adesc, boolean visible) {
                // look for @Suspendable or @DontInstrument annotation
                if (adesc.equals(SUSPENDABLE_DESC))
                    susp = SuspendableType.SUSPENDABLE;
                else if (adesc.equals(DONT_INSTRUMENT_DESC))
                    susp = SuspendableType.NON_SUSPENDABLE;
                susp = suspendableToSuperIfAbstract(access, susp);
                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%s suspendable: %s (markedSuspendable: %s setSuspendable: %s)", className, name, desc, susp, susp, setSuspendable);
                classEntry.set(name, desc, susp);
                if (susp == SuspendableType.SUSPENDABLE && checkAccessForMethodInstrumentation(access)) {
                    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);
                    }
                    methods.add(mn);
                } else {
                    MethodVisitor _mv = makeOutMV(mn);
                    _mv = new JSRInlinerAdapter(_mv, access, name, desc, signature, exceptions);
                    mn.accept(new MethodVisitor(ASMAPI, _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);
}
Also used : SuspendableType(co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType) MethodNode(org.objectweb.asm.tree.MethodNode) ArrayList(java.util.ArrayList) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

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