googleJavaFormat & codeNarc

This commit is contained in:
dougqh 2020-01-23 11:15:39 -05:00
parent 726236bd64
commit 984d77e44c
2 changed files with 26 additions and 33 deletions

View File

@ -29,17 +29,17 @@ import net.bytebuddy.pool.TypePool;
* that combines loader ID & name
* </ul>
*
* <p>This design was chosen to create a single limited size cache that can be adjusted
* for the entire application -- without having to create a large number of WeakReference objects.
* <p>This design was chosen to create a single limited size cache that can be adjusted for the
* entire application -- without having to create a large number of WeakReference objects.
*
* <p>The ID assignment mostly assigns a single ID to each ClassLoader, but the maximumSize
* restriction means that an evicted ClassLoader could be assigned another ID later on.
*
* <p>For the validity of the cache, the important part is that ID assignment guarantees that
* no two ClassLoaders share the same ID.
* <p>For the validity of the cache, the important part is that ID assignment guarantees that no two
* ClassLoaders share the same ID.
*
* <p>NOTE: As an additional safe-guard, a new CacheInstance can be created if the original loader ID
* sequence is exhausted.
* <p>NOTE: As an additional safe-guard, a new CacheInstance can be created if the original loader
* ID sequence is exhausted.
*/
@Slf4j
public class DDCachingPoolStrategy implements PoolStrategy {
@ -192,9 +192,7 @@ public class DDCachingPoolStrategy implements PoolStrategy {
private final TypePool createCachingTypePool(
final long loaderId, final ClassFileLocator classFileLocator) {
return new TypePool.Default.WithLazyResolution(
createCacheProvider(loaderId),
classFileLocator,
TypePool.Default.ReaderMode.FAST);
createCacheProvider(loaderId), classFileLocator, TypePool.Default.ReaderMode.FAST);
}
private final TypePool createCachingTypePool(
@ -255,10 +253,11 @@ public class DDCachingPoolStrategy implements PoolStrategy {
@Override
public TypePool.Resolution find(final String name) {
TypePool.Resolution existingResolution = sharedResolutionCache.getIfPresent(new TypeCacheKey(cacheId, name));
if ( existingResolution != null ) return existingResolution;
TypePool.Resolution existingResolution =
sharedResolutionCache.getIfPresent(new TypeCacheKey(cacheId, name));
if (existingResolution != null) return existingResolution;
if ( OBJECT_NAME.equals(name) ) {
if (OBJECT_NAME.equals(name)) {
return OBJECT_RESOLUTION;
}
@ -267,7 +266,7 @@ public class DDCachingPoolStrategy implements PoolStrategy {
@Override
public TypePool.Resolution register(final String name, final TypePool.Resolution resolution) {
if ( OBJECT_NAME.equals(name) ) {
if (OBJECT_NAME.equals(name)) {
return resolution;
}

View File

@ -1,18 +1,12 @@
package datadog.trace.agent.tooling
import datadog.trace.util.gc.GCUtils
import datadog.trace.util.test.DDSpecification
import net.bytebuddy.description.type.TypeDescription
import net.bytebuddy.dynamic.ClassFileLocator
import net.bytebuddy.pool.TypePool
import spock.lang.Timeout
import java.lang.ref.WeakReference
import java.security.SecureClassLoader
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
import static datadog.trace.agent.tooling.AgentTooling.CLEANER
@Timeout(5)
class CacheProviderTest extends DDSpecification {
@ -52,9 +46,9 @@ class CacheProviderTest extends DDSpecification {
def "test basic caching"() {
setup:
def cacheInstance = new DDCachingPoolStrategy.CacheInstance();
def cacheInstance = new DDCachingPoolStrategy.CacheInstance()
def cacheProvider = cacheInstance.createCacheProvider(1);
def cacheProvider = cacheInstance.createCacheProvider(1)
when:
cacheProvider.register("foo", new TypePool.Resolution.Simple(TypeDescription.VOID))
@ -67,10 +61,10 @@ class CacheProviderTest extends DDSpecification {
def "test ID equivalence"() {
setup:
def cacheInstance = new DDCachingPoolStrategy.CacheInstance();
def cacheInstance = new DDCachingPoolStrategy.CacheInstance()
def cacheProvider1A = cacheInstance.createCacheProvider(1);
def cacheProvider1B = cacheInstance.createCacheProvider(1);
def cacheProvider1A = cacheInstance.createCacheProvider(1)
def cacheProvider1B = cacheInstance.createCacheProvider(1)
when:
cacheProvider1A.register("foo", newVoid())
@ -86,10 +80,10 @@ class CacheProviderTest extends DDSpecification {
def "test ID separation"() {
setup:
def cacheInstance = new DDCachingPoolStrategy.CacheInstance();
def cacheInstance = new DDCachingPoolStrategy.CacheInstance()
def cacheProvider1 = cacheInstance.createCacheProvider(1);
def cacheProvider2 = cacheInstance.createCacheProvider(2);
def cacheProvider1 = cacheInstance.createCacheProvider(1)
def cacheProvider2 = cacheInstance.createCacheProvider(2)
when:
cacheProvider1.register("foo", newVoid())
@ -173,8 +167,8 @@ class CacheProviderTest extends DDSpecification {
def cacheInstance = new DDCachingPoolStrategy.CacheInstance()
def capacity = DDCachingPoolStrategy.CacheInstance.TYPE_CAPACITY
def cacheProvider1 = cacheInstance.createCacheProvider(1);
def cacheProvider2 = cacheInstance.createCacheProvider(2);
def cacheProvider1 = cacheInstance.createCacheProvider(1)
def cacheProvider2 = cacheInstance.createCacheProvider(2)
def id = 0
@ -201,15 +195,15 @@ class CacheProviderTest extends DDSpecification {
cacheInstance.approximateSize() > capacity - 4
}
static def newVoid() {
static newVoid() {
return new TypePool.Resolution.Simple(TypeDescription.VOID)
}
static def newClassLoader() {
return new SecureClassLoader(null) {};
static newClassLoader() {
return new SecureClassLoader(null) {}
}
static def newLocator() {
static newLocator() {
return new ClassFileLocator() {
@Override
ClassFileLocator.Resolution locate(String name) throws IOException {