Skip to content

Commit

Permalink
[ci skip] Migrate from JSR-305 annotations to CheckerFramework's & Er…
Browse files Browse the repository at this point in the history
…rorProne's (fixes #242)
  • Loading branch information
ben-manes committed May 28, 2018
1 parent b8e6867 commit d0e47f7
Show file tree
Hide file tree
Showing 86 changed files with 336 additions and 588 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Expand Up @@ -80,9 +80,6 @@ subprojects {
}

dependencies {
provided libraries.jsr305
provided libraries.errorProneAnnotations

testCompile libraries.guava
testCompile testLibraries.mockito
testCompile testLibraries.hamcrest
Expand Down
5 changes: 3 additions & 2 deletions caffeine/build.gradle
Expand Up @@ -26,6 +26,9 @@ plugins.withType(EclipsePlugin) {
}

dependencies {
compile libraries.checkerAnnotations
compile libraries.errorProneAnnotations

testCompile libraries.ycsb
testCompile libraries.guava
testCompile libraries.fastutil
Expand All @@ -43,7 +46,6 @@ dependencies {
jmh benchmarkLibraries.cache2k
jmh benchmarkLibraries.ehcache3
jmh benchmarkLibraries.koloboke
jmh benchmarkLibraries.rapidoid
jmh benchmarkLibraries.slf4jNop
jmh benchmarkLibraries.collision
jmh benchmarkLibraries.jackrabbit
Expand All @@ -52,7 +54,6 @@ dependencies {
jmh benchmarkLibraries.concurrentlinkedhashmap

javaPoetCompile libraries.guava
javaPoetCompile libraries.jsr305
javaPoetCompile libraries.javapoet
javaPoetCompile libraries.commonsLang3
}
Expand Down
Expand Up @@ -35,9 +35,10 @@
import java.util.Set;
import java.util.TreeMap;

import javax.annotation.Nullable;
import javax.lang.model.element.Modifier;

import org.checkerframework.checker.nullness.qual.Nullable;

import com.github.benmanes.caffeine.cache.local.AddConstructor;
import com.github.benmanes.caffeine.cache.local.AddDeques;
import com.github.benmanes.caffeine.cache.local.AddExpirationTicker;
Expand Down
Expand Up @@ -15,24 +15,22 @@
*/
package com.github.benmanes.caffeine.cache;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A facade for benchmark implementations.
*
* @author ben.manes@gmail.com (Ben Manes)
*/
@ThreadSafe
public interface BasicCache<K, V> {

/** Returns the value stored in the cache, or null if not present. */
@Nullable
V get(@Nonnull K key);
V get(@NonNull K key);

/** Stores the value into the cache, replacing an existing mapping if present. */
void put(@Nonnull K key, @Nonnull V value);
void put(@NonNull K key, @NonNull V value);

/** Invalidates all entries from the cache. */
void clear();
Expand Down
Expand Up @@ -30,7 +30,6 @@
import com.github.benmanes.caffeine.cache.impl.ExpiringMapCache;
import com.github.benmanes.caffeine.cache.impl.GuavaCache;
import com.github.benmanes.caffeine.cache.impl.LinkedHashMapCache;
import com.github.benmanes.caffeine.cache.impl.RapidoidCache;
import com.github.benmanes.caffeine.cache.impl.TCache;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.trivago.triava.tcache.EvictionPolicy;
Expand Down Expand Up @@ -129,11 +128,6 @@ public enum CacheType {
return new LinkedHashMapCache<>(maximumSize, /* accessOrder */ true);
}
},
Rapidoid {
@Override public <K, V> BasicCache<K, V> create(int maximumSize) {
return new RapidoidCache<>(maximumSize);
}
},
TCache_Lfu {
@Override public <K, V> BasicCache<K, V> create(int maximumSize) {
return new TCache<>(maximumSize, EvictionPolicy.LFU);
Expand Down
Expand Up @@ -27,8 +27,6 @@
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.rapidoid.cache.Caching;
import org.rapidoid.lambda.Mapper;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand All @@ -44,7 +42,6 @@ public class ComputeBenchmark {
static final int MASK = SIZE - 1;
static final int ITEMS = SIZE / 3;
static final Integer COMPUTE_KEY = SIZE / 2;
static final Mapper<Integer, Boolean> mapper = any -> Boolean.TRUE;
static final Function<Integer, Boolean> mappingFunction = any -> Boolean.TRUE;
static final CacheLoader<Integer, Boolean> cacheLoader = CacheLoader.from(key -> Boolean.TRUE);

Expand Down Expand Up @@ -77,8 +74,6 @@ public void setup() {
setupCaffeine();
} else if (computeType.equals("Guava")) {
setupGuava();
} else if (computeType.equals("Rapidoid")) {
setupRapidoid();
} else {
throw new AssertionError("Unknown computingType: " + computeType);
}
Expand Down Expand Up @@ -110,9 +105,4 @@ private void setupGuava() {
CacheBuilder.newBuilder().concurrencyLevel(64).build(cacheLoader);
benchmarkFunction = cache::getUnchecked;
}

private void setupRapidoid() {
org.rapidoid.cache.Cache<Integer, Boolean> cache = Caching.of(mapper).build();
benchmarkFunction = cache::get;
}
}
Expand Up @@ -59,7 +59,6 @@ public class GetPutBenchmark {
"ExpiringMap_Lru",
"TCache_Lfu",
"TCache_Lru",
"Rapidoid",
})
CacheType cacheType;

Expand Down
Expand Up @@ -19,8 +19,7 @@
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
Expand Down
Expand Up @@ -18,8 +18,6 @@
import java.util.LinkedHashMap;
import java.util.Map;

import javax.annotation.concurrent.NotThreadSafe;

import com.github.benmanes.caffeine.cache.BasicCache;

/**
Expand Down Expand Up @@ -53,7 +51,6 @@ public void clear() {
}
}

@NotThreadSafe
static final class BoundedLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
private static final long serialVersionUID = 1L;
private final int maximumSize;
Expand Down

This file was deleted.

Expand Up @@ -31,8 +31,8 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import com.github.benmanes.caffeine.SingleConsumerQueue.Node;
import com.github.benmanes.caffeine.base.UnsafeAccess;
Expand Down Expand Up @@ -289,7 +289,7 @@ public boolean addAll(Collection<? extends E> c) {
}

/** Adds the linked list of nodes to the queue. */
void append(@Nonnull Node<E> first, @Nonnull Node<E> last) {
void append(@NonNull Node<E> first, @NonNull Node<E> last) {
for (;;) {
Node<E> t = tail;
if (casTail(t, last)) {
Expand Down Expand Up @@ -328,7 +328,7 @@ void append(@Nonnull Node<E> first, @Nonnull Node<E> last) {
* @return either {@code null} if the element was transferred, the first node if neither a
* transfer nor receive were successful, or the received last element from a producer
*/
@Nullable Node<E> transferOrCombine(@Nonnull Node<E> first, Node<E> last) {
@Nullable Node<E> transferOrCombine(@NonNull Node<E> first, Node<E> last) {
int index = index();
AtomicReference<Node<E>> slot = arena[index];

Expand Down Expand Up @@ -370,7 +370,7 @@ static int index() {
}

/** Returns the last node in the linked list. */
@Nonnull static <E> Node<E> findLast(@Nonnull Node<E> node) {
@NonNull static <E> Node<E> findLast(@NonNull Node<E> node) {
Node<E> next;
while ((next = node.getNextRelaxed()) != null) {
node = next;
Expand Down
Expand Up @@ -19,8 +19,7 @@
import java.util.Collection;
import java.util.NoSuchElementException;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* This class provides a skeletal implementation of the {@link LinkedDeque} interface to minimize
Expand All @@ -29,7 +28,6 @@
* @author ben.manes@gmail.com (Ben Manes)
* @param <E> the type of elements held in this collection
*/
@NotThreadSafe
abstract class AbstractLinkedDeque<E> extends AbstractCollection<E> implements LinkedDeque<E> {

// This class provides a doubly-linked list that is optimized for the virtual machine. The first
Expand Down
Expand Up @@ -17,8 +17,7 @@

import java.util.Deque;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.checkerframework.checker.nullness.qual.Nullable;

import com.github.benmanes.caffeine.cache.AccessOrderDeque.AccessOrder;

Expand All @@ -28,7 +27,6 @@
* @author ben.manes@gmail.com (Ben Manes)
* @param <E> the type of elements held in this collection
*/
@NotThreadSafe
final class AccessOrderDeque<E extends AccessOrder<E>> extends AbstractLinkedDeque<E> {

@Override
Expand Down
Expand Up @@ -24,7 +24,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;

import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Static utility methods and classes pertaining to asynchronous operations.
Expand Down
Expand Up @@ -20,9 +20,8 @@
import java.util.function.BiFunction;
import java.util.function.Function;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A semi-persistent mapping from keys to values. Cache entries are manually added using
Expand All @@ -36,7 +35,6 @@
* @param <K> the type of keys maintained by this cache
* @param <V> the type of mapped values
*/
@ThreadSafe
public interface AsyncCache<K, V> {

/**
Expand All @@ -49,7 +47,7 @@ public interface AsyncCache<K, V> {
* @throws NullPointerException if the specified key is null
*/
@Nullable
CompletableFuture<V> getIfPresent(@Nonnull Object key);
CompletableFuture<V> getIfPresent(@NonNull Object key);

/**
* Returns the future associated with {@code key} in this cache, obtaining that value from
Expand All @@ -69,9 +67,9 @@ public interface AsyncCache<K, V> {
* @return the current (existing or computed) future value associated with the specified key
* @throws NullPointerException if the specified key or mappingFunction is null
*/
@Nonnull
CompletableFuture<V> get(@Nonnull K key,
@Nonnull Function<? super K, ? extends V> mappingFunction);
@NonNull
CompletableFuture<V> get(@NonNull K key,
@NonNull Function<? super K, ? extends V> mappingFunction);

/**
* Returns the future associated with {@code key} in this cache, obtaining that value from
Expand All @@ -94,9 +92,9 @@ CompletableFuture<V> get(@Nonnull K key,
* @throws RuntimeException or Error if the mappingFunction does when constructing the future,
* in which case the mapping is left unestablished
*/
@Nonnull
CompletableFuture<V> get(@Nonnull K key,
@Nonnull BiFunction<? super K, Executor, CompletableFuture<V>> mappingFunction);
@NonNull
CompletableFuture<V> get(@NonNull K key,
@NonNull BiFunction<? super K, Executor, CompletableFuture<V>> mappingFunction);

/**
* Associates {@code value} with {@code key} in this cache. If the cache previously contained a
Expand All @@ -110,7 +108,7 @@ CompletableFuture<V> get(@Nonnull K key,
* @param valueFuture value to be associated with the specified key
* @throws NullPointerException if the specified key or value is null
*/
void put(@Nonnull K key, @Nonnull CompletableFuture<V> valueFuture);
void put(@NonNull K key, @NonNull CompletableFuture<V> valueFuture);

/**
* Returns a view of the entries stored in this cache as a synchronous {@link Cache}. A mapping is
Expand All @@ -120,6 +118,6 @@ CompletableFuture<V> get(@Nonnull K key,
*
* @return a thread-safe synchronous view of this cache
*/
@Nonnull
@NonNull
Cache<K, V> synchronous();
}

0 comments on commit d0e47f7

Please sign in to comment.