Skip to content

Commit d8281bd

Browse files
committed
Remove locationForType(), it was only used in tests
1 parent 2b99240 commit d8281bd

File tree

5 files changed

+11
-91
lines changed

5 files changed

+11
-91
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/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: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ protected Location moveLocation(Location oldLocation) {
111111
return advance(oldLocation);
112112
}
113113

114-
public Location newObjectLocation() {
115-
return newObjectLocation(false, null, NO_VALUE);
116-
}
117-
118114
private Location newObjectLocation(boolean decorateFinal, Location oldLocation, Object value) {
119115
if (InObjectFields) {
120116
LayoutImpl l = getLayout();
@@ -138,33 +134,6 @@ private Location newObjectArrayLocation(boolean decorateFinal, Location oldLocat
138134
return advance(location);
139135
}
140136

141-
private Location newTypedObjectLocation(Class<?> type, boolean nonNull, boolean decorateFinal, Location oldLocation, Object value) {
142-
if (InObjectFields) {
143-
LayoutImpl l = getLayout();
144-
int insertPos = objectFieldSize;
145-
if (insertPos + OBJECT_SLOT_SIZE <= l.getObjectFieldCount()) {
146-
FieldInfo fieldInfo = l.getObjectField(insertPos);
147-
TypeAssumption initialTypeAssumption = getTypeAssumptionForTypeOrValue(type, nonNull, oldLocation, value);
148-
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
149-
LocationImpl location = newObjectFieldLocationWithAssumption(insertPos, fieldInfo, initialTypeAssumption, initialFinalAssumption);
150-
return advance(location);
151-
}
152-
}
153-
return newTypedObjectArrayLocation(type, nonNull, decorateFinal, oldLocation, value);
154-
}
155-
156-
private Location newTypedObjectArrayLocation(Class<?> type, boolean nonNull, boolean decorateFinal, Location oldLocation, Object value) {
157-
if (type != Object.class) {
158-
int index = objectArraySize;
159-
TypeAssumption initialTypeAssumption = getTypeAssumptionForTypeOrValue(type, nonNull, oldLocation, value);
160-
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
161-
LocationImpl location = newObjectArrayLocationWithAssumption(index, initialTypeAssumption, initialFinalAssumption);
162-
return advance(location);
163-
} else {
164-
return newObjectArrayLocation(decorateFinal, oldLocation, value);
165-
}
166-
}
167-
168137
private static ObjectFieldLocation newObjectFieldLocationWithAssumption(int index, FieldInfo fieldInfo,
169138
TypeAssumption initialTypeAssumption, Assumption initialFinalAssumption) {
170139
return new ObjectFieldLocation(index, fieldInfo, initialFinalAssumption, initialTypeAssumption);
@@ -193,17 +162,6 @@ private static TypeAssumption getTypeAssumption(Location oldLocation, Object val
193162
return TypeAssumption.ANY;
194163
}
195164

196-
private static TypeAssumption getTypeAssumptionForTypeOrValue(Class<?> type, boolean nonNull, Location oldLocation, Object value) {
197-
if (!NewTypeSpeculation && !NewFinalSpeculation && value == NO_VALUE) {
198-
if (oldLocation instanceof AbstractObjectLocation) {
199-
return ((AbstractObjectLocation) oldLocation).getTypeAssumption();
200-
}
201-
return AbstractObjectLocation.createTypeAssumption(type, nonNull);
202-
} else {
203-
return getTypeAssumption(oldLocation, value);
204-
}
205-
}
206-
207165
private static Assumption getFinalAssumption(Location oldLocation, boolean allowFinalSpeculation) {
208166
if (NewFinalSpeculation && allowFinalSpeculation) {
209167
if (oldLocation == null) {
@@ -223,10 +181,6 @@ private static int tryAllocatePrimitiveSlot(LayoutImpl l, int startIndex, final
223181
return startIndex < l.getPrimitiveFieldCount() ? startIndex : -1;
224182
}
225183

226-
private Location newIntLocation() {
227-
return newIntLocation(false, null, NO_VALUE);
228-
}
229-
230184
private Location newIntLocation(boolean decorateFinal, Location oldLocation, Object value) {
231185
if (PrimitiveLocations && IntegerLocations) {
232186
LayoutImpl l = getLayout();
@@ -249,10 +203,6 @@ private Location newIntLocation(boolean decorateFinal, Location oldLocation, Obj
249203
return newObjectLocation(decorateFinal, oldLocation, value);
250204
}
251205

252-
private Location newDoubleLocation() {
253-
return newDoubleLocation(false, getLayout().isAllowedIntToDouble(), null, NO_VALUE);
254-
}
255-
256206
private Location newDoubleLocation(boolean decorateFinal, boolean allowIntToDouble, Location oldLocation, Object value) {
257207
if (PrimitiveLocations && DoubleLocations) {
258208
LayoutImpl l = getLayout();
@@ -293,10 +243,6 @@ private static int alignArrayIndex(int index, int slotSize) {
293243
}
294244
}
295245

296-
private Location newLongLocation() {
297-
return newLongLocation(false, getLayout().isAllowedIntToLong(), null, NO_VALUE);
298-
}
299-
300246
private Location newLongLocation(boolean decorateFinal, boolean allowIntToLong, Location oldLocation, Object value) {
301247
if (PrimitiveLocations && LongLocations) {
302248
LayoutImpl l = getLayout();
@@ -371,23 +317,6 @@ Location locationForValue(Object value, int putFlags) {
371317
return newObjectLocation(decorateFinal, null, value);
372318
}
373319

374-
@Override
375-
public Location locationForType(Class<?> type) {
376-
if (type == int.class) {
377-
return newIntLocation();
378-
} else if (type == double.class) {
379-
return newDoubleLocation();
380-
} else if (type == long.class) {
381-
return newLongLocation();
382-
} else if (type == boolean.class) {
383-
return locationForValue(true);
384-
} else if (type != null && type != Object.class) {
385-
assert !type.isPrimitive() : "unsupported primitive type";
386-
return newTypedObjectLocation(type, false, false, null, NO_VALUE);
387-
}
388-
return newObjectLocation();
389-
}
390-
391320
static Class<?> getCommonSuperclass(Class<?> a, Class<?> b) {
392321
Class<?> type = a;
393322
while (type != Object.class) {

0 commit comments

Comments
 (0)