Skip to content

Commit

Permalink
Remove load fence, deemed unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjeet committed Oct 8, 2023
1 parent 83f0544 commit a862e96
Showing 1 changed file with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.netflix.hollow.api.sampling.HollowObjectSampler;
import com.netflix.hollow.api.sampling.HollowSampler;
import com.netflix.hollow.api.sampling.HollowSamplingDirector;
import com.netflix.hollow.core.memory.HollowUnsafeHandle;
import com.netflix.hollow.core.memory.MemoryMode;
import com.netflix.hollow.core.memory.encoding.GapEncodedVariableLengthIntegerReader;
import com.netflix.hollow.core.memory.encoding.VarInt;
Expand Down Expand Up @@ -353,7 +352,7 @@ public boolean isNull(int ordinal, int fieldIndex) {
// atomic assignment below operations on a stale shards holder will be legal
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.isNull(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile); // there is a load (acquire) fence imposed within shard.isNull, no need for another here
return result;
}

Expand All @@ -367,7 +366,7 @@ public int readOrdinal(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readOrdinal(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -381,7 +380,7 @@ public int readInt(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readInt(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -395,7 +394,7 @@ public float readFloat(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readFloat(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -409,7 +408,7 @@ public double readDouble(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readDouble(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -423,7 +422,7 @@ public long readLong(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readLong(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -437,7 +436,7 @@ public Boolean readBoolean(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readBoolean(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -451,7 +450,7 @@ public byte[] readBytes(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readBytes(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -465,7 +464,7 @@ public String readString(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.readString(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -479,7 +478,7 @@ public boolean isStringFieldEqual(int ordinal, int fieldIndex, String testValue)
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
result = shard.isStringFieldEqual(ordinal >> shard.shardOrdinalShift, fieldIndex, testValue);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return result;
}

Expand All @@ -493,15 +492,10 @@ public int findVarLengthFieldHashCode(int ordinal, int fieldIndex) {
shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard shard = shardsHolder.shards[ordinal & shardsHolder.shardNumberMask];
hashCode = shard.findVarLengthFieldHashCode(ordinal >> shard.shardOrdinalShift, fieldIndex);
} while(readWasUnsafe(shardsHolder));
} while(shardsHolder != this.shardsVolatile);
return hashCode;
}

private boolean readWasUnsafe(ShardsHolder shardsHolder) {
HollowUnsafeHandle.getUnsafe().loadFence(); // for why, see explanation in HollowObjectTypeReadStateShard::readWasUnsafe
return shardsHolder != shardsVolatile;
}

/**
* Warning: Not thread-safe. Should only be called within the update thread.
* @param fieldName the field name
Expand All @@ -527,10 +521,10 @@ public HollowSampler getSampler() {

@Override
protected void invalidate() {
ShardsHolder shardsHolder = this.shardsVolatile;
HollowObjectTypeReadStateShard[] shards = this.shardsVolatile.shards;
stateListeners = EMPTY_LISTENERS;
for(int i=0;i<shardsHolder.shards.length;i++)
shardsHolder.shards[i].invalidate();
for(int i=0;i<shards.length;i++)
shards[i].invalidate();
}

@Override
Expand All @@ -548,9 +542,6 @@ public void ignoreUpdateThreadForSampling(Thread t) {
sampler.setUpdateThread(t);
}

/**
* Warning: Not thread-safe. Should only be called within the update thread.
*/
HollowObjectTypeDataElements[] currentDataElements() {
final HollowObjectTypeReadStateShard[] shards = this.shardsVolatile.shards;
HollowObjectTypeDataElements currentDataElements[] = new HollowObjectTypeDataElements[shards.length];
Expand Down Expand Up @@ -582,9 +573,8 @@ public long getApproximateHeapFootprintInBytes() {
final HollowObjectTypeReadStateShard[] shards = this.shardsVolatile.shards;
long totalApproximateHeapFootprintInBytes = 0;

for(int i=0;i<shards.length;i++) {
for(int i=0;i<shards.length;i++)
totalApproximateHeapFootprintInBytes += shards[i].getApproximateHeapFootprintInBytes();
}

return totalApproximateHeapFootprintInBytes;
}
Expand Down

0 comments on commit a862e96

Please sign in to comment.