Skip to content

Commit 2456716

Browse files
committed
Removed eager advice loading
1 parent 33b6130 commit 2456716

File tree

4 files changed

+2
-61
lines changed

4 files changed

+2
-61
lines changed

instrumentation/internal/internal-class-loader/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/classloader/ClassLoaderInstrumentationModule.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ public boolean isHelperClass(String className) {
3434
return className.equals("io.opentelemetry.javaagent.tooling.Constants");
3535
}
3636

37-
@Override
38-
public boolean loadAdviceClassesEagerly() {
39-
// This is required due to DefineClassInstrumentation
40-
// Without this, we would get an infinite recursion on bootstrapping of that instrumentation:
41-
// 1. ClassLoader.defineClass is invoked somewhere
42-
// 2. The inserted invokedynamic for the instrumentation is reached
43-
// 3. To bootstrap the advice, IndyBootstrap is invoked
44-
// 4. IndyBootstrap tries to load the DefineClassInstrumentation Advice class
45-
// 5. The loading calls ClassLoader.defineClass -> recursion, BOOM!
46-
// We avoid this recursion by ensuring that the DefineClassInstrumentation Advice class
47-
// is loaded eagerly before the corresponding invokedynamic is reached
48-
return true;
49-
}
50-
5137
@Override
5238
public List<TypeInstrumentation> typeInstrumentations() {
5339
return asList(

instrumentation/internal/internal-class-loader/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/classloader/DefineClassInstrumentation.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,10 @@ public static DefineClassContext onEnter(
5252
classLoader, className, classBytes, offset, length);
5353
}
5454

55-
// TODO: the ToReturned does nothing except for signaling the AdviceTransformer that it must
56-
// not touch this advice
57-
// this is done to ensure that ClassLoaderInstrumentationModule.loadAdviceClassesEagerly works
58-
// correctly
59-
// we can therefore remove it, as soon as the AdviceTransformer is not applied anymore
6055
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
61-
@Advice.AssignReturned.ToReturned
62-
public static Class<?> onExit(
56+
public static void onExit(
6357
@Advice.Enter DefineClassContext context, @Advice.Return Class<?> returned) {
6458
DefineClassHelper.afterDefineClass(context);
65-
return returned;
6659
}
6760
}
6861

@@ -76,17 +69,10 @@ public static DefineClassContext onEnter(
7669
return DefineClassHelper.beforeDefineClass(classLoader, className, classBytes);
7770
}
7871

79-
// TODO: the ToReturned does nothing except for signaling the AdviceTransformer that it must
80-
// not touch this advice
81-
// this is done to ensure that ClassLoaderInstrumentationModule.loadAdviceClassesEagerly works
82-
// correctly
83-
// we can therefore remove it, as soon as the AdviceTransformer is not applied anymore
8472
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
85-
@Advice.AssignReturned.ToReturned
86-
public static Class<?> onExit(
73+
public static void onExit(
8774
@Advice.Enter DefineClassContext context, @Advice.Return Class<?> returned) {
8875
DefineClassHelper.afterDefineClass(context);
89-
return returned;
9076
}
9177
}
9278
}

javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/instrumentation/internal/ExperimentalInstrumentationModule.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,4 @@ default String getModuleGroup() {
6161
default List<String> agentPackagesToHide() {
6262
return Collections.emptyList();
6363
}
64-
65-
/**
66-
* By default, Advice classes are loaded lazily the first time the corresponding instrumented
67-
* method is invoked. This function allows to change the behaviour so that all Advice classes are
68-
* loaded and initialized as soon as a matching type is instrumented.
69-
*
70-
* <p>Note: this functionality currently does not work together with the AdviceTransformer.
71-
* Therefore you should make your Advices indy-compatible (use @Advice.AssignReturned) before
72-
* using this feature.
73-
*
74-
* @return true, if Advice classes should be loaded on instrumentation instead of first execution
75-
*/
76-
default boolean loadAdviceClassesEagerly() {
77-
return false;
78-
}
7964
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Map;
2626
import java.util.Set;
2727
import java.util.concurrent.ConcurrentHashMap;
28-
import java.util.logging.Level;
2928
import java.util.logging.Logger;
3029
import java.util.stream.Collectors;
3130
import javax.annotation.Nullable;
@@ -158,21 +157,6 @@ public synchronized void installModule(InstrumentationModule module) {
158157
ExperimentalInstrumentationModule experimentalModule =
159158
(ExperimentalInstrumentationModule) module;
160159
hiddenAgentPackages.addAll(experimentalModule.agentPackagesToHide());
161-
if (experimentalModule.loadAdviceClassesEagerly()) {
162-
for (String adviceClass : getModuleAdviceNames(module)) {
163-
try {
164-
this.loadClass(adviceClass, true);
165-
} catch (ClassNotFoundException e) {
166-
logger.log(
167-
Level.SEVERE,
168-
"Failed to eagerly load advice class {0}",
169-
new Object[] {adviceClass, e});
170-
}
171-
}
172-
// We also eagerly load the LookupExposer, because that is also required for invokedynamic
173-
// bootstrapping
174-
getLookup();
175-
}
176160
}
177161
}
178162

0 commit comments

Comments
 (0)