Search in sources :

Example 1 with PointCutInvocationHandler

use of com.newrelic.agent.tracers.PointCutInvocationHandler in project newrelic-java-agent by newrelic.

the class GenericClassAdapter method visitMethod.

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    if (canModifyClassStructure()) {
        if (CLINIT_METHOD_NAME.equals(name)) {
            mv = new InitMethodAdapter(mv, access, name, desc);
            processedClassInitMethod = true;
            return mv;
        }
    }
    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        // don't instrument abstract methods
        return mv;
    }
    PointCut pointCut = getMatch(access, name, desc);
    if (pointCut == null) {
        return mv;
    }
    Method method = new Method(name, desc);
    context.addTimedMethods(method);
    if (canModifyClassStructure()) {
        context.addOldInvokerStyleInstrumentationMethod(method, pointCut);
        mv = new InvocationHandlerTracingMethodAdapter(this, mv, access, method);
        pointcutsApplied.add(pointCut);
    } else {
        PointCutInvocationHandler pointCutInvocationHandler = pointCut.getPointCutInvocationHandler();
        int id = ServiceFactory.getTracerService().getInvocationHandlerId(pointCutInvocationHandler);
        if (id == -1) {
            Agent.LOG.log(Level.FINE, "Unable to find invocation handler for method: {0} in class: {1}. Skipping instrumentation.", name, className);
        } else {
            context.addOldReflectionStyleInstrumentationMethod(method, pointCut);
            mv = new ReflectionStyleClassMethodAdapter(this, mv, access, method, id);
            pointcutsApplied.add(pointCut);
        }
    }
    return mv;
}
Also used : PointCutInvocationHandler(com.newrelic.agent.tracers.PointCutInvocationHandler) Method(org.objectweb.asm.commons.Method) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 2 with PointCutInvocationHandler

use of com.newrelic.agent.tracers.PointCutInvocationHandler in project newrelic-java-agent by newrelic.

the class PointCutClassTransformer method evaluate.

public InvocationHandler evaluate(Class clazz, TracerService tracerService, Object className, Object methodName, Object methodDesc, boolean ignoreApdex, Object[] args) {
    ClassMethodSignature classMethodSignature = new ClassMethodSignature(((String) className).replace('/', '.'), (String) methodName, (String) methodDesc);
    for (PointCut pc : getPointcuts()) {
        // code. Bummer for you!
        if (pc.getClassMatcher().isMatch(clazz) && pc.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, classMethodSignature.getMethodName(), classMethodSignature.getMethodDesc(), MethodMatcher.UNSPECIFIED_ANNOTATIONS)) {
            PointCutInvocationHandler invocationHandler = pc.getPointCutInvocationHandler();
            return InvocationPoint.getInvocationPoint(invocationHandler, tracerService, classMethodSignature, ignoreApdex);
        }
    }
    if (ignoreApdex) {
        return IgnoreApdexInvocationHandler.INVOCATION_HANDLER;
    }
    Agent.LOG.log(Level.FINE, "No invocation handler was registered for {0}", classMethodSignature);
    return NoOpInvocationHandler.INVOCATION_HANDLER;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) PointCutInvocationHandler(com.newrelic.agent.tracers.PointCutInvocationHandler)

Aggregations

PointCutInvocationHandler (com.newrelic.agent.tracers.PointCutInvocationHandler)2 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1 Method (org.objectweb.asm.commons.Method)1