Skip to content

Commit 9e510e3

Browse files
committed
Remove unused code and simplify locationForValueUpcast.
1 parent 319fa92 commit 9e510e3

File tree

7 files changed

+82
-189
lines changed

7 files changed

+82
-189
lines changed

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

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -87,45 +87,37 @@ public CoreLocation declaredLocation(Object value) {
8787

8888
@Override
8989
protected Location moveLocation(Location oldLocation) {
90-
if (oldLocation instanceof LongLocation) {
91-
return newLongLocation(oldLocation.isFinal(), ((LongLocation) oldLocation).isImplicitCastIntToLong());
90+
if (oldLocation instanceof LongLocation longLocation) {
91+
return newLongLocation(longLocation.isImplicitCastIntToLong());
9292
} else if (oldLocation instanceof IntLocation) {
93-
return newIntLocation(oldLocation.isFinal());
94-
} else if (oldLocation instanceof DoubleLocation) {
95-
return newDoubleLocation(oldLocation.isFinal(), ((DoubleLocation) oldLocation).isImplicitCastIntToDouble());
93+
return newIntLocation();
94+
} else if (oldLocation instanceof DoubleLocation doubleLocation) {
95+
return newDoubleLocation(doubleLocation.isImplicitCastIntToDouble());
9696
} else if (oldLocation instanceof BooleanLocation) {
97-
return newBooleanLocation(oldLocation.isFinal());
97+
return newBooleanLocation();
9898
} else if (oldLocation instanceof ObjectLocation) {
99-
return newObjectLocation(oldLocation.isFinal(), ((ObjectLocation) oldLocation).isNonNull());
99+
return newObjectLocation();
100100
} else {
101101
assert oldLocation instanceof CoreLocations.ValueLocation : oldLocation;
102102
return advance(oldLocation);
103103
}
104104
}
105105

106-
@Override
107-
public Location newObjectLocation(boolean useFinal, boolean nonNull) {
106+
private Location newObjectLocation() {
108107
if (ObjectStorageOptions.InObjectFields) {
109108
int insertPos = objectFieldSize;
110109
if (insertPos + OBJECT_SLOT_SIZE <= getLayout().getObjectFieldCount()) {
111110
return advance((Location) getLayout().getObjectFieldLocation(insertPos));
112111
}
113112
}
114-
return newObjectArrayLocation(useFinal, nonNull);
113+
return newObjectArrayLocation();
115114
}
116115

117-
@SuppressWarnings("unused")
118-
private Location newObjectArrayLocation(boolean useFinal, boolean nonNull) {
116+
private Location newObjectArrayLocation() {
119117
return advance(new ObjectArrayLocation(objectArraySize));
120118
}
121119

122-
@Override
123-
public Location newTypedObjectLocation(boolean useFinal, Class<?> type, boolean nonNull) {
124-
return newObjectLocation(useFinal, nonNull);
125-
}
126-
127-
@Override
128-
protected Location newIntLocation(boolean useFinal) {
120+
private Location newIntLocation() {
129121
if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.IntegerLocations) {
130122
if (ObjectStorageOptions.InObjectFields && primitiveFieldSize + getLayout().getLongFieldSize() <= getLayout().getPrimitiveFieldCount()) {
131123
return advance(new IntLocationDecorator(getLayout().getPrimitiveFieldLocation(primitiveFieldSize)));
@@ -134,15 +126,14 @@ protected Location newIntLocation(boolean useFinal) {
134126
return advance(new IntLocationDecorator(new LongArrayLocation(alignedIndex)));
135127
}
136128
}
137-
return newObjectLocation(useFinal, true);
129+
return newObjectLocation();
138130
}
139131

140-
@Override
141-
public Location newDoubleLocation(boolean useFinal) {
142-
return newDoubleLocation(useFinal, getLayout().isAllowedIntToDouble());
132+
private Location newDoubleLocation() {
133+
return newDoubleLocation(getLayout().isAllowedIntToDouble());
143134
}
144135

145-
Location newDoubleLocation(boolean useFinal, boolean allowedIntToDouble) {
136+
Location newDoubleLocation(boolean allowedIntToDouble) {
146137
if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.DoubleLocations) {
147138
if (ObjectStorageOptions.InObjectFields && primitiveFieldSize + getLayout().getLongFieldSize() <= getLayout().getPrimitiveFieldCount()) {
148139
return advance(new DoubleLocationDecorator(getLayout().getPrimitiveFieldLocation(primitiveFieldSize), allowedIntToDouble));
@@ -151,15 +142,14 @@ Location newDoubleLocation(boolean useFinal, boolean allowedIntToDouble) {
151142
return advance(new DoubleLocationDecorator(new LongArrayLocation(alignedIndex), allowedIntToDouble));
152143
}
153144
}
154-
return newObjectLocation(useFinal, true);
145+
return newObjectLocation();
155146
}
156147

157-
@Override
158-
public Location newLongLocation(boolean useFinal) {
159-
return newLongLocation(useFinal, getLayout().isAllowedIntToLong());
148+
private Location newLongLocation() {
149+
return newLongLocation(getLayout().isAllowedIntToLong());
160150
}
161151

162-
Location newLongLocation(boolean useFinal, boolean allowedIntToLong) {
152+
Location newLongLocation(boolean allowedIntToLong) {
163153
if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.LongLocations) {
164154
if (ObjectStorageOptions.InObjectFields && primitiveFieldSize + getLayout().getLongFieldSize() <= getLayout().getPrimitiveFieldCount()) {
165155
return advance((Location) CoreLocations.createLongLocation(getLayout().getPrimitiveFieldLocation(primitiveFieldSize), allowedIntToLong));
@@ -168,59 +158,53 @@ Location newLongLocation(boolean useFinal, boolean allowedIntToLong) {
168158
return advance(new LongArrayLocation(alignedIndex, allowedIntToLong));
169159
}
170160
}
171-
return newObjectLocation(useFinal, true);
161+
return newObjectLocation();
172162
}
173163

174-
@Override
175-
public Location newBooleanLocation(boolean useFinal) {
164+
private Location newBooleanLocation() {
176165
if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.BooleanLocations) {
177166
if (primitiveFieldSize + getLayout().getLongFieldSize() <= getLayout().getPrimitiveFieldCount()) {
178167
return advance(new BooleanLocationDecorator(getLayout().getPrimitiveFieldLocation(primitiveFieldSize)));
179168
}
180169
}
181-
return newObjectLocation(useFinal, true);
170+
return newObjectLocation();
182171
}
183172

184173
@Override
185-
protected Location locationForValue(Object value, boolean useFinal, boolean nonNull) {
186-
return locationForValue(value, useFinal, nonNull, 0);
174+
public Location locationForValue(Object value) {
175+
return locationForValue(value, 0);
187176
}
188177

189-
Location locationForValue(Object value, boolean useFinal, boolean nonNull, int putFlags) {
178+
Location locationForValue(Object value, int putFlags) {
190179
if (Flags.isConstant(putFlags)) {
191180
return constantLocation(value);
192181
} else if (Flags.isDeclaration(putFlags)) {
193182
return declaredLocation(value);
194183
}
195184
if (value instanceof Integer) {
196-
return newIntLocation(useFinal);
185+
return newIntLocation();
197186
} else if (value instanceof Double) {
198-
return newDoubleLocation(useFinal, Flags.isImplicitCastIntToDouble(putFlags) || layout.isAllowedIntToDouble());
187+
return newDoubleLocation(Flags.isImplicitCastIntToDouble(putFlags) || layout.isAllowedIntToDouble());
199188
} else if (value instanceof Long) {
200-
return newLongLocation(useFinal, Flags.isImplicitCastIntToLong(putFlags) || layout.isAllowedIntToLong());
189+
return newLongLocation(Flags.isImplicitCastIntToLong(putFlags) || layout.isAllowedIntToLong());
201190
} else if (value instanceof Boolean) {
202-
return newBooleanLocation(useFinal);
203-
} else if (ObjectStorageOptions.TypedObjectLocations && value != null) {
204-
return newTypedObjectLocation(useFinal, value.getClass(), nonNull);
191+
return newBooleanLocation();
205192
}
206-
return newObjectLocation(useFinal, nonNull && value != null);
193+
return newObjectLocation();
207194
}
208195

209196
@Override
210-
protected Location locationForType(Class<?> type, boolean useFinal, boolean nonNull) {
197+
public Location locationForType(Class<?> type) {
211198
if (type == int.class) {
212-
return newIntLocation(useFinal);
199+
return newIntLocation();
213200
} else if (type == double.class) {
214-
return newDoubleLocation(useFinal);
201+
return newDoubleLocation();
215202
} else if (type == long.class) {
216-
return newLongLocation(useFinal);
203+
return newLongLocation();
217204
} else if (type == boolean.class) {
218-
return newBooleanLocation(useFinal);
219-
} else if (ObjectStorageOptions.TypedObjectLocations && type != null && type != Object.class) {
220-
assert !type.isPrimitive() : "unsupported primitive type";
221-
return newTypedObjectLocation(useFinal, type, nonNull);
205+
return newBooleanLocation();
222206
}
223-
return newObjectLocation(useFinal, nonNull);
207+
return newObjectLocation();
224208
}
225209

226210
@Override
@@ -230,7 +214,7 @@ protected Location locationForValueUpcast(Object value, Location oldLocation, in
230214
if (oldLocation instanceof ConstantLocation && Flags.isConstant(putFlags)) {
231215
return constantLocation(value);
232216
} else if (oldLocation instanceof ValueLocation) {
233-
return locationForValue(value, false, value != null);
217+
return locationForValue(value, putFlags);
234218
} else if (oldLocation instanceof TypedLocation && ((TypedLocation) oldLocation).getType().isPrimitive()) {
235219
if (!shared && ((TypedLocation) oldLocation).getType() == int.class) {
236220
LongLocation primLocation = ((PrimitiveLocationDecorator) oldLocation).getInternalLongLocation();
@@ -242,9 +226,9 @@ protected Location locationForValueUpcast(Object value, Location oldLocation, in
242226
return new DoubleLocationDecorator(primLocation, true);
243227
}
244228
}
245-
return newObjectLocation(oldLocation.isFinal(), value != null);
229+
return newObjectLocation();
246230
}
247-
return locationForValue(value, false, value != null);
231+
return locationForValue(value, putFlags);
248232
}
249233

250234
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public BaseAllocator createAllocator(LayoutImpl layout) {
8888

8989
@Override
9090
protected Location createLocationForValue(ShapeImpl shape, Object value, int putFlags) {
91-
return ((CoreAllocator) shape.allocator()).locationForValue(value, true, value != null, putFlags);
91+
return ((CoreAllocator) shape.allocator()).locationForValue(value, putFlags);
9292
}
9393

9494
@Override

0 commit comments

Comments
 (0)