Skip to content

Commit

Permalink
minor refinements to 4fb19e8 (clarifying memory barriers)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Nov 28, 2021
1 parent 7ebb9f4 commit 1405bd0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ jobs:
restore-keys: ${{ runner.os }}-gradle
- name: Run tests
run: ./.github/scripts/test.sh
- name: Set up JDK 17.0.1
if: matrix.java == env.MAX_JVM
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 17.0.1
- name: Run JDK-8274349 tests
if: matrix.java == env.MAX_JVM
run: ./gradlew jdk8274349Test
- name: Publish Coverage
if: >
matrix.java == env.MIN_JVM
Expand Down Expand Up @@ -72,3 +63,18 @@ jobs:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
run: ./gradlew publishToSonatype
jdk8274349:
runs-on: ubuntu-latest
env:
JAVA_VERSION: 17
steps:
- uses: actions/checkout@v2.4.0
- name: Set up JDK 17.0.1
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 17.0.1
- name: Run JDK-8274349 tests
uses: gradle/gradle-build-action@v2
with:
arguments: jdk8274349Test
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private MethodSpec makeGetValue() {

var code = CodeBlock.builder()
.beginControlFlow("for (;;)")
.addStatement("$1T<V> ref = ($1T<V>) $2L.get(this)", Reference.class, handle)
.addStatement("$1T<V> ref = ($1T<V>) $2L.getOpaque(this)", Reference.class, handle)
.addStatement("V referent = ref.get()")
.beginControlFlow("if ((referent != null) || (ref == $L.getAcquire(this)))", handle)
.addStatement("return referent")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected final MethodSpec newGetter(Strength strength, TypeName varType,
.addModifiers(context.publicFinalModifiers())
.returns(varType);
if (strength == Strength.STRONG) {
if ((visibility == Visibility.PLAIN) || (visibility == Visibility.OPAQUE)) {
if (visibility == Visibility.PLAIN) {
var template = String.format("return (%s) $L.get(this)",
varType.isPrimitive() ? "$L" : "$T");
getter.addStatement(template, varType, varHandleName(varName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public RingBuffer(E e) {
@Override
public int offer(E e) {
long head = readCounter;
long tail = relaxedWriteCounter();
long tail = writeCounterOpaque();
long size = (tail - head);
if (size >= BUFFER_SIZE) {
return Buffer.FULL;
Expand All @@ -83,14 +83,14 @@ public int offer(E e) {
@Override
public void drainTo(Consumer<E> consumer) {
long head = readCounter;
long tail = relaxedWriteCounter();
long tail = writeCounterOpaque();
long size = (tail - head);
if (size == 0) {
return;
}
do {
int index = (int) (head & MASK);
E e = (E) BUFFER.getVolatile(buffer, index);
E e = (E) BUFFER.getAcquire(buffer, index);
if (e == null) {
// not published yet
break;
Expand All @@ -99,7 +99,7 @@ public void drainTo(Consumer<E> consumer) {
consumer.accept(e);
head++;
} while (head != tail);
lazySetReadCounter(head);
setReadCounterOpaque(head);
}

@Override
Expand Down Expand Up @@ -169,12 +169,12 @@ abstract static class ReadAndWriteCounterRef extends PadWriteCounter {
WRITE.setOpaque(this, 1);
}

void lazySetReadCounter(long count) {
void setReadCounterOpaque(long count) {
READ.setOpaque(this, count);
}

long relaxedWriteCounter() {
return (long) WRITE.get(this);
long writeCounterOpaque() {
return (long) WRITE.getOpaque(this);
}

boolean casWriteCounter(long expect, long update) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ext {
]
pluginVersions = [
bnd: '6.1.0',
checkstyle: '9.1',
checkstyle: '9.2',
coveralls: '2.12.0',
errorprone: '2.0.2',
findsecbugs: '1.11.0',
Expand Down

0 comments on commit 1405bd0

Please sign in to comment.