Merge pull request #1262 from DataDog/mar-kolya/upkeep

Upkeep
This commit is contained in:
Nikolay Martynov 2020-02-27 15:55:16 +01:00 committed by GitHub
commit e8d13aad23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 10 deletions

View File

@ -217,11 +217,13 @@ public interface Instrumenter {
public abstract Map<? extends ElementMatcher<? super MethodDescription>, String> transformers();
/**
* A map of {class-name -> context-class-name}. Keys (and their subclasses) will be associated
* with a context of the value.
* Context stores to define for this instrumentation.
*
* <p>A map of {class-name -> context-class-name}. Keys (and their subclasses) will be
* associated with a context of the value.
*/
public Map<String, String> contextStore() {
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}
protected boolean defaultEnabled() {

View File

@ -28,4 +28,9 @@ class SafeExtendsClassMatcher<T extends TypeDescription>
}
return false;
}
@Override
public String toString() {
return "safeExtendsClass(" + matcher + ")";
}
}

View File

@ -127,8 +127,8 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
@Override
public AgentBuilder.Identified.Extendable instrumentationTransformer(
AgentBuilder.Identified.Extendable builder) {
if (instrumenter.contextStore().size() > 0) {
/**
if (!instrumenter.contextStore().isEmpty()) {
/*
* Install transformer that rewrites accesses to context store with specialized bytecode that
* invokes appropriate storage implementation.
*/
@ -304,14 +304,14 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
private AgentBuilder.Identified.Extendable injectHelpersIntoBootstrapClassloader(
AgentBuilder.Identified.Extendable builder) {
/**
/*
* We inject into bootstrap classloader because field accessor interfaces are needed by context
* store implementations. Unfortunately this forces us to remove stored type checking because
* actual classes may not be available at this point.
*/
builder = builder.transform(fieldAccessorInterfacesInjector);
/**
/*
* We inject context store implementation into bootstrap classloader because same implementation
* may be used by different instrumentations and it has to use same static map in case of
* fallback to map-backed storage.
@ -348,7 +348,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
if (fieldInjectionEnabled) {
for (final Map.Entry<String, String> entry : instrumenter.contextStore().entrySet()) {
/**
/*
* For each context store defined in a current instrumentation we create an agent builder
* that injects necessary fields.
*/
@ -363,7 +363,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
.and(not(isAnnotatedWith(named("javax.decorator.Decorator"))))
.transform(AgentBuilder.Transformer.NoOp.INSTANCE);
/**
/*
* We inject helpers here as well as when instrumentation is applied to ensure that helpers
* are present even if instrumented classes are not loaded, but classes with state fields
* added are loaded (e.g. sun.net.www.protocol.https.HttpsURLConnectionImpl).
@ -388,7 +388,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
final JavaModule module,
final Class<?> classBeingRedefined,
final ProtectionDomain protectionDomain) {
/**
/*
* The idea here is that we can add fields if class is just being loaded
* (classBeingRedefined == null) and we have to add same fields again if class we added
* fields before is being transformed again. Note: here we assume that Class#getInterfaces()