Search in sources :

Example 1 with ClassInfo

use of io.fabric8.apmagent.ClassInfo in project fabric8 by jboss-fuse.

the class TraceStrategy method transform.

@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    byte[] buffer = null;
    ClassInfo classInfo = context.getClassInfo(className);
    classInfo.setOriginalClass(classBeingRedefined);
    if (classInfo.getTransformed() == null) {
        // we haven't been transformed before
        classInfo.setOriginal(classfileBuffer);
    }
    if (!cleanUp.get()) {
        byte[] classBufferToRedefine = classInfo.getOriginal();
        if (configuration.isAudit(className)) {
            if (classInfo.isTransformed()) {
                // remove metrics from methods no longer defined
                context.resetMethods(classInfo);
            }
            ClassReader cr = new ClassReader(classBufferToRedefine);
            ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
            ApmClassVisitor visitor = new ApmClassVisitor(this, cw, classInfo);
            cr.accept(visitor, ClassReader.SKIP_FRAMES);
            buffer = cw.toByteArray();
            if (!verifyClass(className, buffer)) {
                classInfo.setCanTransform(false);
                buffer = null;
            }
            classInfo.setTransformed(buffer);
        }
    } else {
        if (classInfo.getOriginal() != null) {
            buffer = classInfo.getOriginal();
            context.resetAll(classInfo);
        }
    }
    return buffer;
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassWriter(org.objectweb.asm.ClassWriter) ClassInfo(io.fabric8.apmagent.ClassInfo)

Example 2 with ClassInfo

use of io.fabric8.apmagent.ClassInfo in project fabric8 by jboss-fuse.

the class ApmAgentContext method buildDeltaList.

public List<ClassInfo> buildDeltaList() {
    List<ClassInfo> result = new ArrayList<>();
    for (ClassInfo classInfo : allMethods.values()) {
        if (classInfo.isTransformed()) {
            // check to see its still should be audited
            if (configuration.isAudit(classInfo.getClassName())) {
                boolean retransform = false;
                // check to see if there's a change to methods that should be transformed
                Set<String> transformedMethodNames = classInfo.getAllTransformedMethodNames();
                for (String methodName : transformedMethodNames) {
                    if (!configuration.isAudit(classInfo.getClassName(), methodName)) {
                        retransform = true;
                        break;
                    }
                }
                if (!retransform) {
                    // check to see if there are methods that should now be audited but weren't
                    Set<String> allMethodNames = classInfo.getAllMethodNames();
                    for (String methodName : allMethodNames) {
                        if (!transformedMethodNames.contains(methodName) && configuration.isAudit(classInfo.getClassName(), methodName)) {
                            retransform = true;
                            break;
                        }
                    }
                }
                if (retransform) {
                    result.add(classInfo);
                }
            } else {
                // we were once audited - but now need to be removed
                result.add(classInfo);
            }
        } else if (configuration.isAudit(classInfo.getClassName())) {
            if (classInfo.isCanTransform()) {
                result.add(classInfo);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ClassInfo(io.fabric8.apmagent.ClassInfo)

Example 3 with ClassInfo

use of io.fabric8.apmagent.ClassInfo in project fabric8 by jboss-fuse.

the class ApmAgentContext method resetAll.

public void resetAll(ClassInfo classInfo) {
    Collection<MethodDescription> list = classInfo.getTransformedMethodDescriptions();
    for (MethodDescription methodDescription : list) {
        remove(methodDescription);
    }
    classInfo.resetTransformed();
}
Also used : MethodDescription(io.fabric8.apmagent.MethodDescription)

Example 4 with ClassInfo

use of io.fabric8.apmagent.ClassInfo in project fabric8 by fabric8io.

the class TraceStrategy method transform.

@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    byte[] buffer = null;
    ClassInfo classInfo = context.getClassInfo(className);
    classInfo.setOriginalClass(classBeingRedefined);
    if (classInfo.getTransformed() == null) {
        // we haven't been transformed before
        classInfo.setOriginal(classfileBuffer);
    }
    if (!cleanUp.get()) {
        byte[] classBufferToRedefine = classInfo.getOriginal();
        if (configuration.isAudit(className)) {
            if (classInfo.isTransformed()) {
                // remove metrics from methods no longer defined
                context.resetMethods(classInfo);
            }
            ClassReader cr = new ClassReader(classBufferToRedefine);
            ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
            ApmClassVisitor visitor = new ApmClassVisitor(this, cw, classInfo);
            cr.accept(visitor, ClassReader.SKIP_FRAMES);
            buffer = cw.toByteArray();
            if (!verifyClass(className, buffer)) {
                classInfo.setCanTransform(false);
                buffer = null;
            }
            classInfo.setTransformed(buffer);
        }
    } else {
        if (classInfo.getOriginal() != null) {
            buffer = classInfo.getOriginal();
            context.resetAll(classInfo);
        }
    }
    return buffer;
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassWriter(org.objectweb.asm.ClassWriter) ClassInfo(io.fabric8.apmagent.ClassInfo)

Example 5 with ClassInfo

use of io.fabric8.apmagent.ClassInfo in project fabric8 by fabric8io.

the class ApmAgentContext method buildDeltaList.

public List<ClassInfo> buildDeltaList() {
    List<ClassInfo> result = new ArrayList<>();
    for (ClassInfo classInfo : allMethods.values()) {
        if (classInfo.isTransformed()) {
            // check to see its still should be audited
            if (configuration.isAudit(classInfo.getClassName())) {
                boolean retransform = false;
                // check to see if there's a change to methods that should be transformed
                Set<String> transformedMethodNames = classInfo.getAllTransformedMethodNames();
                for (String methodName : transformedMethodNames) {
                    if (!configuration.isAudit(classInfo.getClassName(), methodName)) {
                        retransform = true;
                        break;
                    }
                }
                if (!retransform) {
                    // check to see if there are methods that should now be audited but weren't
                    Set<String> allMethodNames = classInfo.getAllMethodNames();
                    for (String methodName : allMethodNames) {
                        if (!transformedMethodNames.contains(methodName) && configuration.isAudit(classInfo.getClassName(), methodName)) {
                            retransform = true;
                            break;
                        }
                    }
                }
                if (retransform) {
                    result.add(classInfo);
                }
            } else {
                // we were once audited - but now need to be removed
                result.add(classInfo);
            }
        } else if (configuration.isAudit(classInfo.getClassName())) {
            if (classInfo.isCanTransform()) {
                result.add(classInfo);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ClassInfo(io.fabric8.apmagent.ClassInfo)

Aggregations

ClassInfo (io.fabric8.apmagent.ClassInfo)6 MethodDescription (io.fabric8.apmagent.MethodDescription)2 ArrayList (java.util.ArrayList)2 ClassReader (org.objectweb.asm.ClassReader)2 ClassWriter (org.objectweb.asm.ClassWriter)2