Skip to content

Commit

Permalink
enable nullaway on jmh benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Dec 8, 2024
1 parent 047021c commit 68e525e
Show file tree
Hide file tree
Showing 36 changed files with 147 additions and 121 deletions.
6 changes: 2 additions & 4 deletions .github/actions/run-gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,17 @@ runs:
fi
echo "JDK_CI=$JAVA_HOME" >> $GITHUB_ENV
echo "JDK_EA=${{ inputs.early-access == inputs.java }}" >> $GITHUB_ENV
echo "JAVA_TOOL_OPTIONS=-Dorg.gradle.workers.max=$((2 * $(nproc)))" >> $GITHUB_ENV
echo "ORG_GRADLE_PROJECT_org.gradle.java.installations.auto-download=false" >> $GITHUB_ENV
- name: Setup Gradle
uses: gradle/actions/setup-gradle@cc4fc85e6b35bafd578d5ffbc76a5518407e1af0 # v4.2.1
env:
ORG_GRADLE_PROJECT_org.gradle.java.installations.auto-download: 'false'
with:
add-job-summary: never
cache-read-only: false
gradle-home-cache-strict-match: true
cache-encryption-key: ${{ inputs.cache-encryption-key }}
- name: Run ${{ inputs.arguments }}
if: ${{ inputs.arguments != '' }}
env:
ORG_GRADLE_PROJECT_org.gradle.java.installations.auto-download: 'false'
shell: bash
run: |
echo "::add-matcher::.github/problem-matcher.json"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
github.com:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: actionlint
uses: reviewdog/action-actionlint@053981cb135d7a696bbeec6181d9d5fae6e07dae # v1.57.0
uses: reviewdog/action-actionlint@08ef4afa963243489a457cca426f705ce4e0d1a5 # v1.60.0
env:
SHELLCHECK_OPTS: -e SC2001 -e SC2035 -e SC2046 -e SC2061 -e SC2086 -e SC2156
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ jobs:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
continue-on-error: true
- name: Publish to Codecov
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7
uses: codecov/codecov-action@7f8b4b4bde536c465e797be725718b88c5d95e0e # v5.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Publish to Codacy
Expand Down Expand Up @@ -343,11 +343,11 @@ jobs:
egress-policy: block
allowed-endpoints: >
${{ env.ALLOWED_ENDPOINTS }}
checkerframework.org:443
docs.oracle.com:443
errorprone.info:443
lightbend.github.io:443
guava.dev:443
jspecify.dev:443
lightbend.github.io:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Publish Snapshot
uses: ./.github/actions/run-gradle
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
if: steps.check_files.outputs.files_exists == 'true'
run: jq -c '.runs |= unique_by({tool, invocations, results})' < results.sarif > codacy.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
if: steps.check_files.outputs.files_exists == 'true'
continue-on-error: true
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ jobs:
java: ${{ env.JAVA_VERSION }}
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
- name: Initialize CodeQL
uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/init@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
with:
languages: java
- name: Autobuild
uses: github/codeql-action/autobuild@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/autobuild@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/analyze@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
2 changes: 1 addition & 1 deletion .github/workflows/dependency-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
with:
files: build/reports/dependency-check-report.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
if: steps.check_files.outputs.files_exists == 'true'
with:
sarif_file: build/reports/dependency-check-report.sarif
2 changes: 1 addition & 1 deletion .github/workflows/devskim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ jobs:
- name: Run DevSkim scanner
uses: microsoft/DevSkim-Action@914fa647b406c387000300b2f09bb28691be2b6d # v1.0.14
- name: Upload DevSkim scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
with:
sarif_file: devskim-results.sarif
4 changes: 2 additions & 2 deletions .github/workflows/qodana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
api.github.com:443
auth.docker.io:443
caffeine.gradle-enterprise.cloud:443
checkerframework.org:443
docs.oracle.com:443
download.jetbrains.com:443
download-cdn.jetbrains.com:443
Expand All @@ -39,6 +38,7 @@ jobs:
github.com:443
guava.dev:443
jcenter.bintray.com:443
jspecify.dev:443
lightbend.github.io:443
objects.githubusercontent.com:443
packages.jetbrains.team:443
Expand Down Expand Up @@ -70,6 +70,6 @@ jobs:
upload-result: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload SARIF file for GitHub Advanced Security Dashboard
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
2 changes: 1 addition & 1 deletion .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ jobs:
path: results.sarif
retention-days: 5
- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
if: steps.check_files.outputs.files_exists == 'true'
run: jq -c '.runs[0].tool.driver.rules |= unique_by(.id)' < results.sarif > semgrep.sarif
- name: Upload SARIF file for GitHub Advanced Security Dashboard
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
if: steps.check_files.outputs.files_exists == 'true'
continue-on-error: true
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snyk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
with:
files: snyk.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
if: steps.check_files.outputs.files_exists == 'true'
with:
sarif_file: snyk.sarif
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
github.com:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Misspell
uses: reviewdog/action-misspell@ef8b22c1cca06c8d306fc6be302c3dab0f6ca12f # v1.23.0
uses: reviewdog/action-misspell@18ffb61effb93b47e332f185216be7e49592e7e1 # v1.26.1
with:
reporter: github-check
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -34,4 +34,4 @@ jobs:
objects.githubusercontent.com:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Typos
uses: crate-ci/typos@b74202f74b4346efdbce7801d187ec57b266bac8 # v1.27.3
uses: crate-ci/typos@2872c382bb9668d4baa5eade234dcbc0048ca2cf # v1.28.2
2 changes: 1 addition & 1 deletion .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
files: results.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
if: steps.check_files.outputs.files_exists == 'true'
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion caffeine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ tasks.register<Test>("isolatedTest") {
tasks.register<Test>("lincheckTest") {
group = "Verification"
description = "Tests that assert linearizability"
enabled = (System.getenv("JDK_EA") != "true")
enabled = !isEarlyAccess()
useTestNG {
testLogging.events("started")
includeGroups("lincheck")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;

import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
Expand Down Expand Up @@ -55,12 +56,12 @@ public static class ThreadState {
}

@Benchmark
public Integer inherit_get(ThreadState threadState) {
public @Nullable Integer inherit_get(ThreadState threadState) {
return inherit.get(threadState.index++ & MASK);
}

@Benchmark
public Integer delegate_get(ThreadState threadState) {
public @Nullable Integer delegate_get(ThreadState threadState) {
return delegate.get(threadState.index++ & MASK);
}

Expand All @@ -76,6 +77,7 @@ static final class InheritMap extends ConcurrentHashMap<Integer, Integer> {
static final class DelegateMap extends ForwardingMap<Integer, Integer> {
final Map<Integer, Integer> delegate = new ConcurrentHashMap<>();

@NullUnmarked
@Override public @Nullable Integer get(Object key) {
Integer value = delegate.get(key);
return (value == null) ? null : (value - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Random;

import org.jspecify.annotations.Nullable;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Group;
import org.openjdk.jmh.annotations.GroupThreads;
Expand Down Expand Up @@ -94,7 +95,7 @@ public void tearDown() {
}

@Benchmark @Group("read_only") @GroupThreads(8)
public Boolean readOnly(ThreadState threadState) {
public @Nullable Boolean readOnly(ThreadState threadState) {
return cache.get(ints[threadState.index++ & MASK]);
}

Expand All @@ -104,7 +105,7 @@ public void writeOnly(ThreadState threadState) {
}

@Benchmark @Group("readwrite") @GroupThreads(6)
public Boolean readwrite_get(ThreadState threadState) {
public @Nullable Boolean readwrite_get(ThreadState threadState) {
return cache.get(ints[threadState.index++ & MASK]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public int descending() {
}

static final class Timer extends Node<Integer, Integer> {
Node<Integer, Integer> prev;
Node<Integer, Integer> next;
@Nullable Node<Integer, Integer> prev;
@Nullable Node<Integer, Integer> next;
long time;

Timer(long time) {
Expand All @@ -126,12 +126,14 @@ static final class Timer extends Node<Integer, Integer> {
@Override public void setVariableTime(long time) {
this.time = time;
}
@SuppressWarnings("NullAway")
@Override public Node<Integer, Integer> getPreviousInVariableOrder() {
return prev;
}
@Override public void setPreviousInVariableOrder(@Nullable Node<Integer, Integer> prev) {
this.prev = prev;
}
@SuppressWarnings("NullAway")
@Override public Node<Integer, Integer> getNextInVariableOrder() {
return next;
}
Expand All @@ -143,7 +145,7 @@ static final class Timer extends Node<Integer, Integer> {
@Override public Object getKeyReference() { throw new UnsupportedOperationException(); }
@Override public Integer getValue() { throw new UnsupportedOperationException(); }
@Override public Object getValueReference() { throw new UnsupportedOperationException(); }
@Override public void setValue(Integer value, ReferenceQueue<Integer> referenceQueue) {}
@Override public void setValue(Integer value, @Nullable ReferenceQueue<Integer> queue) {}
@Override public boolean containsValue(Object value) { return false; }
@Override public boolean isAlive() { return false; }
@Override public boolean isRetired() { return false; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.github.benmanes.caffeine.cache.impl;

import org.jspecify.annotations.Nullable;

import com.github.benmanes.caffeine.cache.BasicCache;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
Expand All @@ -33,7 +35,7 @@ public CaffeineCache(int maximumSize) {
}

@Override
public V get(K key) {
public @Nullable V get(K key) {
return cache.getIfPresent(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.Map;

import org.jspecify.annotations.Nullable;

import com.github.benmanes.caffeine.cache.BasicCache;
import com.tangosol.net.cache.LocalCache;

Expand All @@ -34,7 +36,7 @@ public CoherenceCache(int maximumSize, int evictionPolicyType) {
}

@Override
public V get(K key) {
public @Nullable V get(K key) {
return map.get(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.util.concurrent.ConcurrentMap;

import org.jspecify.annotations.Nullable;

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

/**
Expand All @@ -32,7 +34,7 @@ public ConcurrentMapCache(ConcurrentMap<K, V> map) {
}

@Override
public V get(K key) {
public @Nullable V get(K key) {
return map.get(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static com.github.benmanes.caffeine.cache.CacheType.CONCURRENCY_LEVEL;

import org.jspecify.annotations.Nullable;

import com.github.benmanes.caffeine.cache.BasicCache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
Expand All @@ -36,7 +38,7 @@ public GuavaCache(int maximumSize) {
}

@Override
public V get(K key) {
public @Nullable V get(K key) {
return cache.getIfPresent(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.jspecify.annotations.Nullable;

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

/**
Expand All @@ -31,7 +33,7 @@ public LinkedHashMapCache(int maximumSize, boolean accessOrder) {
}

@Override
public V get(K key) {
public @Nullable V get(K key) {
synchronized (map) {
return map.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3961,12 +3961,12 @@ static class BoundedLocalManualCache<K, V> implements LocalManualCache<K, V>, Se
}

@Override
public BoundedLocalCache<K, V> cache() {
public final BoundedLocalCache<K, V> cache() {
return cache;
}

@Override
public Policy<K, V> policy() {
public final Policy<K, V> policy() {
if (policy == null) {
@SuppressWarnings("NullAway")
Function<@Nullable V, @Nullable V> identity = identity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ default void notifyOnReplace(K key, @Nullable V oldValue, V newValue) {
}
}

/** Decorates the remapping function to record statistics if enabled. */
/** Decorates the mapping function to record statistics if enabled, recording a miss if called. */
default <T, R> Function<? super T, ? extends R> statsAware(
Function<? super T, ? extends R> mappingFunction, boolean recordLoad) {
if (!isRecordingStats()) {
Expand Down
Loading

0 comments on commit 68e525e

Please sign in to comment.