Skip to content

Commit c502eb2

Browse files
committed
[GR-69185] Remove support for DynamicObject inline int fields
PullRequest: graal/22007
2 parents b4039c6 + d8281bd commit c502eb2

File tree

12 files changed

+46
-328
lines changed

12 files changed

+46
-328
lines changed

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/basic/test/DOTestAsserts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public static Assumption getTypeAssumption(Location location) {
214214
return invokeGetter("getAssumption", getTypeAssumptionRecord(location));
215215
}
216216

217-
public static Location locationForType(Shape shape, Class<?> valueType) {
218-
return invokeMethod("locationForType", invokeGetter("allocator", shape), valueType);
217+
public static Location locationForValue(Shape shape, Object value) {
218+
return invokeMethod("locationForValue", invokeGetter("allocator", shape), value);
219219
}
220220
}

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/basic/test/LocationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public void testDelete() {
217217
@Test
218218
public void testLocationDecoratorEquals() {
219219
var allocator = invokeGetter("allocator", rootShape);
220-
Location intLocation1 = invokeMethod("locationForType", allocator, int.class);
221-
Location intLocation2 = invokeMethod("locationForType", allocator, int.class);
220+
Location intLocation1 = invokeMethod("locationForValue", allocator, 42);
221+
Location intLocation2 = invokeMethod("locationForValue", allocator, 43);
222222
assertEquals(intLocation1.getClass(), intLocation2.getClass());
223223
Assert.assertNotEquals(intLocation1, intLocation2);
224224
}
@@ -241,14 +241,14 @@ public void testDeleteDeclaredProperty() {
241241
public void testLocationIsPrimitive() {
242242
var allocator = invokeGetter("allocator", rootShape);
243243

244-
Location objectLocation = invokeMethod("locationForType", allocator, Object.class);
244+
Location objectLocation = invokeMethod("locationForValue", allocator, new Object());
245245
assertFalse(objectLocation.isPrimitive());
246246

247-
Location intLocation = invokeMethod("locationForType", allocator, int.class);
247+
Location intLocation = invokeMethod("locationForValue", allocator, 42);
248248
assertTrue(intLocation.isPrimitive());
249-
Location doubleLocation = invokeMethod("locationForType", allocator, double.class);
249+
Location doubleLocation = invokeMethod("locationForValue", allocator, 3.14);
250250
assertTrue(doubleLocation.isPrimitive());
251-
Location longLocation = invokeMethod("locationForType", allocator, long.class);
251+
Location longLocation = invokeMethod("locationForValue", allocator, 43L);
252252
assertTrue(longLocation.isPrimitive());
253253

254254
Location constantLocation = invokeMethod("constantLocation", allocator, "constantValue");

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/basic/test/ShapeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
package com.oracle.truffle.object.basic.test;
4242

4343
import static com.oracle.truffle.object.basic.test.DOTestAsserts.invokeMethod;
44-
import static com.oracle.truffle.object.basic.test.DOTestAsserts.locationForType;
44+
import static com.oracle.truffle.object.basic.test.DOTestAsserts.locationForValue;
4545

4646
import java.lang.invoke.MethodHandles;
4747
import java.util.Arrays;
@@ -97,11 +97,11 @@ public void testToString() {
9797
"\"b\":Object@1",
9898
"\"a\":Object@0"}, aIntBObj);
9999

100-
Location boolLocation = locationForType(rootShape, boolean.class);
100+
Location boolLocation = locationForValue(rootShape, true);
101101
Shape bool = invokeMethod("addProperty", rootShape, Property.create("bool", boolLocation, 0));
102102
DOTestAsserts.assertShape(new String[]{"\"bool\":Object@0"}, bool);
103103

104-
Location strLocation = locationForType(rootShape, String.class);
104+
Location strLocation = locationForValue(rootShape, "");
105105
Shape str = invokeMethod("addProperty", rootShape, Property.create("str", strLocation, 0));
106106
DOTestAsserts.assertShape(new String[]{"\"str\":Object@0"}, str);
107107

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/ext/test/CustomLayoutTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ protected TestDynamicObject3(Shape shape) {
107107
}
108108

109109
static class TestDynamicObject4 extends TestDynamicObject2 {
110-
@DynamicField int p0;
111-
@DynamicField int p1;
112-
@DynamicField int p2;
110+
@DynamicField long p0;
111+
@DynamicField long p1;
112+
@DynamicField long p2;
113113

114114
protected TestDynamicObject4(Shape shape) {
115115
super(shape);

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ public Location declaredLocation(Object value) {
9696

9797
protected abstract Location locationForValueUpcast(Object value, Location oldLocation, int putFlags);
9898

99-
/**
100-
* Creates a new location for a fixed type. It can only be assigned to values of this type.
101-
* <p>
102-
* Used by tests.
103-
*
104-
* @param type the Java type this location must be compatible with (may be primitive)
105-
*/
106-
public abstract Location locationForType(Class<?> type);
107-
10899
protected <T extends Location> T advance(T location0) {
109100
if (location0 instanceof LocationImpl location) {
110101
location.accept(this);

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

Lines changed: 4 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import static com.oracle.truffle.api.object.ExtLocations.INT_ARRAY_SLOT_SIZE;
4545
import static com.oracle.truffle.api.object.ExtLocations.LONG_ARRAY_SLOT_SIZE;
4646
import static com.oracle.truffle.api.object.ExtLocations.OBJECT_SLOT_SIZE;
47-
import static com.oracle.truffle.api.object.ObjectStorageOptions.BooleanLocations;
4847
import static com.oracle.truffle.api.object.ObjectStorageOptions.DoubleLocations;
4948
import static com.oracle.truffle.api.object.ObjectStorageOptions.InObjectFields;
5049
import static com.oracle.truffle.api.object.ObjectStorageOptions.IntegerLocations;
@@ -55,8 +54,6 @@
5554

5655
import com.oracle.truffle.api.Assumption;
5756
import com.oracle.truffle.api.object.ExtLocations.AbstractObjectLocation;
58-
import com.oracle.truffle.api.object.ExtLocations.BooleanFieldLocation;
59-
import com.oracle.truffle.api.object.ExtLocations.BooleanLocation;
6057
import com.oracle.truffle.api.object.ExtLocations.DoubleArrayLocation;
6158
import com.oracle.truffle.api.object.ExtLocations.DoubleFieldLocation;
6259
import com.oracle.truffle.api.object.ExtLocations.DoubleLocation;
@@ -105,8 +102,6 @@ protected Location moveLocation(Location oldLocation) {
105102
return newDoubleLocation(decorateFinal, ((DoubleLocation) oldLocation).isImplicitCastIntToDouble(), oldLocation, NO_VALUE);
106103
} else if (oldLocation instanceof LongLocation) {
107104
return newLongLocation(decorateFinal, ((LongLocation) oldLocation).isImplicitCastIntToLong(), oldLocation, NO_VALUE);
108-
} else if (oldLocation instanceof BooleanLocation) {
109-
return newBooleanLocation(decorateFinal, oldLocation, NO_VALUE);
110105
} else if (oldLocation instanceof ObjectFieldLocation) {
111106
return newObjectLocation(decorateFinal, oldLocation, NO_VALUE);
112107
} else if (oldLocation instanceof ObjectArrayLocation) {
@@ -116,10 +111,6 @@ protected Location moveLocation(Location oldLocation) {
116111
return advance(oldLocation);
117112
}
118113

119-
public Location newObjectLocation() {
120-
return newObjectLocation(false, null, NO_VALUE);
121-
}
122-
123114
private Location newObjectLocation(boolean decorateFinal, Location oldLocation, Object value) {
124115
if (InObjectFields) {
125116
LayoutImpl l = getLayout();
@@ -143,33 +134,6 @@ private Location newObjectArrayLocation(boolean decorateFinal, Location oldLocat
143134
return advance(location);
144135
}
145136

146-
private Location newTypedObjectLocation(Class<?> type, boolean nonNull, boolean decorateFinal, Location oldLocation, Object value) {
147-
if (InObjectFields) {
148-
LayoutImpl l = getLayout();
149-
int insertPos = objectFieldSize;
150-
if (insertPos + OBJECT_SLOT_SIZE <= l.getObjectFieldCount()) {
151-
FieldInfo fieldInfo = l.getObjectField(insertPos);
152-
TypeAssumption initialTypeAssumption = getTypeAssumptionForTypeOrValue(type, nonNull, oldLocation, value);
153-
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
154-
LocationImpl location = newObjectFieldLocationWithAssumption(insertPos, fieldInfo, initialTypeAssumption, initialFinalAssumption);
155-
return advance(location);
156-
}
157-
}
158-
return newTypedObjectArrayLocation(type, nonNull, decorateFinal, oldLocation, value);
159-
}
160-
161-
private Location newTypedObjectArrayLocation(Class<?> type, boolean nonNull, boolean decorateFinal, Location oldLocation, Object value) {
162-
if (type != Object.class) {
163-
int index = objectArraySize;
164-
TypeAssumption initialTypeAssumption = getTypeAssumptionForTypeOrValue(type, nonNull, oldLocation, value);
165-
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
166-
LocationImpl location = newObjectArrayLocationWithAssumption(index, initialTypeAssumption, initialFinalAssumption);
167-
return advance(location);
168-
} else {
169-
return newObjectArrayLocation(decorateFinal, oldLocation, value);
170-
}
171-
}
172-
173137
private static ObjectFieldLocation newObjectFieldLocationWithAssumption(int index, FieldInfo fieldInfo,
174138
TypeAssumption initialTypeAssumption, Assumption initialFinalAssumption) {
175139
return new ObjectFieldLocation(index, fieldInfo, initialFinalAssumption, initialTypeAssumption);
@@ -198,17 +162,6 @@ private static TypeAssumption getTypeAssumption(Location oldLocation, Object val
198162
return TypeAssumption.ANY;
199163
}
200164

201-
private static TypeAssumption getTypeAssumptionForTypeOrValue(Class<?> type, boolean nonNull, Location oldLocation, Object value) {
202-
if (!NewTypeSpeculation && !NewFinalSpeculation && value == NO_VALUE) {
203-
if (oldLocation instanceof AbstractObjectLocation) {
204-
return ((AbstractObjectLocation) oldLocation).getTypeAssumption();
205-
}
206-
return AbstractObjectLocation.createTypeAssumption(type, nonNull);
207-
} else {
208-
return getTypeAssumption(oldLocation, value);
209-
}
210-
}
211-
212165
private static Assumption getFinalAssumption(Location oldLocation, boolean allowFinalSpeculation) {
213166
if (NewFinalSpeculation && allowFinalSpeculation) {
214167
if (oldLocation == null) {
@@ -224,31 +177,8 @@ private static Assumption getFinalAssumption(Location oldLocation, boolean allow
224177
}
225178

226179
private static int tryAllocatePrimitiveSlot(LayoutImpl l, int startIndex, final int desiredBytes) {
227-
if (desiredBytes > l.getPrimitiveFieldMaxSize()) {
228-
// no primitive fields in this layout that are wide enough
229-
return -1;
230-
}
231-
for (int fieldIndex = startIndex; fieldIndex < l.getPrimitiveFieldCount(); fieldIndex++) {
232-
// ensure alignment
233-
final int align = desiredBytes - 1;
234-
FieldInfo fieldInfo = l.getPrimitiveField(fieldIndex);
235-
if ((fieldInfo.offset() & align) != 0) {
236-
continue;
237-
}
238-
239-
int availableBytes = fieldInfo.getBytes();
240-
if (availableBytes < desiredBytes) {
241-
// this field is not suitable for the desired number of bytes, try the next one
242-
continue;
243-
}
244-
245-
return fieldIndex;
246-
}
247-
return -1;
248-
}
249-
250-
private Location newIntLocation() {
251-
return newIntLocation(false, null, NO_VALUE);
180+
assert desiredBytes <= Long.BYTES;
181+
return startIndex < l.getPrimitiveFieldCount() ? startIndex : -1;
252182
}
253183

254184
private Location newIntLocation(boolean decorateFinal, Location oldLocation, Object value) {
@@ -273,20 +203,15 @@ private Location newIntLocation(boolean decorateFinal, Location oldLocation, Obj
273203
return newObjectLocation(decorateFinal, oldLocation, value);
274204
}
275205

276-
private Location newDoubleLocation() {
277-
return newDoubleLocation(false, getLayout().isAllowedIntToDouble(), null, NO_VALUE);
278-
}
279-
280206
private Location newDoubleLocation(boolean decorateFinal, boolean allowIntToDouble, Location oldLocation, Object value) {
281207
if (PrimitiveLocations && DoubleLocations) {
282208
LayoutImpl l = getLayout();
283209
if (InObjectFields) {
284210
int fieldIndex = tryAllocatePrimitiveSlot(l, primitiveFieldSize, Double.BYTES);
285211
if (fieldIndex >= 0) {
286212
FieldInfo fieldInfo = l.getPrimitiveField(fieldIndex);
287-
int slotCount = Double.BYTES / fieldInfo.getBytes();
288213
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
289-
LocationImpl location = new DoubleFieldLocation(fieldIndex, fieldInfo, allowIntToDouble, slotCount, initialFinalAssumption);
214+
LocationImpl location = new DoubleFieldLocation(fieldIndex, fieldInfo, allowIntToDouble, initialFinalAssumption);
290215
return advance(location);
291216
}
292217
}
@@ -318,20 +243,15 @@ private static int alignArrayIndex(int index, int slotSize) {
318243
}
319244
}
320245

321-
private Location newLongLocation() {
322-
return newLongLocation(false, getLayout().isAllowedIntToLong(), null, NO_VALUE);
323-
}
324-
325246
private Location newLongLocation(boolean decorateFinal, boolean allowIntToLong, Location oldLocation, Object value) {
326247
if (PrimitiveLocations && LongLocations) {
327248
LayoutImpl l = getLayout();
328249
if (InObjectFields) {
329250
int fieldIndex = tryAllocatePrimitiveSlot(l, primitiveFieldSize, Long.BYTES);
330251
if (fieldIndex >= 0) {
331252
FieldInfo fieldInfo = l.getPrimitiveField(fieldIndex);
332-
int slotCount = Long.BYTES / fieldInfo.getBytes();
333253
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
334-
LocationImpl location = new LongFieldLocation(fieldIndex, fieldInfo, allowIntToLong, slotCount, initialFinalAssumption);
254+
LocationImpl location = new LongFieldLocation(fieldIndex, fieldInfo, allowIntToLong, initialFinalAssumption);
335255
return advance(location);
336256
}
337257
}
@@ -345,26 +265,6 @@ private Location newLongLocation(boolean decorateFinal, boolean allowIntToLong,
345265
return newObjectLocation(decorateFinal, oldLocation, value);
346266
}
347267

348-
private Location newBooleanLocation() {
349-
return newBooleanLocation(false, null, NO_VALUE);
350-
}
351-
352-
private Location newBooleanLocation(boolean decorateFinal, Location oldLocation, Object value) {
353-
if (PrimitiveLocations && BooleanLocations && InObjectFields) {
354-
LayoutImpl l = getLayout();
355-
int fieldIndex = tryAllocatePrimitiveSlot(l, primitiveFieldSize, Integer.BYTES);
356-
if (fieldIndex >= 0) {
357-
FieldInfo fieldInfo = l.getPrimitiveField(fieldIndex);
358-
if (fieldInfo.type() == int.class) {
359-
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
360-
LocationImpl location = new BooleanFieldLocation(fieldIndex, fieldInfo, initialFinalAssumption);
361-
return advance(location);
362-
}
363-
}
364-
}
365-
return newObjectLocation(decorateFinal, oldLocation, value);
366-
}
367-
368268
@Override
369269
protected Location locationForValueUpcast(Object value, Location oldLocation, int putFlags) {
370270
assert !oldLocation.canStore(value);
@@ -413,29 +313,10 @@ Location locationForValue(Object value, int putFlags) {
413313
return newDoubleLocation(decorateFinal, getLayout().isAllowedIntToDouble(), null, value);
414314
} else if (value instanceof Long) {
415315
return newLongLocation(decorateFinal, getLayout().isAllowedIntToLong(), null, value);
416-
} else if (value instanceof Boolean) {
417-
return newBooleanLocation(decorateFinal, null, value);
418316
}
419317
return newObjectLocation(decorateFinal, null, value);
420318
}
421319

422-
@Override
423-
public Location locationForType(Class<?> type) {
424-
if (type == int.class) {
425-
return newIntLocation();
426-
} else if (type == double.class) {
427-
return newDoubleLocation();
428-
} else if (type == long.class) {
429-
return newLongLocation();
430-
} else if (type == boolean.class) {
431-
return newBooleanLocation();
432-
} else if (type != null && type != Object.class) {
433-
assert !type.isPrimitive() : "unsupported primitive type";
434-
return newTypedObjectLocation(type, false, false, null, NO_VALUE);
435-
}
436-
return newObjectLocation();
437-
}
438-
439320
static Class<?> getCommonSuperclass(Class<?> a, Class<?> b) {
440321
Class<?> type = a;
441322
while (type != Object.class) {

0 commit comments

Comments
 (0)