diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java index db75391f9d3..0ffbe5e796a 100644 --- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java +++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java @@ -1325,6 +1325,26 @@ public void writeVolatileShort(long address, short i16) { } } + @Override + public short readVolatileShort(Object object, long offset) { + assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset); + if ((offset & 0x1) == 0) + return super.readVolatileShort(object, offset); + UNSAFE.loadFence(); + return super.readShort(object, offset); + } + + @Override + public void writeVolatileShort(Object object, long offset, short i16) { + assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset); + if ((offset & 0x1) == 0) { + super.writeVolatileShort(object, offset, i16); + } else { + super.writeShort(object, offset, i16); + UNSAFE.storeFence(); + } + } + @Override public void writeFloat(long address, float f) { assert SKIP_ASSERTIONS || address != 0; @@ -1369,6 +1389,15 @@ public int readVolatileInt(long address) { return super.readInt(address); } + @Override + public int readVolatileInt(Object object, long offset) { + assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset); + if (safeAlignedInt(offset)) + return super.readVolatileInt(object, offset); + UNSAFE.loadFence(); + return super.readInt(object, offset); + } + @Override public float readVolatileFloat(long address) { assert SKIP_ASSERTIONS || address != 0;