Skip to content

Commit 53683e6

Browse files
committed
Ensure newShape.isValid() is checked just before execution the specialization
1 parent c6ad07d commit 53683e6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/truffleruby/language/objects/WriteObjectFieldNode.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void writeNewField(DynamicObject object, Object value, boolean generalize
114114
@Cached("object.getShape()") Shape oldShape,
115115
@Cached("defineProperty(oldShape, value, generalize)") Shape newShape,
116116
@Cached("getNewLocation(newShape)") Location newLocation,
117-
@Cached("createAssumption(oldShape, newLocation)") Assumption validLocation,
117+
@Cached("createAssumption(oldShape, newShape, newLocation)") Assumption validLocation,
118118
@Cached("isShared(oldShape)") boolean shared,
119119
@Cached("createWriteBarrierNode(shared)") WriteBarrierNode writeBarrierNode,
120120
@Cached("createProfile(shared)") BranchProfile shapeRaceProfile) {
@@ -205,6 +205,15 @@ protected Assumption createAssumption(Shape shape, Location location) {
205205
return Truffle.getRuntime().createAssumption("object location is valid");
206206
}
207207

208+
// The location is passed here even though it's not used,
209+
// to make sure the DSL checks this Assumption after all lookups are done in executeAndSpecialize().
210+
protected Assumption createAssumption(Shape oldShape, Shape newShape, Location location) {
211+
if (!oldShape.isValid() || !newShape.isValid()) {
212+
return NeverValidAssumption.INSTANCE;
213+
}
214+
return Truffle.getRuntime().createAssumption("object location is valid");
215+
}
216+
208217
protected int getCacheLimit() {
209218
return getContext().getOptions().INSTANCE_VARIABLE_CACHE;
210219
}

0 commit comments

Comments
 (0)