44
44
import static com .oracle .truffle .api .object .ExtLocations .INT_ARRAY_SLOT_SIZE ;
45
45
import static com .oracle .truffle .api .object .ExtLocations .LONG_ARRAY_SLOT_SIZE ;
46
46
import static com .oracle .truffle .api .object .ExtLocations .OBJECT_SLOT_SIZE ;
47
- import static com .oracle .truffle .api .object .ObjectStorageOptions .BooleanLocations ;
48
47
import static com .oracle .truffle .api .object .ObjectStorageOptions .DoubleLocations ;
49
48
import static com .oracle .truffle .api .object .ObjectStorageOptions .InObjectFields ;
50
49
import static com .oracle .truffle .api .object .ObjectStorageOptions .IntegerLocations ;
55
54
56
55
import com .oracle .truffle .api .Assumption ;
57
56
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 ;
60
57
import com .oracle .truffle .api .object .ExtLocations .DoubleArrayLocation ;
61
58
import com .oracle .truffle .api .object .ExtLocations .DoubleFieldLocation ;
62
59
import com .oracle .truffle .api .object .ExtLocations .DoubleLocation ;
@@ -105,8 +102,6 @@ protected Location moveLocation(Location oldLocation) {
105
102
return newDoubleLocation (decorateFinal , ((DoubleLocation ) oldLocation ).isImplicitCastIntToDouble (), oldLocation , NO_VALUE );
106
103
} else if (oldLocation instanceof LongLocation ) {
107
104
return newLongLocation (decorateFinal , ((LongLocation ) oldLocation ).isImplicitCastIntToLong (), oldLocation , NO_VALUE );
108
- } else if (oldLocation instanceof BooleanLocation ) {
109
- return newBooleanLocation (decorateFinal , oldLocation , NO_VALUE );
110
105
} else if (oldLocation instanceof ObjectFieldLocation ) {
111
106
return newObjectLocation (decorateFinal , oldLocation , NO_VALUE );
112
107
} else if (oldLocation instanceof ObjectArrayLocation ) {
@@ -116,10 +111,6 @@ protected Location moveLocation(Location oldLocation) {
116
111
return advance (oldLocation );
117
112
}
118
113
119
- public Location newObjectLocation () {
120
- return newObjectLocation (false , null , NO_VALUE );
121
- }
122
-
123
114
private Location newObjectLocation (boolean decorateFinal , Location oldLocation , Object value ) {
124
115
if (InObjectFields ) {
125
116
LayoutImpl l = getLayout ();
@@ -143,33 +134,6 @@ private Location newObjectArrayLocation(boolean decorateFinal, Location oldLocat
143
134
return advance (location );
144
135
}
145
136
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
-
173
137
private static ObjectFieldLocation newObjectFieldLocationWithAssumption (int index , FieldInfo fieldInfo ,
174
138
TypeAssumption initialTypeAssumption , Assumption initialFinalAssumption ) {
175
139
return new ObjectFieldLocation (index , fieldInfo , initialFinalAssumption , initialTypeAssumption );
@@ -198,17 +162,6 @@ private static TypeAssumption getTypeAssumption(Location oldLocation, Object val
198
162
return TypeAssumption .ANY ;
199
163
}
200
164
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
-
212
165
private static Assumption getFinalAssumption (Location oldLocation , boolean allowFinalSpeculation ) {
213
166
if (NewFinalSpeculation && allowFinalSpeculation ) {
214
167
if (oldLocation == null ) {
@@ -224,31 +177,8 @@ private static Assumption getFinalAssumption(Location oldLocation, boolean allow
224
177
}
225
178
226
179
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 ;
252
182
}
253
183
254
184
private Location newIntLocation (boolean decorateFinal , Location oldLocation , Object value ) {
@@ -273,20 +203,15 @@ private Location newIntLocation(boolean decorateFinal, Location oldLocation, Obj
273
203
return newObjectLocation (decorateFinal , oldLocation , value );
274
204
}
275
205
276
- private Location newDoubleLocation () {
277
- return newDoubleLocation (false , getLayout ().isAllowedIntToDouble (), null , NO_VALUE );
278
- }
279
-
280
206
private Location newDoubleLocation (boolean decorateFinal , boolean allowIntToDouble , Location oldLocation , Object value ) {
281
207
if (PrimitiveLocations && DoubleLocations ) {
282
208
LayoutImpl l = getLayout ();
283
209
if (InObjectFields ) {
284
210
int fieldIndex = tryAllocatePrimitiveSlot (l , primitiveFieldSize , Double .BYTES );
285
211
if (fieldIndex >= 0 ) {
286
212
FieldInfo fieldInfo = l .getPrimitiveField (fieldIndex );
287
- int slotCount = Double .BYTES / fieldInfo .getBytes ();
288
213
Assumption initialFinalAssumption = getFinalAssumption (oldLocation , decorateFinal );
289
- LocationImpl location = new DoubleFieldLocation (fieldIndex , fieldInfo , allowIntToDouble , slotCount , initialFinalAssumption );
214
+ LocationImpl location = new DoubleFieldLocation (fieldIndex , fieldInfo , allowIntToDouble , initialFinalAssumption );
290
215
return advance (location );
291
216
}
292
217
}
@@ -318,20 +243,15 @@ private static int alignArrayIndex(int index, int slotSize) {
318
243
}
319
244
}
320
245
321
- private Location newLongLocation () {
322
- return newLongLocation (false , getLayout ().isAllowedIntToLong (), null , NO_VALUE );
323
- }
324
-
325
246
private Location newLongLocation (boolean decorateFinal , boolean allowIntToLong , Location oldLocation , Object value ) {
326
247
if (PrimitiveLocations && LongLocations ) {
327
248
LayoutImpl l = getLayout ();
328
249
if (InObjectFields ) {
329
250
int fieldIndex = tryAllocatePrimitiveSlot (l , primitiveFieldSize , Long .BYTES );
330
251
if (fieldIndex >= 0 ) {
331
252
FieldInfo fieldInfo = l .getPrimitiveField (fieldIndex );
332
- int slotCount = Long .BYTES / fieldInfo .getBytes ();
333
253
Assumption initialFinalAssumption = getFinalAssumption (oldLocation , decorateFinal );
334
- LocationImpl location = new LongFieldLocation (fieldIndex , fieldInfo , allowIntToLong , slotCount , initialFinalAssumption );
254
+ LocationImpl location = new LongFieldLocation (fieldIndex , fieldInfo , allowIntToLong , initialFinalAssumption );
335
255
return advance (location );
336
256
}
337
257
}
@@ -345,26 +265,6 @@ private Location newLongLocation(boolean decorateFinal, boolean allowIntToLong,
345
265
return newObjectLocation (decorateFinal , oldLocation , value );
346
266
}
347
267
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
-
368
268
@ Override
369
269
protected Location locationForValueUpcast (Object value , Location oldLocation , int putFlags ) {
370
270
assert !oldLocation .canStore (value );
@@ -413,29 +313,10 @@ Location locationForValue(Object value, int putFlags) {
413
313
return newDoubleLocation (decorateFinal , getLayout ().isAllowedIntToDouble (), null , value );
414
314
} else if (value instanceof Long ) {
415
315
return newLongLocation (decorateFinal , getLayout ().isAllowedIntToLong (), null , value );
416
- } else if (value instanceof Boolean ) {
417
- return newBooleanLocation (decorateFinal , null , value );
418
316
}
419
317
return newObjectLocation (decorateFinal , null , value );
420
318
}
421
319
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
-
439
320
static Class <?> getCommonSuperclass (Class <?> a , Class <?> b ) {
440
321
Class <?> type = a ;
441
322
while (type != Object .class ) {
0 commit comments