Skip to content

Commit

Permalink
Fixes JCTools#308: Remove useless fences on chunk's prev field accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Jun 1, 2020
1 parent c0b570d commit cae3e01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Expand Up @@ -308,7 +308,7 @@ final R producerChunkForIndex(
{
// prev cannot be null, because the consumer cannot null it without consuming the element for which we are
// trying to get the chunk.
currentChunk = currentChunk.lvPrev();
currentChunk = currentChunk.lpPrev();
assert currentChunk != null;
}
assert currentChunk.lvIndex() == requiredChunkIndex;
Expand Down Expand Up @@ -355,7 +355,7 @@ private R newOrPooledChunk(R prevChunk, long nextChunkIndex)
{
// single-writer: prevChunk::index == nextChunkIndex is protecting it
assert newChunk.lvIndex() < prevChunk.lvIndex();
newChunk.soPrev(prevChunk);
newChunk.spPrev(prevChunk);
// index set is releasing prev, allowing other pending offers to continue
newChunk.soIndex(nextChunkIndex);
}
Expand All @@ -374,7 +374,7 @@ final void moveToNextConsumerChunk(R cChunk, R next)
{
// avoid GC nepotism
cChunk.soNext(null);
next.soPrev(null);
next.spPrev(null);
// no need to cChunk.soIndex(NOT_USED)
if (cChunk.isPooled())
{
Expand Down
Expand Up @@ -11,21 +11,20 @@ class MpUnboundedXaddChunk<R,E>
{
final static int NOT_USED = -1;

private static final long PREV_OFFSET = fieldOffset(MpUnboundedXaddChunk.class, "prev");
private static final long NEXT_OFFSET = fieldOffset(MpUnboundedXaddChunk.class, "next");
private static final long INDEX_OFFSET = fieldOffset(MpUnboundedXaddChunk.class, "index");

private final boolean pooled;
private final E[] buffer;

private volatile R prev;
private R prev;
private volatile long index;
private volatile R next;
MpUnboundedXaddChunk(long index, R prev, int size, boolean pooled)
{
buffer = allocateRefArray(size);
// next is null
soPrev(prev);
spPrev(prev);
spIndex(index);
this.pooled = pooled;
}
Expand Down Expand Up @@ -60,14 +59,14 @@ final void soNext(R value)
UNSAFE.putOrderedObject(this, NEXT_OFFSET, value);
}

final R lvPrev()
final R lpPrev()
{
return prev;
return this.prev;
}

final void soPrev(R value)
final void spPrev(R value)
{
UNSAFE.putObject(this, PREV_OFFSET, value);
this.prev = value;
}

final void soElement(int index, E e)
Expand Down

0 comments on commit cae3e01

Please sign in to comment.