Skip to content

Commit cfd7f94

Browse files
authored
Merge pull request #2155 from DataDog/tyler/muzzle-super
2 parents 7d6a41b + 5d9ca5f commit cfd7f94

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/ReferenceCreator.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class ReferenceCreator extends ClassVisitor {
3535
*/
3636
private static final String REFERENCE_CREATION_PACKAGE = "datadog.trace.instrumentation.";
3737

38+
private static final int UNDEFINED_LINE = -1;
39+
3840
/**
3941
* Generate all references reachable from a given class.
4042
*
@@ -180,9 +182,18 @@ public void visit(
180182
refSourceClassName = Utils.getClassName(name);
181183
refSourceType = Type.getType("L" + name + ";");
182184
refSourceTypeInternalName = refSourceType.getInternalName();
183-
// Additional references we could check
184-
// - supertype of class and visible from this package
185-
// - interfaces of class and visible from this package
185+
186+
// Add references to each of the interfaces.
187+
for (String iface : interfaces) {
188+
addReference(
189+
new Reference.Builder(iface)
190+
.withSource(
191+
refSourceClassName,
192+
UNDEFINED_LINE) // We don't have a specific line number to use.
193+
.withFlag(Reference.Flag.PUBLIC)
194+
.build());
195+
}
196+
// the super type is handled by the method visitor to the constructor.
186197
super.visit(version, access, name, signature, superName, interfaces);
187198
}
188199

@@ -215,7 +226,7 @@ public MethodVisitor visitMethod(
215226
}
216227

217228
private class AdviceReferenceMethodVisitor extends MethodVisitor {
218-
private int currentLineNumber = -1;
229+
private int currentLineNumber = UNDEFINED_LINE;
219230

220231
public AdviceReferenceMethodVisitor(final MethodVisitor methodVisitor) {
221232
super(Opcodes.ASM7, methodVisitor);

dd-java-agent/testing/src/test/groovy/muzzle/ReferenceCreatorTest.groovy

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ class ReferenceCreatorTest extends AgentTestRunner {
6767
references.get('muzzle.TestClasses$MethodBodyAdvice$A') != null
6868
}
6969

70+
def "interface impl creates references"() {
71+
setup:
72+
Map<String, Reference> references = ReferenceCreator.createReferencesFrom(MethodBodyAdvice.SomeImplementation.getName(), this.getClass().getClassLoader())
73+
74+
expect:
75+
references.get('muzzle.TestClasses$MethodBodyAdvice$SomeInterface') != null
76+
references.size() == 1
77+
}
78+
79+
def "child class creates references"() {
80+
setup:
81+
Map<String, Reference> references = ReferenceCreator.createReferencesFrom(MethodBodyAdvice.A2.getName(), this.getClass().getClassLoader())
82+
83+
expect:
84+
references.get('muzzle.TestClasses$MethodBodyAdvice$A') != null
85+
references.size() == 1
86+
}
87+
7088
def "instanceof creates references"() {
7189
setup:
7290
Map<String, Reference> references = ReferenceCreator.createReferencesFrom(InstanceofAdvice.getName(), this.getClass().getClassLoader())
@@ -82,7 +100,7 @@ class ReferenceCreatorTest extends AgentTestRunner {
82100
Map<String, Reference> references = ReferenceCreator.createReferencesFrom(TestClasses.InDyAdvice.getName(), this.getClass().getClassLoader())
83101

84102
expect:
85-
references.get('muzzle.TestClasses$MethodBodyAdvice$SomeImplementation') != null
103+
references.get('muzzle.TestClasses$MethodBodyAdvice$HasMethod') != null
86104
references.get('muzzle.TestClasses$MethodBodyAdvice$B') != null
87105
}
88106

dd-java-agent/testing/src/test/java/muzzle/TestClasses.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ public static boolean instanceofMethod(final Object a) {
9595

9696
// Can't test this until java 7 is dropped.
9797
public static class InDyAdvice {
98-
// public static MethodBodyAdvice.SomeInterface indyMethod(
99-
// final MethodBodyAdvice.SomeImplementation a) {
98+
// public static MethodBodyAdvice.HasMethod indyMethod(final MethodBodyAdvice.HasMethod a) {
10099
// Runnable aStaticMethod = MethodBodyAdvice.B::aStaticMethod;
101-
// return a::someMethod;
100+
// return a::requiredMethod;
102101
// }
103102
}
104103
}

dd-trace-core/src/main/java/datadog/trace/core/PendingTrace.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ private void decrementRefAndMaybeWrite(boolean isRootSpan) {
240240
}
241241
}
242242
if (log.isDebugEnabled()) {
243-
log.debug("t_id={} -> expired reference. pending count={}", traceId, count);
243+
log.debug(
244+
"t_id={} -> expired reference. root={} pending count={}", traceId, isRootSpan, count);
244245
}
245246
}
246247

0 commit comments

Comments
 (0)