Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muzzle match only once in each class loader #4543

Merged
merged 4 commits into from
Nov 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;

import io.opentelemetry.instrumentation.api.caching.Cache;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.tooling.HelperInjector;
Expand Down Expand Up @@ -124,6 +125,8 @@ AgentBuilder install(
private static class MuzzleMatcher implements AgentBuilder.RawMatcher {
private final InstrumentationModule instrumentationModule;
private final AtomicBoolean initialized = new AtomicBoolean(false);
private final Cache<ClassLoader, Boolean> matchingResult =
Cache.builder().setWeakKeys().build();
private volatile ReferenceMatcher referenceMatcher;

private MuzzleMatcher(InstrumentationModule instrumentationModule) {
Expand All @@ -141,6 +144,12 @@ public boolean matches(
if (classLoader == BOOTSTRAP_LOADER) {
classLoader = Utils.getBootstrapProxy();
}

Boolean cachedResult = matchingResult.get(classLoader);
mateuszrzeszutek marked this conversation as resolved.
Show resolved Hide resolved
if (cachedResult != null) {
return cachedResult.booleanValue();
}

boolean isMatch = muzzle.matches(classLoader);

if (!isMatch) {
Expand All @@ -165,6 +174,8 @@ public boolean matches(
}
}

matchingResult.put(classLoader, isMatch);

return isMatch;
}

Expand Down