Skip to content

Commit 286d4e0

Browse files
committed
[GR-69185] Remove support for DynamicObject inline int fields
1 parent 4b023a1 commit 286d4e0

File tree

8 files changed

+25
-237
lines changed

8 files changed

+25
-237
lines changed

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/ExtAllocator.java

Lines changed: 5 additions & 53 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) {
@@ -224,27 +219,8 @@ private static Assumption getFinalAssumption(Location oldLocation, boolean allow
224219
}
225220

226221
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;
222+
assert desiredBytes <= Long.BYTES;
223+
return startIndex < l.getPrimitiveFieldCount() ? startIndex : -1;
248224
}
249225

250226
private Location newIntLocation() {
@@ -284,9 +260,8 @@ private Location newDoubleLocation(boolean decorateFinal, boolean allowIntToDoub
284260
int fieldIndex = tryAllocatePrimitiveSlot(l, primitiveFieldSize, Double.BYTES);
285261
if (fieldIndex >= 0) {
286262
FieldInfo fieldInfo = l.getPrimitiveField(fieldIndex);
287-
int slotCount = Double.BYTES / fieldInfo.getBytes();
288263
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
289-
LocationImpl location = new DoubleFieldLocation(fieldIndex, fieldInfo, allowIntToDouble, slotCount, initialFinalAssumption);
264+
LocationImpl location = new DoubleFieldLocation(fieldIndex, fieldInfo, allowIntToDouble, initialFinalAssumption);
290265
return advance(location);
291266
}
292267
}
@@ -329,9 +304,8 @@ private Location newLongLocation(boolean decorateFinal, boolean allowIntToLong,
329304
int fieldIndex = tryAllocatePrimitiveSlot(l, primitiveFieldSize, Long.BYTES);
330305
if (fieldIndex >= 0) {
331306
FieldInfo fieldInfo = l.getPrimitiveField(fieldIndex);
332-
int slotCount = Long.BYTES / fieldInfo.getBytes();
333307
Assumption initialFinalAssumption = getFinalAssumption(oldLocation, decorateFinal);
334-
LocationImpl location = new LongFieldLocation(fieldIndex, fieldInfo, allowIntToLong, slotCount, initialFinalAssumption);
308+
LocationImpl location = new LongFieldLocation(fieldIndex, fieldInfo, allowIntToLong, initialFinalAssumption);
335309
return advance(location);
336310
}
337311
}
@@ -345,26 +319,6 @@ private Location newLongLocation(boolean decorateFinal, boolean allowIntToLong,
345319
return newObjectLocation(decorateFinal, oldLocation, value);
346320
}
347321

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-
368322
@Override
369323
protected Location locationForValueUpcast(Object value, Location oldLocation, int putFlags) {
370324
assert !oldLocation.canStore(value);
@@ -413,8 +367,6 @@ Location locationForValue(Object value, int putFlags) {
413367
return newDoubleLocation(decorateFinal, getLayout().isAllowedIntToDouble(), null, value);
414368
} else if (value instanceof Long) {
415369
return newLongLocation(decorateFinal, getLayout().isAllowedIntToLong(), null, value);
416-
} else if (value instanceof Boolean) {
417-
return newBooleanLocation(decorateFinal, null, value);
418370
}
419371
return newObjectLocation(decorateFinal, null, value);
420372
}
@@ -428,7 +380,7 @@ public Location locationForType(Class<?> type) {
428380
} else if (type == long.class) {
429381
return newLongLocation();
430382
} else if (type == boolean.class) {
431-
return newBooleanLocation();
383+
return newObjectLocation();
432384
} else if (type != null && type != Object.class) {
433385
assert !type.isPrimitive() : "unsupported primitive type";
434386
return newTypedObjectLocation(type, false, false, null, NO_VALUE);

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

Lines changed: 13 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,6 @@ default void setDouble(DynamicObject store, double value, Shape shape) {
152152
}
153153
}
154154

155-
sealed interface BooleanLocation extends TypedLocation, com.oracle.truffle.api.object.BooleanLocation {
156-
@Override
157-
boolean getBoolean(DynamicObject store, boolean guard);
158-
159-
@Override
160-
default boolean getBoolean(DynamicObject store, Shape shape) {
161-
return getBoolean(store, store.getShape() == shape);
162-
}
163-
164-
void setBoolean(DynamicObject store, boolean value, boolean guard, boolean init);
165-
166-
@Override
167-
default void setBoolean(DynamicObject store, boolean value, Shape shape) {
168-
setBoolean(store, value, store.getShape() == shape, false);
169-
}
170-
171-
@Override
172-
default Class<Boolean> getType() {
173-
return boolean.class;
174-
}
175-
}
176-
177155
abstract static sealed class ValueLocation extends LocationImpl {
178156

179157
private final Object value;
@@ -775,6 +753,7 @@ abstract static sealed class AbstractPrimitiveFieldLocation extends InstanceLoca
775753

776754
AbstractPrimitiveFieldLocation(int index, FieldInfo field, Assumption finalAssumption) {
777755
super(index, finalAssumption);
756+
assert field.type() == long.class : field;
778757
this.field = Objects.requireNonNull(field);
779758
}
780759

@@ -804,7 +783,6 @@ static final class IntFieldLocation extends AbstractPrimitiveFieldLocation imple
804783

805784
IntFieldLocation(int index, FieldInfo field, Assumption finalAssumption) {
806785
super(index, field, finalAssumption);
807-
assert field.type() == long.class || field.type() == int.class : field;
808786
}
809787

810788
@Override
@@ -815,18 +793,10 @@ public Object get(DynamicObject store, boolean guard) {
815793
@Override
816794
public int getInt(DynamicObject store, boolean guard) {
817795
if (UseVarHandle) {
818-
if (field.type() == long.class) {
819-
return (int) (long) field.varHandle().get(store);
820-
} else {
821-
return (int) field.varHandle().get(store);
822-
}
796+
return (int) (long) field.varHandle().get(store);
823797
}
824798
field.receiverCheck(store);
825-
if (field.type() == long.class) {
826-
return (int) UnsafeAccess.unsafeGetLong(store, getOffset(), guard, this);
827-
} else {
828-
return UnsafeAccess.unsafeGetInt(store, getOffset(), guard, this);
829-
}
799+
return (int) UnsafeAccess.unsafeGetLong(store, getOffset(), guard, this);
830800
}
831801

832802
@Override
@@ -848,19 +818,11 @@ public void setInt(DynamicObject store, int value, boolean guard, boolean init)
848818

849819
private void setIntInternal(DynamicObject store, int value) {
850820
if (UseVarHandle) {
851-
if (field.type() == long.class) {
852-
field.varHandle().set(store, value & 0xffff_ffffL);
853-
} else {
854-
field.varHandle().set(store, value);
855-
}
821+
field.varHandle().set(store, value & 0xffff_ffffL);
856822
return;
857823
}
858824
field.receiverCheck(store);
859-
if (field.type() == long.class) {
860-
UnsafeAccess.unsafePutLong(store, getOffset(), value & 0xffff_ffffL, this);
861-
} else {
862-
UnsafeAccess.unsafePutInt(store, getOffset(), value, this);
863-
}
825+
UnsafeAccess.unsafePutLong(store, getOffset(), value & 0xffff_ffffL, this);
864826
}
865827

866828
@Override
@@ -886,13 +848,10 @@ public void accept(LocationVisitor locationVisitor) {
886848

887849
static final class DoubleFieldLocation extends AbstractPrimitiveFieldLocation implements DoubleLocation {
888850
private final boolean allowInt;
889-
private final byte slotSize;
890851

891-
DoubleFieldLocation(int index, FieldInfo field, boolean allowInt, int slotSize, Assumption finalAssumption) {
852+
DoubleFieldLocation(int index, FieldInfo field, boolean allowInt, Assumption finalAssumption) {
892853
super(index, field, finalAssumption);
893854
this.allowInt = allowInt;
894-
assert slotSize >= 1 && slotSize <= 2;
895-
this.slotSize = (byte) slotSize;
896855
}
897856

898857
@Override
@@ -906,11 +865,7 @@ public double getDouble(DynamicObject store, boolean guard) {
906865
return Double.longBitsToDouble((long) field.varHandle().get(store));
907866
}
908867
field.receiverCheck(store);
909-
if (field.type() == long.class) {
910-
return Double.longBitsToDouble(UnsafeAccess.unsafeGetLong(store, getOffset(), guard, this));
911-
} else {
912-
return UnsafeAccess.unsafeGetDouble(store, getOffset(), guard, this);
913-
}
868+
return Double.longBitsToDouble(UnsafeAccess.unsafeGetLong(store, getOffset(), guard, this));
914869
}
915870

916871
@Override
@@ -927,11 +882,7 @@ private void setDoubleInternal(DynamicObject store, double value) {
927882
return;
928883
}
929884
field.receiverCheck(store);
930-
if (field.type() == long.class) {
931-
UnsafeAccess.unsafePutLong(store, getOffset(), Double.doubleToRawLongBits(value), this);
932-
} else {
933-
UnsafeAccess.unsafePutDouble(store, getOffset(), value, this);
934-
}
885+
UnsafeAccess.unsafePutLong(store, getOffset(), Double.doubleToRawLongBits(value), this);
935886
}
936887

937888
@Override
@@ -970,12 +921,12 @@ public Class<Double> getType() {
970921

971922
@Override
972923
public int primitiveFieldCount() {
973-
return slotSize;
924+
return 1;
974925
}
975926

976927
@Override
977928
public void accept(LocationVisitor locationVisitor) {
978-
locationVisitor.visitPrimitiveField(getIndex(), slotSize);
929+
locationVisitor.visitPrimitiveField(getIndex(), 1);
979930
}
980931

981932
@Override
@@ -989,74 +940,6 @@ public boolean isImplicitCastIntToDouble() {
989940
}
990941
}
991942

992-
static final class BooleanFieldLocation extends AbstractPrimitiveFieldLocation implements BooleanLocation {
993-
994-
BooleanFieldLocation(int index, FieldInfo field, Assumption finalAssumption) {
995-
super(index, field, finalAssumption);
996-
assert field.type() == int.class : field;
997-
}
998-
999-
@Override
1000-
public Object get(DynamicObject store, boolean guard) {
1001-
return getBoolean(store, guard);
1002-
}
1003-
1004-
@Override
1005-
public boolean getBoolean(DynamicObject store, boolean guard) {
1006-
if (UseVarHandle) {
1007-
return UnsafeAccess.booleanCast((int) field.varHandle().get(store));
1008-
}
1009-
field.receiverCheck(store);
1010-
return UnsafeAccess.booleanCast(UnsafeAccess.unsafeGetInt(store, getOffset(), guard, this));
1011-
}
1012-
1013-
@Override
1014-
public void setBoolean(DynamicObject store, boolean value, boolean guard, boolean init) {
1015-
if (!init) {
1016-
maybeInvalidateFinalAssumption();
1017-
}
1018-
setBooleanInternal(store, value);
1019-
}
1020-
1021-
private void setBooleanInternal(DynamicObject store, boolean value) {
1022-
if (UseVarHandle) {
1023-
field.varHandle().set(store, UnsafeAccess.intCast(value));
1024-
return;
1025-
}
1026-
field.receiverCheck(store);
1027-
UnsafeAccess.unsafePutInt(store, getOffset(), UnsafeAccess.intCast(value), this);
1028-
}
1029-
1030-
@Override
1031-
protected void set(DynamicObject store, Object value, boolean guard, boolean init) {
1032-
if (canStore(value)) {
1033-
setBoolean(store, (boolean) value, guard, init);
1034-
} else {
1035-
throw incompatibleLocationException();
1036-
}
1037-
}
1038-
1039-
@Override
1040-
public boolean canStore(Object value) {
1041-
return value instanceof Boolean;
1042-
}
1043-
1044-
@Override
1045-
public Class<Boolean> getType() {
1046-
return boolean.class;
1047-
}
1048-
1049-
@Override
1050-
public int primitiveFieldCount() {
1051-
return INT_FIELD_SLOT_SIZE;
1052-
}
1053-
1054-
@Override
1055-
public void accept(LocationVisitor locationVisitor) {
1056-
locationVisitor.visitPrimitiveField(getIndex(), INT_FIELD_SLOT_SIZE);
1057-
}
1058-
}
1059-
1060943
abstract static sealed class AbstractPrimitiveArrayLocation extends InstanceLocation implements ArrayLocation {
1061944

1062945
AbstractPrimitiveArrayLocation(int index, Assumption finalAssumption) {
@@ -1224,13 +1107,10 @@ protected int getBytes() {
12241107

12251108
static final class LongFieldLocation extends AbstractPrimitiveFieldLocation implements LongLocation {
12261109
private final boolean allowInt;
1227-
private final byte slotSize;
12281110

1229-
LongFieldLocation(int index, FieldInfo field, boolean allowInt, int slotSize, Assumption finalAssumption) {
1111+
LongFieldLocation(int index, FieldInfo field, boolean allowInt, Assumption finalAssumption) {
12301112
super(index, field, finalAssumption);
12311113
this.allowInt = allowInt;
1232-
assert slotSize >= 1 && slotSize <= 2;
1233-
this.slotSize = (byte) slotSize;
12341114
}
12351115

12361116
@Override
@@ -1295,12 +1175,12 @@ public Class<Long> getType() {
12951175

12961176
@Override
12971177
public int primitiveFieldCount() {
1298-
return slotSize;
1178+
return 1;
12991179
}
13001180

13011181
@Override
13021182
public void accept(LocationVisitor locationVisitor) {
1303-
locationVisitor.visitPrimitiveField(getIndex(), slotSize);
1183+
locationVisitor.visitPrimitiveField(getIndex(), 1);
13041184
}
13051185

13061186
@Override

0 commit comments

Comments
 (0)