Skip to content

Commit

Permalink
[GR-30944] Insert a store-store fence between setting the value and t…
Browse files Browse the repository at this point in the history
…he shape.

PullRequest: graal/8813
  • Loading branch information
woess committed Apr 26, 2021
2 parents 556391b + ba4dd5a commit ca82e5c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ default void setInt(DynamicObject store, int value) throws FinalLocationExceptio
default void setInt(DynamicObject store, int value, Shape oldShape, Shape newShape) {
ACCESS.grow(store, oldShape, newShape);
setInt(store, value, false);
ACCESS.setShape(store, newShape);
ACCESS.setShapeWithStoreFence(store, newShape);
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ default void setLong(DynamicObject store, long value) throws FinalLocationExcept
default void setLong(DynamicObject store, long value, Shape oldShape, Shape newShape) {
ACCESS.grow(store, oldShape, newShape);
setLong(store, value, false);
ACCESS.setShape(store, newShape);
ACCESS.setShapeWithStoreFence(store, newShape);
}
}

Expand Down Expand Up @@ -185,7 +185,7 @@ default void setDouble(DynamicObject store, double value) throws FinalLocationEx
default void setDouble(DynamicObject store, double value, Shape oldShape, Shape newShape) {
ACCESS.grow(store, oldShape, newShape);
setDouble(store, value, false);
ACCESS.setShape(store, newShape);
ACCESS.setShapeWithStoreFence(store, newShape);
}
}

Expand Down Expand Up @@ -219,7 +219,7 @@ default void setBoolean(DynamicObject store, boolean value) throws FinalLocation
default void setBoolean(DynamicObject store, boolean value, Shape oldShape, Shape newShape) {
ACCESS.grow(store, oldShape, newShape);
setBoolean(store, value, false);
ACCESS.setShape(store, newShape);
ACCESS.setShapeWithStoreFence(store, newShape);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private static boolean putUncachedSlow(DynamicObject object, Object key, Object
} catch (IncompatibleLocationException e) {
throw shouldNotHappen(e);
}
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
updateShapeImpl(object);
} else {
try {
Expand Down Expand Up @@ -1249,7 +1249,7 @@ protected boolean putImpl(DynamicObject object, Shape cachedShape, Object key, O
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand Down Expand Up @@ -1293,7 +1293,7 @@ protected boolean putIntImpl(DynamicObject object, Shape cachedShape, Object key
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand All @@ -1309,7 +1309,7 @@ protected boolean putIntImpl(DynamicObject object, Shape cachedShape, Object key
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand All @@ -1325,7 +1325,7 @@ protected boolean putIntImpl(DynamicObject object, Shape cachedShape, Object key
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand All @@ -1341,7 +1341,7 @@ protected boolean putIntImpl(DynamicObject object, Shape cachedShape, Object key
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand Down Expand Up @@ -1383,7 +1383,7 @@ protected boolean putLongImpl(DynamicObject object, Shape cachedShape, Object ke
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand All @@ -1400,7 +1400,7 @@ protected boolean putLongImpl(DynamicObject object, Shape cachedShape, Object ke
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand Down Expand Up @@ -1442,7 +1442,7 @@ protected boolean putDoubleImpl(DynamicObject object, Shape cachedShape, Object
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand All @@ -1459,7 +1459,7 @@ protected boolean putDoubleImpl(DynamicObject object, Shape cachedShape, Object
throw shouldNotHappen(e);
}
if (newShape != oldShape) {
ACCESS.setShape(object, newShape);
ACCESS.setShapeWithStoreFence(object, newShape);
}
c.maybeUpdateShape(object);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.memory.MemoryFence;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.Location;
import com.oracle.truffle.api.object.ObjectType;
Expand Down Expand Up @@ -171,6 +172,13 @@ protected abstract static class Support extends Access {
protected Support() {
}

public final void setShapeWithStoreFence(DynamicObject object, Shape shape) {
if (shape.isShared()) {
MemoryFence.storeStore();
}
super.setShape(object, shape);
}

public final void grow(DynamicObject object, Shape thisShape, Shape otherShape) {
DynamicObjectSupport.grow(object, thisShape, otherShape);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void set(DynamicObject store, Object value, Shape oldShape, Shape newShap
} catch (IncompatibleLocationException ex) {
throw DynamicObjectLibraryImpl.shouldNotHappen(ex);
}
LayoutImpl.ACCESS.setShape(store, newShape);
LayoutImpl.ACCESS.setShapeWithStoreFence(store, newShape);
} else {
throw incompatibleLocation();
}
Expand Down

0 comments on commit ca82e5c

Please sign in to comment.