newLocation = oldLocation; } else { newLocation = ((BaseAllocator) oldShape.allocator()).locationForValueUpcast(value, oldLocation);
/** @since 0.17 or earlier */ protected ShapeImpl applyTransition(ShapeImpl shape, Transition transition, boolean append) { if (transition instanceof AddPropertyTransition) { Property property = ((AddPropertyTransition) transition).getProperty(); if (append) { return shape.append(property); } else { shape.onPropertyTransition(property); return addProperty(shape, property, false); } } else if (transition instanceof ObjectTypeTransition) { return shape.changeType(((ObjectTypeTransition) transition).getObjectType()); } else if (transition instanceof ReservePrimitiveArrayTransition) { return shape.reservePrimitiveExtensionArray(); } else if (transition instanceof DirectReplacePropertyTransition) { Property oldProperty = ((DirectReplacePropertyTransition) transition).getPropertyBefore(); Property newProperty = ((DirectReplacePropertyTransition) transition).getPropertyAfter(); if (append) { oldProperty = shape.getProperty(oldProperty.getKey()); newProperty = newProperty.relocate(shape.allocator().moveLocation(newProperty.getLocation())); } return directReplaceProperty(shape, oldProperty, newProperty); } else { throw new UnsupportedOperationException(transition.getClass().getName()); } }
/** @since 0.17 or earlier */ @Override protected Location locationForType(Class<?> type, boolean useFinal, boolean nonNull) { if (type == int.class) { return newIntLocation(useFinal); } else if (type == double.class) { return newDoubleLocation(useFinal); } else if (type == long.class) { return newLongLocation(useFinal); } else if (type == boolean.class) { return newBooleanLocation(useFinal); } else if (ObjectStorageOptions.TypedObjectLocations && type != null && type != Object.class) { assert !type.isPrimitive() : "unsupported primitive type"; return newTypedObjectLocation(useFinal, type, nonNull); } return newObjectLocation(useFinal, nonNull); }
/** @since 0.17 or earlier */ protected ShapeImpl applyTransition(ShapeImpl shape, Transition transition, boolean append) { if (transition instanceof AddPropertyTransition) { Property property = ((AddPropertyTransition) transition).getProperty(); if (append) { return shape.append(property); } else { shape.onPropertyTransition(property); return addProperty(shape, property, false); } } else if (transition instanceof ObjectTypeTransition) { return shape.changeType(((ObjectTypeTransition) transition).getObjectType()); } else if (transition instanceof ReservePrimitiveArrayTransition) { return shape.reservePrimitiveExtensionArray(); } else if (transition instanceof DirectReplacePropertyTransition) { Property oldProperty = ((DirectReplacePropertyTransition) transition).getPropertyBefore(); Property newProperty = ((DirectReplacePropertyTransition) transition).getPropertyAfter(); if (append) { oldProperty = shape.getProperty(oldProperty.getKey()); newProperty = newProperty.relocate(shape.allocator().moveLocation(newProperty.getLocation())); } return directReplaceProperty(shape, oldProperty, newProperty); } else { throw new UnsupportedOperationException(transition.getClass().getName()); } }
@Override protected Location locationForType(Class<?> type, boolean useFinal, boolean nonNull) { if (type == int.class) { return newIntLocation(useFinal); } else if (type == double.class) { return newDoubleLocation(useFinal); } else if (type == long.class) { return newLongLocation(useFinal); } else if (type == boolean.class) { return newBooleanLocation(useFinal); } else if (ObjectStorageOptions.TypedObjectLocations && type != null && type != Object.class) { assert !type.isPrimitive() : "unsupported primitive type"; return newTypedObjectLocation(useFinal, type, nonNull); } return newObjectLocation(useFinal, nonNull); }
/** @since 0.17 or earlier */ @Override protected Location locationForValue(Object value, boolean useFinal, boolean nonNull) { if (value instanceof Integer) { return newIntLocation(useFinal); } else if (value instanceof Double) { return newDoubleLocation(useFinal); } else if (value instanceof Long) { return newLongLocation(useFinal); } else if (value instanceof Boolean) { return newBooleanLocation(useFinal); } else if (ObjectStorageOptions.TypedObjectLocations && value != null) { return newTypedObjectLocation(useFinal, value.getClass(), nonNull); } return newObjectLocation(useFinal, nonNull && value != null); }
/** @since 0.17 or earlier */ @Override protected Location locationForValue(Object value, boolean useFinal, boolean nonNull) { if (value instanceof Integer) { return newIntLocation(useFinal); } else if (value instanceof Double) { return newDoubleLocation(useFinal); } else if (value instanceof Long) { return newLongLocation(useFinal); } else if (value instanceof Boolean) { return newBooleanLocation(useFinal); } else if (ObjectStorageOptions.TypedObjectLocations && value != null) { return newTypedObjectLocation(useFinal, value.getClass(), nonNull); } return newObjectLocation(useFinal, nonNull && value != null); }
@Override @TruffleBoundary public void define(Object id, Object value, int flags) { ShapeImpl oldShape = getShape(); Property existing = oldShape.getProperty(id); if (existing == null) { updateShape(); oldShape = getShape(); Shape newShape = oldShape.addProperty(Property.create(id, oldShape.allocator().locationForValue(value, true, true), flags)); updateShape(); newShape.getLastProperty().setGeneric(this, value, oldShape, newShape); } else { defineExisting(id, value, flags, existing, oldShape); } }
/** @since 0.17 or earlier */ @Override protected Location locationForType(Class<?> type, boolean useFinal, boolean nonNull) { if (type == int.class) { return newIntLocation(useFinal); } else if (type == double.class) { return newDoubleLocation(useFinal); } else if (type == long.class) { return newLongLocation(useFinal); } else if (type == boolean.class) { return newBooleanLocation(useFinal); } else if (ObjectStorageOptions.TypedObjectLocations && type != null && type != Object.class) { assert !type.isPrimitive() : "unsupported primitive type"; return newTypedObjectLocation(useFinal, type, nonNull); } return newObjectLocation(useFinal, nonNull); }
/** * Create a new shape that reserves the primitive extension array field. * * @since 0.17 or earlier */ protected static ShapeImpl makeShapeWithPrimitiveExtensionArray(ShapeImpl parent, Transition transition) { assert parent.getLayout().hasPrimitiveExtensionArray(); assert !parent.hasPrimitiveArray(); BaseAllocator allocator = parent.allocator().addLocation(parent.getLayout().getPrimitiveArrayLocation()); ShapeImpl newShape = parent.createShape(parent.layout, parent.sharedData, parent, parent.objectType, parent.propertyMap, transition, allocator, parent.id); assert newShape.hasPrimitiveArray(); assert newShape.depth == allocator.depth; return newShape; }
/** * Create a new shape that adds a property to the parent shape. * * @since 0.17 or earlier */ protected static ShapeImpl makeShapeWithAddedProperty(ShapeImpl parent, AddPropertyTransition addTransition) { Property addend = addTransition.getProperty(); BaseAllocator allocator = parent.allocator().addLocation(addend.getLocation()); PropertyMap newPropertyMap = parent.propertyMap.putCopy(addend); ShapeImpl newShape = parent.createShape(parent.layout, parent.sharedData, parent, parent.objectType, newPropertyMap, addTransition, allocator, parent.id); assert ((LocationImpl) addend.getLocation()).primitiveArrayCount() == 0 || newShape.hasPrimitiveArray; assert newShape.depth == allocator.depth; return newShape; }
/** * Create a new shape that reserves the primitive extension array field. * * @since 0.17 or earlier */ protected static ShapeImpl makeShapeWithPrimitiveExtensionArray(ShapeImpl parent, Transition transition) { assert parent.getLayout().hasPrimitiveExtensionArray(); assert !parent.hasPrimitiveArray(); BaseAllocator allocator = parent.allocator().addLocation(parent.getLayout().getPrimitiveArrayLocation()); ShapeImpl newShape = parent.createShape(parent.layout, parent.sharedData, parent, parent.objectType, parent.propertyMap, transition, allocator, parent.id); assert newShape.hasPrimitiveArray(); assert newShape.depth == allocator.depth; return newShape; }
@Override protected Location locationForValue(Object value, boolean useFinal, boolean nonNull) { if (value instanceof Integer) { return newIntLocation(useFinal); } else if (value instanceof Double) { return newDoubleLocation(useFinal); } else if (value instanceof Long) { return newLongLocation(useFinal); } else if (value instanceof Boolean) { return newBooleanLocation(useFinal); } else if (ObjectStorageOptions.TypedObjectLocations && value != null) { return newTypedObjectLocation(useFinal, value.getClass(), nonNull); } return newObjectLocation(useFinal, nonNull && value != null); }
protected Location newDeclaredDualLocation(Object value) { return new DeclaredDualLocation((InternalLongLocation) newLongLocation(false), (ObjectLocation) newObjectLocation(false, false), value, layout); }
/** @since 0.17 or earlier */ protected ShapeImpl directReplaceProperty(ShapeImpl shape, Property oldProperty, Property newProperty) { Transition replacePropertyTransition = new Transition.DirectReplacePropertyTransition(oldProperty, newProperty); ShapeImpl cachedShape = shape.queryTransition(replacePropertyTransition); if (cachedShape != null) { return ensureValid(cachedShape); } PropertyMap newPropertyMap = shape.getPropertyMap().replaceCopy(oldProperty, newProperty); BaseAllocator allocator = shape.allocator().addLocation(newProperty.getLocation()); ShapeImpl newShape = shape.createShape(shape.getLayout(), shape.getSharedData(), shape, shape.getObjectType(), newPropertyMap, replacePropertyTransition, allocator, shape.getId()); shape.addDirectTransition(replacePropertyTransition, newShape); return newShape; }
/** @since 0.17 or earlier */ protected ShapeImpl definePropertyChangeFlags(ShapeImpl oldShape, Property oldProperty, Object value, int flags) { Location oldLocation = oldProperty.getLocation(); Location newLocation; if (oldLocation.canSet(value)) { newLocation = oldLocation; } else { newLocation = oldShape.allocator().locationForValueUpcast(value, oldLocation); } Property newProperty = Property.create(oldProperty.getKey(), newLocation, flags); ShapeImpl newShape = oldShape.replaceProperty(oldProperty, newProperty); return newShape; }
public Location createLocation(Shape shape, Object value) { return ((ShapeImpl) shape).allocator().locationForValue(value, true, value != null); } };
/** @since 0.17 or earlier */ protected ShapeImpl directReplaceProperty(ShapeImpl shape, Property oldProperty, Property newProperty) { Transition replacePropertyTransition = new Transition.DirectReplacePropertyTransition(oldProperty, newProperty); ShapeImpl cachedShape = shape.queryTransition(replacePropertyTransition); if (cachedShape != null) { return ensureValid(cachedShape); } PropertyMap newPropertyMap = shape.getPropertyMap().replaceCopy(oldProperty, newProperty); BaseAllocator allocator = shape.allocator().addLocation(newProperty.getLocation()); ShapeImpl newShape = shape.createShape(shape.getLayout(), shape.getSharedData(), shape, shape.getObjectType(), newPropertyMap, replacePropertyTransition, allocator, shape.getId()); shape.addDirectTransition(replacePropertyTransition, newShape); return newShape; }
protected Location newDualLocation(Class<?> type) { return new DualLocation((InternalLongLocation) newLongLocation(false), (ObjectLocation) newObjectLocation(false, false), layout, type); }
@TruffleBoundary @Override public final ShapeImpl append(Property oldProperty) { return addProperty(oldProperty.relocate(allocator().moveLocation(oldProperty.getLocation()))); }