use of com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtility method createMethodMatcher.
/**
* Creates the method matcher to be used in the point cut.
*
* @param cut The xml information about the methods contain in the point cut.
* @param pExtName The name of this extension.
* @param classesToMethods The class/method combos which have already appeared.
* @return The matcher to be used for methods on the point cut.
* @throws XmlException
*/
private static MethodMatcher createMethodMatcher(final Pointcut cut, final String pExtName, final Map<String, MethodMapper> classesToMethods) throws XmlException {
List<Method> methods = cut.getMethod();
List<String> traceReturnTypeDescriptors = cut.getTraceReturnTypeDescriptors();
if (methods != null && !methods.isEmpty()) {
return MethodMatcherUtility.createMethodMatcher(getClassName(cut), methods, classesToMethods, pExtName);
} else if (cut.getMethodAnnotation() != null) {
return new AnnotationMethodMatcher(Type.getObjectType(cut.getMethodAnnotation().replace('.', '/')));
} else if (cut.isTraceLambda()) {
return new LambdaMethodMatcher(cut.getPattern(), cut.getIncludeNonstatic());
} else if (traceReturnTypeDescriptors != null && !traceReturnTypeDescriptors.isEmpty()) {
return new ReturnTypeMethodMatcher(traceReturnTypeDescriptors);
} else {
throw new XmlException(MessageFormat.format(XmlParsingMessages.NO_METHOD, pExtName));
}
}
use of com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher in project newrelic-java-agent by newrelic.
the class OptimizedClassMatcherBuilder method addClassMethodMatcher.
public OptimizedClassMatcherBuilder addClassMethodMatcher(ClassAndMethodMatcher... matchers) {
for (ClassAndMethodMatcher matcher : matchers) {
if (exactClassMatch && !matcher.getClassMatcher().isExactClassMatcher()) {
exactClassMatch = false;
} else {
exactClassNames.addAll(matcher.getClassMatcher().getClassNames());
}
if (matcher.getMethodMatcher() instanceof AnnotationMethodMatcher) {
methodAnnotationMatchers.add(((AnnotationMethodMatcher) matcher.getMethodMatcher()).getAnnotationType().getDescriptor());
}
Method[] exactMethods = matcher.getMethodMatcher().getExactMethods();
if (exactMethods == null || exactMethods.length == 0) {
methodMatchers.put(matcher.getMethodMatcher(), matcher);
} else {
for (Method m : exactMethods) {
if (OptimizedClassMatcher.METHODS_WE_NEVER_INSTRUMENT.contains(m)) {
Agent.LOG.severe("Skipping method matcher for method " + m);
Agent.LOG.fine("Skipping matcher for class matcher " + matcher.getClassMatcher());
} else {
if (OptimizedClassMatcher.DEFAULT_CONSTRUCTOR.equals(m)) {
Agent.LOG.severe("Instrumentation is matching a default constructor. This may result in slow class loading times.");
Agent.LOG.debug("No arg constructor matcher: " + matcher.getClassMatcher());
}
methods.put(m, matcher);
}
}
}
}
return this;
}
use of com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher in project newrelic-java-agent by newrelic.
the class OptimizedClassMatcherTest method before.
@Before
public void before() {
initializeServiceManager();
OptimizedClassMatcherBuilder builder = OptimizedClassMatcherBuilder.newBuilder();
match1 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Collection.class), new ExactMethodMatcher("size", "()I"));
match2 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("get", "(I)Ljava/lang/Object;"));
match3 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(InvocationHandler.class), new ExactMethodMatcher("invoke", "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"));
match4 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Statement.class), new AllMethodsMatcher());
match5 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Runnable.class), OrMethodMatcher.getMethodMatcher(new NameMethodMatcher("run"), new ExactMethodMatcher("bogus", "()V")));
match6 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Map.class), new AccessMethodMatcher(Opcodes.ACC_PUBLIC));
match7 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("add", "(Ljava/lang/Object;)Z"));
annotationMatch = new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AnnotationMethodMatcher(Type.getType(MyAnnotation.class)));
// this is a bogus matcher to attempt to throw off match5
builder.addClassMethodMatcher(new DefaultClassAndMethodMatcher(createInterfaceMatcher(PreparedStatement.class), new NameMethodMatcher("run")));
builder.addClassMethodMatcher(match1);
builder.addClassMethodMatcher(match2);
builder.addClassMethodMatcher(match3);
builder.addClassMethodMatcher(match4);
builder.addClassMethodMatcher(match5);
builder.addClassMethodMatcher(match6);
builder.addClassMethodMatcher(match7);
builder.addClassMethodMatcher(annotationMatch);
this.matcher = builder.build();
}
use of com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher in project newrelic-java-agent by newrelic.
the class ClassesMatcherTest method getMatchingClasses_Annotation.
@Trace
@Test
public void getMatchingClasses_Annotation() {
ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AnnotationMethodMatcher(Type.getType(Trace.class)))).build();
Set<Class<?>> matchingClasses = ClassesMatcher.getMatchingClasses(Collections.singletonList(matcher), matcherHelper, ClassesMatcherTest.class, ArrayList.class, HashMap.class);
assertEquals(1, matchingClasses.size());
assertTrue(matchingClasses.contains(ClassesMatcherTest.class));
}
Aggregations