Search in sources :

Example 1 with ClassEntry

use of co.paralleluniverse.fibers.instrument.MethodDatabase.ClassEntry in project quasar by puniverse.

the class CheckInstrumentationVisitor method visit.

@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
    this.className = name;
    this.isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    this.classEntry = new ClassEntry(superName);
    classEntry.setInterfaces(interfaces);
    classEntry.setIsInterface(isInterface);
}
Also used : ClassEntry(co.paralleluniverse.fibers.instrument.MethodDatabase.ClassEntry)

Example 2 with ClassEntry

use of co.paralleluniverse.fibers.instrument.MethodDatabase.ClassEntry in project quasar by puniverse.

the class InstrumentClass method visitEnd.

@Override
@SuppressWarnings("CallToPrintStackTrace")
public void visitEnd() {
    if (exception != null)
        throw exception;
    classEntry.setRequiresInstrumentation(false);
    db.recordSuspendableMethods(className, classEntry);
    if (methods != null && !methods.isEmpty()) {
        if (alreadyInstrumented && !forceInstrumentation) {
            for (MethodNode mn : methods) {
                db.log(LogLevel.INFO, "Already instrumented and not forcing, so not touching method %s#%s%s", className, mn.name, mn.desc);
                mn.accept(makeOutMV(mn));
            }
        } else {
            if (!alreadyInstrumented) {
                emitInstrumentedAnn();
                classEntry.setInstrumented(true);
            }
            for (MethodNode mn : methods) {
                final MethodVisitor outMV = makeOutMV(mn);
                try {
                    InstrumentMethod im = new InstrumentMethod(db, sourceName, className, mn);
                    db.log(LogLevel.DEBUG, "About to instrument method %s#%s%s", className, mn.name, mn.desc);
                    im.accept(outMV, hasAnnotation(mn));
                } catch (UnableToInstrumentException e) {
                    db.log(LogLevel.WARNING, "UnableToInstrumentException encountered when instrumenting %s#%s%s: %s", className, mn.name, mn.desc, e.getMessage());
                    mn.accept(outMV);
                } catch (AnalyzerException ex) {
                    ex.printStackTrace();
                    throw new InternalError(ex.getMessage());
                }
            }
        }
    } else {
        // if we don't have any suspendable methods, but our superclass is instrumented, we mark this class as instrumented, too.
        if (!alreadyInstrumented && classEntry.getSuperName() != null) {
            ClassEntry superClass = db.getClassEntry(classEntry.getSuperName());
            if (superClass != null && superClass.isInstrumented()) {
                emitInstrumentedAnn();
                classEntry.setInstrumented(true);
            }
        }
    }
    super.visitEnd();
}
Also used : AnalyzerException(org.objectweb.asm.tree.analysis.AnalyzerException) MethodNode(org.objectweb.asm.tree.MethodNode) ClassEntry(co.paralleluniverse.fibers.instrument.MethodDatabase.ClassEntry) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

ClassEntry (co.paralleluniverse.fibers.instrument.MethodDatabase.ClassEntry)2 MethodVisitor (org.objectweb.asm.MethodVisitor)1 MethodNode (org.objectweb.asm.tree.MethodNode)1 AnalyzerException (org.objectweb.asm.tree.analysis.AnalyzerException)1