Skip to content

Commit

Permalink
Setup SonarQube analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Jul 16, 2017
1 parent e6fa7eb commit 6ccd359
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ addons:
apt:
packages:
- oracle-java8-installer
sonarcloud:
organization: caffeine
token:
secure: "D40GIdgUfGx75Yso8Zjo/E0dIsW9KDDyId5wbBNuozMkxJcS2qOIK1+Ia3GPHKSvkeSQJ/1wVyl3TGJunGZB/dLoZvrqtKwaLCOa/9TZA1+Uc80W88uvaZ5yhoZP4vCQV3ka+2eRBBYUzYUptK0qdpJxWRyAmPFvOqtnHmDYgb4="

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.m2
- $HOME/.sonar/cache
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
6 changes: 6 additions & 0 deletions caffeine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ jar.manifest {
'com.github.benmanes.caffeine.cache.stats'
}

sonarqube {
properties {
property "sonar.exclusions", '**/NodeFactory.java, **/LocalCacheFactory.java'
}
}

task generateLocalCaches(type: JavaExec) {
main = 'com.github.benmanes.caffeine.cache.LocalCacheFactoryGenerator'
classpath = sourceSets.javaPoet.runtimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public static long objectFieldOffset(Class<?> clazz, String fieldName) {
}

static Unsafe load(String openJdk, String android) throws NoSuchMethodException,
SecurityException, InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
InstantiationException, IllegalAccessException, InvocationTargetException {
Field field;
try {
// try OpenJDK field name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ static final class AsyncRemovalListener<K, V>
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void onRemoval(K key, @Nonnull CompletableFuture<V> future, RemovalCause cause) {
future.thenAcceptAsync(value -> {
delegate.onRemoval(key, value, cause);
}, executor);
future.thenAcceptAsync(value -> delegate.onRemoval(key, value, cause), executor);
}

Object writeReplace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public int writes() {
final class BBHeader {

@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
static abstract class PadReadCounter {
abstract static class PadReadCounter {
long p00, p01, p02, p03, p04, p05, p06, p07;
long p10, p11, p12, p13, p14, p15, p16;
}

/** Enforces a memory layout to avoid false sharing by padding the read count. */
static abstract class ReadCounterRef extends PadReadCounter {
abstract static class ReadCounterRef extends PadReadCounter {
static final long READ_OFFSET =
UnsafeAccess.objectFieldOffset(ReadCounterRef.class, "readCounter");

Expand All @@ -141,13 +141,13 @@ void lazySetReadCounter(long count) {
}
}

static abstract class PadWriteCounter extends ReadCounterRef {
abstract static class PadWriteCounter extends ReadCounterRef {
long p20, p21, p22, p23, p24, p25, p26, p27;
long p30, p31, p32, p33, p34, p35, p36;
}

/** Enforces a memory layout to avoid false sharing by padding the write count. */
static abstract class ReadAndWriteCounterRef extends PadWriteCounter {
abstract static class ReadAndWriteCounterRef extends PadWriteCounter {
static final long WRITE_OFFSET =
UnsafeAccess.objectFieldOffset(ReadAndWriteCounterRef.class, "writeCounter");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,8 @@ void setAccessTime(Node<K, V> node, long now) {
* Performs the post-processing work required after a write.
*
* @param task the pending operation to be applied
* @param now the current time, in nanoseconds
*/
void afterWrite(Runnable task, long now) {
void afterWrite(Runnable task) {
if (buffersWrites()) {
for (int i = 0; i < WRITE_BUFFER_RETRIES; i++) {
if (writeBuffer().offer(task)) {
Expand Down Expand Up @@ -1649,13 +1648,13 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) {
return computed;
});
if (prior == node) {
afterWrite(new AddTask(node, newWeight), now);
afterWrite(new AddTask(node, newWeight));
return null;
}
} else {
prior = data.putIfAbsent(node.getKeyReference(), node);
if (prior == null) {
afterWrite(new AddTask(node, newWeight), now);
afterWrite(new AddTask(node, newWeight));
return null;
}
}
Expand Down Expand Up @@ -1714,9 +1713,9 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) {

int weightedDifference = mayUpdate ? (newWeight - oldWeight) : 0;
if ((oldValue == null) || (weightedDifference != 0) || expired) {
afterWrite(new UpdateTask(prior, weightedDifference), now);
afterWrite(new UpdateTask(prior, weightedDifference));
} else if (!onlyIfAbsent && expiresAfterWrite() && withinTolerance) {
afterWrite(new UpdateTask(prior, weightedDifference), now);
afterWrite(new UpdateTask(prior, weightedDifference));
} else {
if (mayUpdate) {
setWriteTime(prior, now);
Expand Down Expand Up @@ -1769,7 +1768,7 @@ V removeNoWriter(Object key) {
K castKey = (K) key;
notifyRemoval(castKey, oldValue, cause);
}
afterWrite(new RemovalTask(node), 0L);
afterWrite(new RemovalTask(node));
return (cause == RemovalCause.EXPLICIT) ? oldValue : null;
}

Expand Down Expand Up @@ -1807,7 +1806,7 @@ V removeWithWriter(Object key) {
});

if (cause[0] != null) {
afterWrite(new RemovalTask(node[0]), now);
afterWrite(new RemovalTask(node[0]));
if (hasRemovalListener()) {
notifyRemoval(castKey, oldValue[0], cause[0]);
}
Expand All @@ -1823,7 +1822,7 @@ public boolean remove(Object key, Object value) {
}

@SuppressWarnings({"unchecked", "rawtypes"})
Node<K, V> removed[] = new Node[1];
Node<K, V>[] removed = new Node[1];
@SuppressWarnings("unchecked")
K[] oldKey = (K[]) new Object[1];
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -1856,7 +1855,7 @@ public boolean remove(Object key, Object value) {
} else if (hasRemovalListener()) {
notifyRemoval(oldKey[0], oldValue[0], cause[0]);
}
afterWrite(new RemovalTask(removed[0]), now);
afterWrite(new RemovalTask(removed[0]));
return (cause[0] == RemovalCause.EXPLICIT);
}

Expand Down Expand Up @@ -1902,7 +1901,7 @@ public V replace(K key, V value) {

int weightedDifference = (weight - oldWeight[0]);
if (expiresAfterWrite() || (weightedDifference != 0)) {
afterWrite(new UpdateTask(node, weightedDifference), now);
afterWrite(new UpdateTask(node, weightedDifference));
} else {
afterRead(node, now, /* recordHit */ false);
}
Expand Down Expand Up @@ -1958,7 +1957,7 @@ public boolean replace(K key, V oldValue, V newValue) {

int weightedDifference = (weight - oldWeight[0]);
if (expiresAfterWrite() || (weightedDifference != 0)) {
afterWrite(new UpdateTask(node, weightedDifference), now);
afterWrite(new UpdateTask(node, weightedDifference));
} else {
afterRead(node, now, /* recordHit */ false);
}
Expand Down Expand Up @@ -2076,7 +2075,7 @@ V doComputeIfAbsent(K key, Object keyRef,

if (node == null) {
if (removed[0] != null) {
afterWrite(new RemovalTask(removed[0]), now);
afterWrite(new RemovalTask(removed[0]));
}
return null;
}
Expand All @@ -2096,10 +2095,10 @@ V doComputeIfAbsent(K key, Object keyRef,
return oldValue[0];
}
if ((oldValue[0] == null) && (cause[0] == null)) {
afterWrite(new AddTask(node, weight[1]), now);
afterWrite(new AddTask(node, weight[1]));
} else {
int weightedDifference = (weight[1] - weight[0]);
afterWrite(new UpdateTask(node, weightedDifference), now);
afterWrite(new UpdateTask(node, weightedDifference));
}

return newValue[0];
Expand Down Expand Up @@ -2257,15 +2256,15 @@ V remap(K key, Object keyRef, BiFunction<? super K, ? super V, ? extends V> rema
}

if (removed[0] != null) {
afterWrite(new RemovalTask(removed[0]), now);
afterWrite(new RemovalTask(removed[0]));
} else if (node == null) {
// absent and not computable
} else if ((oldValue[0] == null) && (cause[0] == null)) {
afterWrite(new AddTask(node, weight[1]), now);
afterWrite(new AddTask(node, weight[1]));
} else {
int weightedDifference = weight[1] - weight[0];
if (expiresAfterWrite() || (weightedDifference != 0)) {
afterWrite(new UpdateTask(node, weightedDifference), now);
afterWrite(new UpdateTask(node, weightedDifference));
} else {
if (cause[0] == null) {
if (!isComputingAsync(node)) {
Expand Down Expand Up @@ -3420,13 +3419,13 @@ Object writeReplace() {
/** The namespace for field padding through inheritance. */
final class BLCHeader {

static abstract class PadDrainStatus<K, V> extends AbstractMap<K, V> {
abstract static class PadDrainStatus<K, V> extends AbstractMap<K, V> {
long p00, p01, p02, p03, p04, p05, p06, p07;
long p10, p11, p12, p13, p14, p15, p16;
}

/** Enforces a memory layout to avoid false sharing by padding the drain status. */
static abstract class DrainStatusRef<K, V> extends PadDrainStatus<K, V> {
abstract static class DrainStatusRef<K, V> extends PadDrainStatus<K, V> {
static final long DRAIN_STATUS_OFFSET =
UnsafeAccess.objectFieldOffset(DrainStatusRef.class, "drainStatus");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ boolean isRecordingStats() {
}

@Nonnull
Supplier<? extends StatsCounter> getStatsCounterSupplier() {
Supplier<StatsCounter> getStatsCounterSupplier() {
return (statsCounterSupplier == null)
? StatsCounter::disabledStatsCounter
: statsCounterSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public V put(K key, V value, boolean notifyWriter) {

// ensures that the removal notification is processed after the removal has completed
@SuppressWarnings({"unchecked", "rawtypes"})
V oldValue[] = (V[]) new Object[1];
V[] oldValue = (V[]) new Object[1];
if ((writer == CacheWriter.disabledWriter()) || !notifyWriter) {
oldValue[0] = data.put(key, value);
} else {
Expand Down Expand Up @@ -416,7 +416,7 @@ public V remove(Object key) {
@SuppressWarnings("unchecked")
K castKey = (K) key;
@SuppressWarnings({"unchecked", "rawtypes"})
V oldValue[] = (V[]) new Object[1];
V[] oldValue = (V[]) new Object[1];

if (writer == CacheWriter.disabledWriter()) {
oldValue[0] = data.remove(key);
Expand Down Expand Up @@ -445,7 +445,7 @@ public boolean remove(Object key, Object value) {
@SuppressWarnings("unchecked")
K castKey = (K) key;
@SuppressWarnings({"unchecked", "rawtypes"})
V oldValue[] = (V[]) new Object[1];
V[] oldValue = (V[]) new Object[1];

data.computeIfPresent(castKey, (k, v) -> {
if (v.equals(value)) {
Expand All @@ -468,7 +468,7 @@ public V replace(K key, V value) {
requireNonNull(value);

@SuppressWarnings({"unchecked", "rawtypes"})
V oldValue[] = (V[]) new Object[1];
V[] oldValue = (V[]) new Object[1];
data.computeIfPresent(key, (k, v) -> {
if (value != v) {
writer.write(key, value);
Expand All @@ -489,7 +489,7 @@ public boolean replace(K key, V oldValue, V newValue) {
requireNonNull(newValue);

@SuppressWarnings({"unchecked", "rawtypes"})
V prev[] = (V[]) new Object[1];
V[] prev = (V[]) new Object[1];
data.computeIfPresent(key, (k, v) -> {
if (v.equals(oldValue)) {
if (newValue != v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public void exceedsMaximumBufferSize_onWrite(Cache<Integer, Integer> cache, Cach
BoundedLocalCache<Integer, Integer> localCache = asBoundedLocalCache(cache);

boolean[] ran = new boolean[1];
localCache.afterWrite(() -> ran[0] = true, 0);
localCache.afterWrite(() -> ran[0] = true);
assertThat(ran[0], is(true));

assertThat(localCache.writeBuffer().size(), is(0));
Expand Down Expand Up @@ -480,7 +480,7 @@ public void afterWrite_drainFullWriteBuffer(Cache<Integer, Integer> cache, Cache

int[] triggered = { 0 };
Runnable triggerTask = () -> triggered[0] = 1 + expectedCount[0];
localCache.afterWrite(triggerTask, 0L);
localCache.afterWrite(triggerTask);

assertThat(processed[0], is(expectedCount[0]));
assertThat(triggered[0], is(expectedCount[0] + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public final class CaffeineSpecTest {
static final long UNSET_LONG = UNSET_INT;

@Test(dataProvider = "caches")
@CacheSpec(population = Population.EMPTY, compute = Compute.SYNC, writer = Writer.DISABLED,
@CacheSpec(initialCapacity = {InitialCapacity.DEFAULT, InitialCapacity.FULL},
population = Population.EMPTY, compute = Compute.SYNC, writer = Writer.DISABLED,
removalListener = Listener.DEFAULT, implementation = Implementation.Caffeine)
public void specifications(CacheContext context) {
CaffeineSpec spec = toSpec(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public int writes() {
/** The namespace for field padding through inheritance. */
final class FastFlowHeader {

static abstract class PadReadCache<E> extends ReadBuffer<E> {
abstract static class PadReadCache<E> extends ReadBuffer<E> {
long p00, p01, p02, p03, p04, p05, p06, p07;
long p10, p11, p12, p13, p14, p15, p16, p17;
}

/** Enforces a memory layout to avoid false sharing by padding the read count. */
static abstract class ReadCacheRef<E> extends PadReadCache<E> {
abstract static class ReadCacheRef<E> extends PadReadCache<E> {
static final long READ_CACHE_OFFSET =
UnsafeAccess.objectFieldOffset(ReadCacheRef.class, "readCache");

Expand All @@ -114,13 +114,13 @@ void lazySetReadCache(long count) {
}
}

static abstract class PadReadCounter<E> extends ReadCacheRef<E> {
abstract static class PadReadCounter<E> extends ReadCacheRef<E> {
long p20, p21, p22, p23, p24, p25, p26, p27;
long p30, p31, p32, p33, p34, p35, p36, p37;
}

/** Enforces a memory layout to avoid false sharing by padding the read count. */
static abstract class ReadCounterRef<E> extends PadReadCounter<E> {
abstract static class ReadCounterRef<E> extends PadReadCounter<E> {
static final long READ_OFFSET =
UnsafeAccess.objectFieldOffset(ReadCounterRef.class, "readCounter");

Expand All @@ -131,13 +131,13 @@ void lazySetReadCounter(long count) {
}
}

static abstract class PadWriteCounter<E> extends ReadCounterRef<E> {
abstract static class PadWriteCounter<E> extends ReadCounterRef<E> {
long p40, p41, p42, p43, p44, p45, p46, p47;
long p50, p51, p52, p53, p54, p55, p56, p57;
}

/** Enforces a memory layout to avoid false sharing by padding the write count. */
static abstract class ReadAndWriteCounterRef<E> extends PadWriteCounter<E> {
abstract static class ReadAndWriteCounterRef<E> extends PadWriteCounter<E> {
static final long WRITE_OFFSET =
UnsafeAccess.objectFieldOffset(ReadAndWriteCounterRef.class, "writeCounter");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public int writes() {
/** The namespace for field padding through inheritance. */
final class ManyToOneHeader {

static abstract class PadReadCounter<E> extends ReadBuffer<E> {
abstract static class PadReadCounter<E> extends ReadBuffer<E> {
long p00, p01, p02, p03, p04, p05, p06, p07;
long p10, p11, p12, p13, p14, p15, p16, p17;
}

/** Enforces a memory layout to avoid false sharing by padding the read count. */
static abstract class ReadCounterRef<E> extends PadReadCounter<E> {
abstract static class ReadCounterRef<E> extends PadReadCounter<E> {
static final long READ_OFFSET =
UnsafeAccess.objectFieldOffset(ReadCounterRef.class, "readCounter");

Expand All @@ -108,13 +108,13 @@ void lazySetReadCounter(long count) {
}
}

static abstract class PadWriteCounter<E> extends ReadCounterRef<E> {
abstract static class PadWriteCounter<E> extends ReadCounterRef<E> {
long p20, p21, p22, p23, p24, p25, p26, p27;
long p30, p31, p32, p33, p34, p35, p36, p37;
}

/** Enforces a memory layout to avoid false sharing by padding the write count. */
static abstract class ReadAndWriteCounterRef<E> extends PadWriteCounter<E> {
abstract static class ReadAndWriteCounterRef<E> extends PadWriteCounter<E> {
static final long WRITE_OFFSET =
UnsafeAccess.objectFieldOffset(ReadAndWriteCounterRef.class, "writeCounter");

Expand Down
Loading

0 comments on commit 6ccd359

Please sign in to comment.