44import static net .bytebuddy .jar .asm .ClassReader .SKIP_CODE ;
55import static net .bytebuddy .jar .asm .ClassReader .SKIP_DEBUG ;
66
7+ import datadog .instrument .classmatch .ClassFile ;
8+ import datadog .trace .api .InstrumenterConfig ;
79import java .lang .annotation .Annotation ;
810import java .lang .reflect .Field ;
911import java .lang .reflect .Method ;
1820
1921/** Attempts a minimal parse of just the named elements we need for matching. */
2022final class OutlineTypeParser implements TypeParser {
23+ private static final boolean visitorClassParsing =
24+ InstrumenterConfig .get ().isVisitorClassParsing ();
2125
2226 @ Override
2327 public TypeDescription parse (byte [] bytecode ) {
24- ClassReader classReader = OpenedClassReader .of (bytecode );
25- OutlineTypeExtractor typeExtractor = new OutlineTypeExtractor ();
26- classReader .accept (typeExtractor , SKIP_CODE | SKIP_DEBUG );
27- return typeExtractor .typeOutline ;
28+ if (visitorClassParsing ) {
29+ ClassReader classReader = OpenedClassReader .of (bytecode );
30+ OutlineTypeExtractor typeExtractor = new OutlineTypeExtractor ();
31+ classReader .accept (typeExtractor , SKIP_CODE | SKIP_DEBUG );
32+ return typeExtractor .typeOutline ;
33+ } else {
34+ return new TypeOutline (ClassFile .outline (bytecode ));
35+ }
2836 }
2937
3038 @ Override
@@ -39,7 +47,7 @@ public TypeDescription parse(Class<?> loadedType) {
3947 extractTypeNames (loadedType .getInterfaces ()));
4048
4149 for (Annotation a : loadedType .getDeclaredAnnotations ()) {
42- typeOutline .declare (annotationOutline (Type .getDescriptor (a .annotationType ())));
50+ typeOutline .declare (annotationOutline (Type .getInternalName (a .annotationType ())));
4351 }
4452
4553 for (Field field : loadedType .getDeclaredFields ()) {
@@ -50,7 +58,7 @@ public TypeDescription parse(Class<?> loadedType) {
5058 field .getName (),
5159 Type .getDescriptor (field .getType ()));
5260 for (Annotation a : field .getDeclaredAnnotations ()) {
53- fieldOutline .declare (annotationOutline (Type .getDescriptor (a .annotationType ())));
61+ fieldOutline .declare (annotationOutline (Type .getInternalName (a .annotationType ())));
5462 }
5563 typeOutline .declare (fieldOutline );
5664 }
@@ -63,7 +71,7 @@ public TypeDescription parse(Class<?> loadedType) {
6371 method .getName (),
6472 Type .getMethodDescriptor (method ));
6573 for (Annotation a : method .getDeclaredAnnotations ()) {
66- methodOutline .declare (annotationOutline (Type .getDescriptor (a .annotationType ())));
74+ methodOutline .declare (annotationOutline (Type .getInternalName (a .annotationType ())));
6775 }
6876 typeOutline .declare (methodOutline );
6977 }
0 commit comments