This class may be removed in the future. Consider the replacements in JEP 193 'Variable Handles': http://openjdk.java.net/jeps/193
/** * Orders loads before the fence, with loads and stores after the fence. */ public static void loadFence() { unsafe.loadFence(); }
/** * Validate that the current received record is still valid and has not been overwritten. * <p> * If the receiver is not consuming messages fast enough to keep up with the transmitter then loss * can be experienced resulting in messages being overwritten thus making them no longer valid. * * @return true if still valid otherwise false. */ public boolean validate() { UNSAFE.loadFence(); return validate(cursor); }
final int receiverWindowLength = nextSmReceiverWindowLength; UNSAFE.loadFence();
final int length = lossLength; UNSAFE.loadFence();
private boolean readWasUnsafe(HollowMapTypeDataElements data) { HollowUnsafeHandle.getUnsafe().loadFence(); return data != currentDataVolatile; }
private boolean readWasUnsafe(HollowSetTypeDataElements data) { HollowUnsafeHandle.getUnsafe().loadFence(); return data != currentDataVolatile; }
private boolean readWasUnsafe(HollowListTypeDataElements data) { HollowUnsafeHandle.getUnsafe().loadFence(); return data != currentDataVolatile; }
private boolean readWasUnsafe(HollowObjectTypeDataElements data) { // Use a load (acquire) fence to constrain the compiler reordering prior plain loads so // that they cannot "float down" below the volatile load of currentDataVolatile. // This ensures data is checked against currentData *after* optimistic calculations // have been performed on data. // // Note: the Java Memory Model allows for the reordering of plain loads and stores // before a volatile load (those plain loads and stores can "float down" below the // volatile load), but forbids the reordering of plain loads after a volatile load // (those plain loads are not allowed to "float above" the volatile load). // Similar reordering also applies to plain loads and stores and volatile stores. // In effect the ordering of volatile loads and stores is retained and plain loads // and stores can be shuffled around and grouped together, which increases // optimization opportunities. // This is why locks can be coarsened; plain loads and stores may enter the lock region // from above (float down the acquire) or below (float above the release) but existing // loads and stores may not exit (a "lock roach motel" and why there is almost universal // misunderstanding of, and many misguided attempts to optimize, the infamous double // checked locking idiom). // // Note: the fence provides stronger ordering guarantees than a corresponding non-plain // load or store since the former affects all prior or subsequent loads and stores, // whereas the latter is scoped to the particular load or store. // // For more details see http://gee.cs.oswego.edu/dl/html/j9mm.html HollowUnsafeHandle.getUnsafe().loadFence(); return data != currentDataVolatile; }
/** * Orders loads before the fence, with loads and stores after the fence. */ public static void loadFence() { unsafe.loadFence(); }
@Override @ForceInline public void loadFence() { UNSAFE.loadFence(); }
public boolean isZero() { // Volatile read prevents reordering the relaxed slot gets combined // with the loadFence() below. long sum = relaxed; for (int i = 0; i < SLOTS && sum == 0; i++) { sum += get(i); } UNSAFE.loadFence(); return sum == 0; }
@Override public long readVolatileLong(@NotNull Object object, long offset) { if ((offset & 0x7) == 0) return super.readVolatileLong(object, offset); UNSAFE.loadFence(); return readLong(object, offset); }
@Override public long readVolatileLong(@NotNull Object object, long offset) { if ((offset & 0x7) == 0) return super.readVolatileLong(object, offset); UNSAFE.loadFence(); return readLong(object, offset); }
@Override public float readVolatileFloat(long address) { if ((address & 0x3) == 0) return super.readVolatileFloat(address); UNSAFE.loadFence(); return readFloat(address); }
@Override public double readVolatileDouble(long address) { if ((address & 0x7) == 0) return super.readVolatileDouble(address); UNSAFE.loadFence(); return readDouble(address); }
@Override public int readVolatileInt(long address) { if ((address & 0x3) == 0) return super.readVolatileInt(address); UNSAFE.loadFence(); return super.readInt(address); }
@Override public long readVolatileLong(long address) { if ((address & 0x7) == 0) return super.readVolatileLong(address); UNSAFE.loadFence(); return readLong(address); }
@Override public short readVolatileShort(long address) { if ((address & 0x1) == 0) return super.readVolatileShort(address); UNSAFE.loadFence(); return super.readShort(address); }
@Override public short readVolatileShort(long address) { if ((address & 0x1) == 0) return super.readVolatileShort(address); UNSAFE.loadFence(); return super.readShort(address); }
@Override public int readVolatileInt(long address) { if ((address & 0x3) == 0) return super.readVolatileInt(address); UNSAFE.loadFence(); return super.readInt(address); }