Skip to content

Commit 63fb070

Browse files
committed
[GR-69326] Avoid duplicate property lookup in DynamicObjectLibrary.put.
PullRequest: graal/22034
2 parents a0e665e + ad6fce5 commit 63fb070

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,20 @@ static LocationImpl getLocation(Property existing) {
303303
}
304304

305305
@TruffleBoundary
306-
protected static boolean putUncached(DynamicObject object, Object key, Object value, int newPropertyFlags, int putFlags) {
307-
Shape s = object.getShape();
308-
Property existingProperty = s.getProperty(key);
306+
protected static boolean putGeneric(DynamicObject object, Object key, Object value, int newPropertyFlags, int putFlags, Shape s, Property existingProperty) {
309307
if (existingProperty == null && Flags.isSetExisting(putFlags)) {
310308
return false;
311309
}
312310
if (existingProperty != null && !Flags.isUpdateFlags(putFlags) && existingProperty.getLocation().canStore(value)) {
313311
getLocation(existingProperty).setSafe(object, value, false, false);
314312
return true;
315313
} else {
316-
return putUncachedSlow(object, key, value, newPropertyFlags, putFlags);
314+
return putGenericSlowPath(object, key, value, newPropertyFlags, putFlags, s, existingProperty);
317315
}
318316
}
319317

320-
private static boolean putUncachedSlow(DynamicObject object, Object key, Object value, int newPropertyFlags, int putFlags) {
318+
private static boolean putGenericSlowPath(DynamicObject object, Object key, Object value, int newPropertyFlags, int putFlags,
319+
Shape initialShape, Property propertyOfInitialShape) {
321320
CompilerAsserts.neverPartOfCompilation();
322321
updateShapeImpl(object);
323322
Shape oldShape;
@@ -326,7 +325,11 @@ private static boolean putUncachedSlow(DynamicObject object, Object key, Object
326325
Property property;
327326
do {
328327
oldShape = object.getShape();
329-
existingProperty = oldShape.getProperty(key);
328+
if (oldShape == initialShape) {
329+
existingProperty = propertyOfInitialShape;
330+
} else {
331+
existingProperty = oldShape.getProperty(key);
332+
}
330333
if (existingProperty == null) {
331334
if (Flags.isSetExisting(putFlags)) {
332335
return false;
@@ -720,7 +723,7 @@ public double getDoubleOrDefault(DynamicObject object, Shape cachedShape, Object
720723

721724
@Override
722725
public boolean put(DynamicObject object, Shape cachedShape, Object key, Object value, int propertyFlags, int putFlags) {
723-
return putUncached(object, key, value, propertyFlags, putFlags);
726+
return putGeneric(object, key, value, propertyFlags, putFlags, cachedShape, cachedShape.getProperty(key));
724727
}
725728

726729
@Override
@@ -1297,7 +1300,7 @@ protected boolean putImpl(DynamicObject object, Shape cachedShape, Object key, O
12971300
Shape oldShape = cachedShape;
12981301
MutateCacheData start = cache;
12991302
if (start == MutateCacheData.GENERIC || !cachedShape.isValid()) {
1300-
return putUncached(object, key, value, propertyFlags, putFlags);
1303+
return putGeneric(object, key, value, propertyFlags, putFlags, cachedShape, oldProperty);
13011304
}
13021305
for (MutateCacheData c = start; c != null; c = c.next) {
13031306
if (!c.isValid()) {
@@ -1335,7 +1338,7 @@ protected boolean putIntImpl(DynamicObject object, Shape cachedShape, Object key
13351338
Shape oldShape = cachedShape;
13361339
MutateCacheData start = cache;
13371340
if (start == MutateCacheData.GENERIC || !cachedShape.isValid()) {
1338-
return putUncached(object, key, value, propertyFlags, putFlags);
1341+
return putGeneric(object, key, value, propertyFlags, putFlags, cachedShape, oldProperty);
13391342
}
13401343
for (MutateCacheData c = start; c != null; c = c.next) {
13411344
if (!c.isValid()) {
@@ -1403,7 +1406,7 @@ protected boolean putLongImpl(DynamicObject object, Shape cachedShape, Object ke
14031406
Shape oldShape = cachedShape;
14041407
MutateCacheData start = cache;
14051408
if (start == MutateCacheData.GENERIC) {
1406-
return putUncached(object, key, value, propertyFlags, putFlags);
1409+
return putGeneric(object, key, value, propertyFlags, putFlags, cachedShape, oldProperty);
14071410
}
14081411
for (MutateCacheData c = start; c != null; c = c.next) {
14091412
if (!c.isValid()) {
@@ -1452,7 +1455,7 @@ protected boolean putDoubleImpl(DynamicObject object, Shape cachedShape, Object
14521455
Shape oldShape = cachedShape;
14531456
MutateCacheData start = cache;
14541457
if (start == MutateCacheData.GENERIC) {
1455-
return putUncached(object, key, value, propertyFlags, putFlags);
1458+
return putGeneric(object, key, value, propertyFlags, putFlags, cachedShape, oldProperty);
14561459
}
14571460
for (MutateCacheData c = start; c != null; c = c.next) {
14581461
if (!c.isValid()) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ public final class Shape {
122122

123123
private final int objectArraySize;
124124
private final int objectArrayCapacity;
125-
private final int objectFieldSize;
126-
private final int primitiveFieldSize;
127125
private final int primitiveArraySize;
128126
private final int primitiveArrayCapacity;
127+
private final short objectFieldSize;
128+
private final short primitiveFieldSize;
129129

130130
private final int depth;
131131
private final int propertyCount;
@@ -1230,10 +1230,11 @@ private Shape(LayoutImpl layout, Shape parent, Object objectType, Object sharedD
12301230

12311231
this.objectArraySize = objectArraySize;
12321232
this.objectArrayCapacity = capacityFromSize(objectArraySize);
1233-
this.objectFieldSize = objectFieldSize;
1234-
this.primitiveFieldSize = primitiveFieldSize;
12351233
this.primitiveArraySize = primitiveArraySize;
12361234
this.primitiveArrayCapacity = capacityFromSize(primitiveArraySize);
1235+
assert objectFieldSize <= ExtLocations.MAX_DYNAMIC_FIELDS && primitiveFieldSize <= ExtLocations.MAX_DYNAMIC_FIELDS;
1236+
this.objectFieldSize = (short) objectFieldSize;
1237+
this.primitiveFieldSize = (short) primitiveFieldSize;
12371238

12381239
if (parent != null) {
12391240
this.propertyCount = makePropertyCount(parent, propertyMap, transitionFromParent);

truffle/src/com.oracle.truffle.api.strings/src/com/oracle/truffle/api/strings/TStringInternalNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ abstract static class IndexOfCodePointSetNode extends Node {
13541354
final boolean isUTF16Or32;
13551355

13561356
IndexOfCodePointSetNode(IndexOfCodePointSet.IndexOfNode[] indexOfNodes, Encoding encoding) {
1357-
this.indexOfNodes = insert(indexOfNodes);
1357+
this.indexOfNodes = indexOfNodes;
13581358
this.encoding = encoding;
13591359
this.isUTF16Or32 = isUTF16Or32(encoding);
13601360
}

0 commit comments

Comments
 (0)