googleJavaFormat, codeNarcTest, and test reliability
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/DDCachingPoolStrategy.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/DDCachingPoolStrategy.java
@@ -4,9 +4,7 @@ import static net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
-
import java.lang.ref.WeakReference;
-
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
@@ -54,9 +52,10 @@ public class DDCachingPoolStrategy implements PoolStrategy {
/**
* Cache of recent ClassLoader WeakReferences; used to...
+ *
* <ul>
- * <li>Reduced number of WeakReferences created</li>
- * <li>Allow for quick fast path equivalence check of composite keys</li>
+ * <li>Reduced number of WeakReferences created
+ * <li>Allow for quick fast path equivalence check of composite keys
* </ul>
*/
final Cache<ClassLoader, WeakReference<ClassLoader>> loaderRefCache =
@@ -68,8 +67,7 @@ public class DDCachingPoolStrategy implements PoolStrategy {
.build();
/**
- * Single shared Type.Resolution cache -- uses a composite key --
- * conceptually of loader & name
+ * Single shared Type.Resolution cache -- uses a composite key -- conceptually of loader & name
*/
final Cache<TypeCacheKey, TypePool.Resolution> sharedResolutionCache =
CacheBuilder.newBuilder()
@@ -107,9 +105,7 @@ public class DDCachingPoolStrategy implements PoolStrategy {
}
private final TypePool.CacheProvider createCacheProvider(
- final int loaderHash,
- final WeakReference<ClassLoader> loaderRef)
- {
+ final int loaderHash, final WeakReference<ClassLoader> loaderRef) {
return new SharedResolutionCacheAdapter(loaderHash, loaderRef, sharedResolutionCache);
}
@@ -145,10 +141,7 @@ public class DDCachingPoolStrategy implements PoolStrategy {
private final int hashCode;
TypeCacheKey(
- final int loaderHash,
- final WeakReference<ClassLoader> loaderRef,
- final String className)
- {
+ final int loaderHash, final WeakReference<ClassLoader> loaderRef, final String className) {
this.loaderHash = loaderHash;
this.loaderRef = loaderRef;
this.className = className;
@@ -226,7 +219,8 @@ public class DDCachingPoolStrategy implements PoolStrategy {
}
@Override
- public TypePool.Resolution register(final String className, final TypePool.Resolution resolution) {
+ public TypePool.Resolution register(
+ final String className, final TypePool.Resolution resolution) {
if (OBJECT_NAME.equals(className)) {
return resolution;
}

MODIFY
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/CacheProviderTest.groovy
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/tooling/CacheProviderTest.groovy
@@ -7,12 +7,11 @@ import net.bytebuddy.pool.TypePool
import spock.lang.Timeout
import java.lang.ref.WeakReference
-import java.security.SecureClassLoader
@Timeout(5)
class CacheProviderTest extends DDSpecification {
def "key bootstrap equivalence"() {
- def loader = null
+ // def loader = null
def loaderHash = DDCachingPoolStrategy.BOOTSTRAP_HASH
def loaderRef = null
@@ -197,7 +196,7 @@ class CacheProviderTest extends DDSpecification {
then:
// cache will start to proactively free slots & size calc is approximate
- poolStrat.approximateSize() > capacity - 4
+ poolStrat.approximateSize() > 0.9 * capacity
}
static newVoid() {
@@ -205,7 +204,7 @@ class CacheProviderTest extends DDSpecification {
}
static newClassLoader() {
- return new URLClassLoader([] as URL[], (ClassLoader)null);
+ return new URLClassLoader([] as URL[], (ClassLoader)null)
}
static newLocator() {

googleJavaFormat, codeNarcTest, and test reliability