Skip to content

Commit a0b2219

Browse files
committed
Simplify putGeneric.
1 parent c5fc0d4 commit a0b2219

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

truffle/src/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/ObsolescenceStrategy.java

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -159,74 +159,53 @@ private static boolean assertLocationInRange(final Shape shape, final Location l
159159
}
160160

161161
@TruffleBoundary
162-
static boolean putGeneric(DynamicObject object, Object key, Object value, int newPropertyFlags, int putFlags) {
163-
Shape shape = object.getShape();
164-
Property existingProperty = shape.getProperty(key);
165-
return putGeneric(object, key, value, newPropertyFlags, putFlags, shape, existingProperty);
162+
static boolean putGeneric(DynamicObject object, Object key, Object value, int newPropertyFlags, int mode) {
163+
return putGeneric(object, key, value, newPropertyFlags, mode, null, null);
166164
}
167165

168166
@TruffleBoundary
169-
static boolean putGeneric(DynamicObject object, Object key, Object value, int newPropertyFlags, int putFlags, Shape s, Property existingProperty) {
170-
if (existingProperty == null) {
171-
if (Flags.isPutIfPresent(putFlags)) {
172-
return false;
173-
}
174-
} else {
175-
if (Flags.isPutIfAbsent(putFlags)) {
176-
return false;
177-
} else if (!Flags.isUpdateFlags(putFlags) && existingProperty.getLocation().canStore(value)) {
178-
existingProperty.getLocation().setSafe(object, value, false, false);
179-
return true;
180-
}
181-
}
182-
return putGenericSlowPath(object, key, value, newPropertyFlags, putFlags, s, existingProperty);
183-
}
184-
185-
private static boolean putGenericSlowPath(DynamicObject object, Object key, Object value, int newPropertyFlags, int putFlags,
186-
Shape initialShape, Property propertyOfInitialShape) {
167+
static boolean putGeneric(DynamicObject object, Object key, Object value, int newPropertyFlags, int mode,
168+
Shape cachedShape, Property propertyOfCachedShape) {
187169
CompilerAsserts.neverPartOfCompilation();
188170
updateShape(object);
189171
Shape oldShape;
190172
Shape newShape;
191173
Property property;
192174
do {
193175
oldShape = object.getShape();
194-
final Property existingProperty = reusePropertyLookup(key, initialShape, propertyOfInitialShape, oldShape);
176+
final Property existingProperty = reusePropertyLookup(key, cachedShape, propertyOfCachedShape, oldShape);
195177
if (existingProperty == null) {
196-
if (Flags.isPutIfPresent(putFlags)) {
178+
if (Flags.isPutIfPresent(mode)) {
197179
return false;
198180
} else {
199-
newShape = defineProperty(oldShape, key, value, newPropertyFlags, existingProperty, putFlags);
181+
newShape = defineProperty(oldShape, key, value, newPropertyFlags, null, mode);
200182
property = newShape.getProperty(key);
201183
}
202-
} else if (Flags.isPutIfAbsent(putFlags)) {
184+
} else if (Flags.isPutIfAbsent(mode)) {
203185
return false;
204-
} else if (Flags.isUpdateFlags(putFlags) && newPropertyFlags != existingProperty.getFlags()) {
205-
newShape = defineProperty(oldShape, key, value, newPropertyFlags, existingProperty, putFlags);
206-
property = newShape.getProperty(key);
207-
} else {
208-
if (existingProperty.getLocation().canStore(value)) {
186+
} else if (!Flags.isUpdateFlags(mode) || newPropertyFlags == existingProperty.getFlags()) {
187+
if (existingProperty.getLocation().canStoreValue(value)) {
209188
newShape = oldShape;
210189
property = existingProperty;
211190
} else {
212-
assert !Flags.isUpdateFlags(putFlags) || newPropertyFlags == existingProperty.getFlags();
213-
newShape = defineProperty(oldShape, key, value, existingProperty.getFlags(), existingProperty, putFlags);
191+
newShape = defineProperty(oldShape, key, value, existingProperty.getFlags(), existingProperty, mode);
214192
property = newShape.getProperty(key);
215193
}
194+
} else {
195+
newShape = defineProperty(oldShape, key, value, newPropertyFlags, existingProperty, mode);
196+
property = newShape.getProperty(key);
216197
}
217198
} while (updateShape(object));
218199

219200
assert object.getShape() == oldShape;
201+
assert !Flags.isPutIfAbsent(mode) || oldShape != newShape;
202+
220203
Location location = property.getLocation();
204+
location.setInternal(object, value, false, oldShape, newShape);
205+
221206
if (oldShape != newShape) {
222-
DynamicObjectSupport.grow(object, oldShape, newShape);
223-
location.setSafe(object, value, false, true);
224207
DynamicObjectSupport.setShapeWithStoreFence(object, newShape);
225208
updateShape(object);
226-
} else if (Flags.isPutIfAbsent(putFlags)) {
227-
return false;
228-
} else {
229-
location.setSafe(object, value, false, false);
230209
}
231210
return true;
232211
}

0 commit comments

Comments
 (0)