Skip to content

Commit 26bc117

Browse files
authored
Treat all advice as inline when indy is disabled (#17442)
1 parent 465c8fb commit 26bc117

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/TypeTransformerImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
99
import io.opentelemetry.javaagent.tooling.Utils;
1010
import io.opentelemetry.javaagent.tooling.bytebuddy.ExceptionHandlers;
11+
import io.opentelemetry.javaagent.tooling.instrumentation.indy.AdviceInliningPoolStrategy;
1112
import io.opentelemetry.javaagent.tooling.instrumentation.indy.ForceDynamicallyTypedAssignReturnedFactory;
1213
import java.util.function.Function;
1314
import net.bytebuddy.agent.builder.AgentBuilder;
@@ -33,13 +34,18 @@ public void applyAdviceToMethod(
3334
ElementMatcher<? super MethodDescription> methodMatcher,
3435
Function<Advice.WithCustomMapping, Advice.WithCustomMapping> mappingCustomizer,
3536
String adviceClassName) {
37+
// default strategy used by AgentBuilder.Transformer.ForAdvice
38+
AgentBuilder.PoolStrategy poolStrategy = AgentBuilder.PoolStrategy.Default.FAST;
39+
3640
agentBuilder =
3741
agentBuilder.transform(
3842
new AgentBuilder.Transformer.ForAdvice(mappingCustomizer.apply(adviceMapping))
3943
.include(
4044
Utils.getBootstrapProxy(),
4145
Utils.getAgentClassLoader(),
4246
Utils.getExtensionsClassLoader())
47+
// set the advice "inline" attribute to true
48+
.with(new AdviceInliningPoolStrategy(poolStrategy, true))
4349
.withExceptionHandler(ExceptionHandlers.defaultExceptionHandler())
4450
.advice(methodMatcher, adviceClassName));
4551
}

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/AdviceUninliningPoolStrategy.java renamed to javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/AdviceInliningPoolStrategy.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,40 @@
2424
import org.jetbrains.annotations.NotNull;
2525

2626
/**
27-
* Pool strategy that sets "inline" attribute to false on {@link Advice.OnMethodEnter} and {@link
27+
* Pool strategy that sets "inline" attribute on {@link Advice.OnMethodEnter} and {@link
2828
* Advice.OnMethodExit} annotations.
2929
*/
30-
class AdviceUninliningPoolStrategy implements AgentBuilder.PoolStrategy {
30+
public class AdviceInliningPoolStrategy implements AgentBuilder.PoolStrategy {
3131
private final AgentBuilder.PoolStrategy poolStrategy;
32+
private final boolean inline;
3233

33-
public AdviceUninliningPoolStrategy(AgentBuilder.PoolStrategy poolStrategy) {
34+
public AdviceInliningPoolStrategy(AgentBuilder.PoolStrategy poolStrategy, boolean inline) {
3435
this.poolStrategy = poolStrategy;
36+
this.inline = inline;
3537
}
3638

3739
@NotNull
3840
@Override
3941
public TypePool typePool(@NotNull ClassFileLocator classFileLocator, ClassLoader classLoader) {
4042
TypePool typePool = poolStrategy.typePool(classFileLocator, classLoader);
41-
return new TypePoolWrapper(typePool);
43+
return new TypePoolWrapper(typePool, inline);
4244
}
4345

4446
@NotNull
4547
@Override
4648
public TypePool typePool(
4749
@NotNull ClassFileLocator classFileLocator, ClassLoader classLoader, @NotNull String name) {
4850
TypePool typePool = poolStrategy.typePool(classFileLocator, classLoader, name);
49-
return new TypePoolWrapper(typePool);
51+
return new TypePoolWrapper(typePool, inline);
5052
}
5153

5254
private static class TypePoolWrapper implements TypePool {
5355
private final TypePool typePool;
56+
private final boolean inline;
5457

55-
TypePoolWrapper(TypePool typePool) {
58+
TypePoolWrapper(TypePool typePool, boolean inline) {
5659
this.typePool = typePool;
60+
this.inline = inline;
5761
}
5862

5963
@NotNull
@@ -96,7 +100,7 @@ class MethodListWrapper
96100

97101
@Override
98102
public MethodDescription.InDefinedShape get(int index) {
99-
return new MethodDescriptionWrapper(methods.get(index));
103+
return new MethodDescriptionWrapper(methods.get(index), inline);
100104
}
101105

102106
@Override
@@ -119,9 +123,11 @@ public void clear() {
119123
}
120124

121125
private static class MethodDescriptionWrapper extends DelegatingMethodDescription {
126+
private final boolean inline;
122127

123-
MethodDescriptionWrapper(MethodDescription.InDefinedShape method) {
128+
MethodDescriptionWrapper(MethodDescription.InDefinedShape method, boolean inline) {
124129
super(method);
130+
this.inline = inline;
125131
}
126132

127133
@NotNull
@@ -141,9 +147,9 @@ public AnnotationDescription get(int index) {
141147
return annotation;
142148
}
143149

144-
// replace value for "inline" attribute with false
150+
// replace value for "inline" attribute
145151
return replaceAnnotationValue(
146-
annotation, "inline", oldVal -> AnnotationValue.ForConstant.of(false));
152+
annotation, "inline", oldVal -> AnnotationValue.ForConstant.of(inline));
147153
}
148154

149155
@Override

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyTypeTransformerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public void applyAdviceToMethod(
6262
.advice(methodMatcher, adviceClassName)
6363
// advice transformation already performs uninlining
6464
.with(
65-
transformAdvice ? poolStrategy : new AdviceUninliningPoolStrategy(poolStrategy))
65+
transformAdvice
66+
? poolStrategy
67+
: new AdviceInliningPoolStrategy(poolStrategy, false))
6668
.include(getAdviceLocator(instrumentationModule.getClass().getClassLoader()))
6769
.withExceptionHandler(ExceptionHandlers.defaultExceptionHandler()));
6870
}

0 commit comments

Comments
 (0)