Remove ReplaceIsSafeVisitor
MODIFY
dd-java-agent-ittests/src/test/groovy/datadog/trace/agent/integration/muzzle/MuzzleBytecodeTransformTest.groovy
dd-java-agent-ittests/src/test/groovy/datadog/trace/agent/integration/muzzle/MuzzleBytecodeTransformTest.groovy
@@ -11,7 +11,7 @@ class MuzzleBytecodeTransformTest extends Specification {
List<Class> unMuzzledClasses = []
for (final Object instrumenter : ServiceLoader.load(IntegrationTestUtils.getAgentClassLoader().loadClass("datadog.trace.agent.tooling.Instrumenter"), IntegrationTestUtils.getAgentClassLoader())) {
try {
- instrumenter.getClass().getDeclaredField("referenceMatcher")
+ instrumenter.getClass().getDeclaredField("instrumentationMuzzle")
} catch(NoSuchFieldException nsfe) {
unMuzzledClasses.add(instrumenter.getClass())
}

MODIFY
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/DatadogClassLoader.java
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/DatadogClassLoader.java
@@ -39,7 +39,8 @@ public class DatadogClassLoader extends URLClassLoader {
}
/**
- * A stand-in for the bootstrap classloader. Used to look up bootstrap resources and resources appended by instrumentation.
+ * A stand-in for the bootstrap classloader. Used to look up bootstrap resources and resources
+ * appended by instrumentation.
*
* <p>This class is thread safe.
*/

MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/AdviceReferenceVisitor.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/AdviceReferenceVisitor.java
@@ -85,7 +85,7 @@ public class AdviceReferenceVisitor extends ClassVisitor {
final Set<String> visitedSources = new HashSet<String>();
final Map<String, Reference> references = new HashMap<>();
- final Queue<String> instrumentationQueue = new LinkedList<>();
+ final Queue<String> instrumentationQueue = new ArrayDeque<>();
instrumentationQueue.add(entryPointClassName);
while (!instrumentationQueue.isEmpty()) {

MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/MuzzleVisitor.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/MuzzleVisitor.java
@@ -12,9 +12,8 @@ import net.bytebuddy.jar.asm.*;
import net.bytebuddy.pool.TypePool;
/**
- * Add a referenceMatcher field and 2.
- *
- * <p>And for each decorator add a final transformer to assert the classpath is safe instrument.
+ * Add a instrumentationMuzzle field and for each decorator add a final transformer to assert the
+ * classpath is safe instrument.
*/
public class MuzzleVisitor implements AsmVisitorWrapper {
@Override
@@ -71,7 +70,6 @@ public class MuzzleVisitor implements AsmVisitorWrapper {
if ("<init>".equals(name)) {
methodVisitor = new InitializeFieldVisitor(methodVisitor);
}
- // return new ReplaceIsSafeVisitor(methodVisitor);
return new InsertMuzzleTransformer(methodVisitor);
}
@@ -79,7 +77,7 @@ public class MuzzleVisitor implements AsmVisitorWrapper {
public void visitEnd() {
super.visitField(
Opcodes.ACC_PUBLIC,
- "referenceMatcher",
+ "instrumentationMuzzle",
Type.getDescriptor(ReferenceMatcher.class),
null,
null);
@@ -91,7 +89,7 @@ public class MuzzleVisitor implements AsmVisitorWrapper {
* &nbsp.transform(DDAdvice.create().advice(named("fooMethod", FooAdvice.class.getname())))
* &nbsp.asDecorator(); Into this:<br>
* &nbsp.transform(DDAdvice.create().advice(named("fooMethod", FooAdvice.class.getname())))
- * &nbsp.transform(this.referenceMatcher.assertSafeTransformation("foo.package.FooAdvice"));
+ * &nbsp.transform(this.instrumentationMuzzle.assertSafeTransformation("foo.package.FooAdvice"));
* &nbsp.asDecorator(); className)
*/
public class InsertMuzzleTransformer extends MethodVisitor {
@@ -138,7 +136,7 @@ public class MuzzleVisitor implements AsmVisitorWrapper {
this.visitFieldInsn(
Opcodes.GETFIELD,
instrumentationClassName,
- "referenceMatcher",
+ "instrumentationMuzzle",
Type.getDescriptor(ReferenceMatcher.class));
mv.visitIntInsn(Opcodes.BIPUSH, adviceClassNames.size());
mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String");
@@ -184,53 +182,6 @@ public class MuzzleVisitor implements AsmVisitorWrapper {
}
}
- /**
- * Replace:<br>
- * &nbsp&nbsp advice(elementMatcher, className)<br>
- * Into:<br>
- * &nbsp&nbsp advice(this.referenceMatcher.createElementMatcher(elementMatcher, className),
- * className)
- */
- public class ReplaceIsSafeVisitor extends MethodVisitor {
- public ReplaceIsSafeVisitor(MethodVisitor methodVisitor) {
- super(Opcodes.ASM6, methodVisitor);
- }
-
- @Override
- public void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String descriptor,
- final boolean isInterface) {
- if (name.equals("advice")) {
- // stack: [class, matcher]
- this.visitVarInsn(Opcodes.ALOAD, 0);
- // stack: [this, class, matcher]
- this.visitFieldInsn(
- Opcodes.GETFIELD,
- instrumentationClassName,
- "referenceMatcher",
- Type.getDescriptor(ReferenceMatcher.class));
- // stack: [referenceMatcher, class, matcher]
- this.visitInsn(Opcodes.DUP2_X1);
- // stack: [referenceMatcher, class, matcher, referenceMatcher, class]
- this.visitInsn(Opcodes.POP);
- // stack: [class, matcher, referenceMatcher, class]
- this.visitMethodInsn(
- Opcodes.INVOKEVIRTUAL,
- "datadog/trace/agent/tooling/muzzle/ReferenceMatcher",
- "createElementMatcher",
- "(Lnet/bytebuddy/matcher/ElementMatcher;Ljava/lang/String;)Lnet/bytebuddy/matcher/ElementMatcher;",
- false);
- // stack: [safe-matcher, class]
- this.visitInsn(Opcodes.SWAP);
- // stack: [class, safe-matcher]
- }
- super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
- }
- }
-
/** Append a field initializer to the end of a method. */
public class InitializeFieldVisitor extends MethodVisitor {
public InitializeFieldVisitor(MethodVisitor methodVisitor) {
@@ -252,7 +203,7 @@ public class MuzzleVisitor implements AsmVisitorWrapper {
super.visitFieldInsn(
Opcodes.PUTFIELD,
instrumentationClassName.replace('.', '/'),
- "referenceMatcher",
+ "instrumentationMuzzle",
Type.getDescriptor(ReferenceMatcher.class));
}
super.visitInsn(opcode);

Remove ReplaceIsSafeVisitor