/** @since 0.17 or earlier */ @Override public final Shape createShape(ObjectType objectType) { return createShape(objectType, null); }
protected <T extends Location> T advance(T location0) { if (location0 instanceof LocationImpl) { LocationImpl location = (LocationImpl) location0; if (location != layout.getPrimitiveArrayLocation()) { location.accept(this); } if (layout.hasPrimitiveExtensionArray()) { hasPrimitiveArray |= location == layout.getPrimitiveArrayLocation() || primitiveArraySize > 0; } else { assert !hasPrimitiveArray && primitiveArraySize == 0; } } depth++; return location0; }
/** @since 0.17 or earlier */ @Override public final BaseAllocator allocator() { return layout.getStrategy().createAllocator(this); }
@Override public boolean canStore(Object value) { if (type == null) { return false; } else if (type == int.class) { return value instanceof Integer; } else if (type == long.class) { return value instanceof Long || (layout.isAllowedIntToLong() && value instanceof Integer); } else if (type == double.class) { return value instanceof Double || (layout.isAllowedIntToDouble() && value instanceof Integer); } else if (type == boolean.class) { return value instanceof Boolean; } else if (type == Object.class) { return true; } else { throw new IllegalStateException(); } } }
/** @since 0.17 or earlier */ @Override public final ShapeImpl reservePrimitiveExtensionArray() { if (layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray()) { return layout.getStrategy().addPrimitiveExtensionArray(this); } return this; }
private ShapeImpl addPrimitiveExtensionArray() { assert layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray(); Transition transition = new ReservePrimitiveArrayTransition(); ShapeImpl cachedShape = queryTransition(transition); if (cachedShape != null) { return cachedShape; } ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, layout.getPrimitiveArrayLocation()); ShapeImpl newShape = makeShapeWithPrimitiveExtensionArray(oldShape, transition); oldShape.addDirectTransition(transition, newShape); return newShape; }
/** @since 0.17 or earlier */ @Override public final DynamicObject newInstance() { return layout.newInstance(this); }
/** @since 0.17 or earlier */ @Override public final DynamicObjectFactory createFactory() { List<Property> properties = getPropertyListInternal(true); List<Property> filtered = null; for (ListIterator<Property> iterator = properties.listIterator(); iterator.hasNext();) { Property property = iterator.next(); // skip non-instance fields assert property.getLocation() != layout.getPrimitiveArrayLocation(); if (property.getLocation() instanceof ValueLocation) { if (filtered == null) { filtered = new ArrayList<>(); filtered.addAll(properties.subList(0, iterator.previousIndex())); } } else if (filtered != null) { filtered.add(property); } } if (filtered != null) { properties = filtered; } return new DynamicObjectFactoryImpl(this, properties); }
@Override public final ShapeImpl reservePrimitiveExtensionArray() { if (layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray()) { return addPrimitiveExtensionArray(); } return this; }
/** * Is this property an upcast of the other property? * * @param other the property being compared to * @return true if this is a upcast of the other property, false otherwise */ public boolean isPropertyUpcastOf(Property thiz, Property other) { if (thiz.getLocation() != null && other.getLocation() != null && other.getKey().equals(thiz.getKey()) && other.getFlags() == thiz.getFlags()) { if (isLocationAssignableFrom(thiz.getLocation(), other.getLocation())) { return true; } } return false; }
private void defineExisting(Object id, Object value, int flags, Property existing, ShapeImpl oldShape) { if (existing.getFlags() == flags) { existing.setGeneric(this, value, null); } else { Property newProperty = Property.create(id, oldShape.getLayout().existingLocationForValue(value, existing.getLocation(), oldShape), flags); Shape newShape = oldShape.replaceProperty(existing, newProperty); this.setShapeAndResize(newShape); newProperty.setInternal(this, value); } }
/** @since 0.17 or earlier */ protected ShapeImpl addPrimitiveExtensionArray(ShapeImpl shape) { LayoutImpl layout = shape.getLayout(); assert layout.hasPrimitiveExtensionArray() && !shape.hasPrimitiveArray(); Transition transition = new ReservePrimitiveArrayTransition(); ShapeImpl cachedShape = shape.queryTransition(transition); if (cachedShape != null) { return layout.getStrategy().ensureValid(cachedShape); } ShapeImpl oldShape = ensureSpace(shape, layout.getPrimitiveArrayLocation()); ShapeImpl newShape = ShapeImpl.makeShapeWithPrimitiveExtensionArray(oldShape, transition); oldShape.addDirectTransition(transition, newShape); return newShape; }
@Override public void setInternal(DynamicObject store, Object value) throws IncompatibleLocationException { if (type == Object.class) { ((LocationImpl) objectLocation).setInternal(store, value); } else { long rawValue; if (type == int.class && value instanceof Integer) { rawValue = (int) value; } else if (type == long.class && value instanceof Long) { rawValue = (long) value; } else if (type == long.class && layout.isAllowedIntToLong() && value instanceof Integer) { rawValue = (int) value; } else if (type == double.class && value instanceof Double) { rawValue = Double.doubleToRawLongBits((double) value); } else if (type == double.class && layout.isAllowedIntToDouble() && value instanceof Integer) { rawValue = Double.doubleToRawLongBits((int) value); } else if (type == boolean.class && value instanceof Boolean) { rawValue = (boolean) value ? 1 : 0; } else { throw incompatibleLocation(); } primitiveLocation.setLongInternal(store, rawValue); } }
/** @since 0.17 or earlier */ @Override public final ShapeImpl reservePrimitiveExtensionArray() { if (layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray()) { return layout.getStrategy().addPrimitiveExtensionArray(this); } return this; }
/** @since 0.17 or earlier */ @Override public final DynamicObject newInstance() { return layout.newInstance(this); }
/** @since 0.17 or earlier */ @Override public final DynamicObjectFactory createFactory() { List<Property> properties = getPropertyListInternal(true); List<Property> filtered = null; for (ListIterator<Property> iterator = properties.listIterator(); iterator.hasNext();) { Property property = iterator.next(); // skip non-instance fields assert property.getLocation() != layout.getPrimitiveArrayLocation(); if (property.getLocation() instanceof ValueLocation) { if (filtered == null) { filtered = new ArrayList<>(); filtered.addAll(properties.subList(0, iterator.previousIndex())); } } else if (filtered != null) { filtered.add(property); } } if (filtered != null) { properties = filtered; } return new DynamicObjectFactoryImpl(this, properties); }
/** @since 0.17 or earlier */ @Override public final BaseAllocator allocator() { return layout.getStrategy().createAllocator(this); }
/** @since 0.17 or earlier */ protected ShapeImpl addPrimitiveExtensionArray(ShapeImpl shape) { LayoutImpl layout = shape.getLayout(); assert layout.hasPrimitiveExtensionArray() && !shape.hasPrimitiveArray(); Transition transition = new ReservePrimitiveArrayTransition(); ShapeImpl cachedShape = shape.queryTransition(transition); if (cachedShape != null) { return layout.getStrategy().ensureValid(cachedShape); } ShapeImpl oldShape = ensureSpace(shape, layout.getPrimitiveArrayLocation()); ShapeImpl newShape = ShapeImpl.makeShapeWithPrimitiveExtensionArray(oldShape, transition); oldShape.addDirectTransition(transition, newShape); return newShape; }
/** @since 0.17 or earlier */ protected <T extends Location> T advance(T location0) { if (location0 instanceof LocationImpl) { LocationImpl location = (LocationImpl) location0; if (location != layout.getPrimitiveArrayLocation()) { location.accept(this); } if (layout.hasPrimitiveExtensionArray()) { hasPrimitiveArray |= location == layout.getPrimitiveArrayLocation() || primitiveArraySize > 0; } else { assert !hasPrimitiveArray && primitiveArraySize == 0; } } depth++; return location0; }
protected boolean isLocationAssignableFrom(Location destination, Location source) { LayoutImpl layout = this; if (destination.isFinal()) { // allowed Final<X>Location => Final<X>Location // allowed FinalIntLocation => Final{Int,Double}Location // allowed: Final{Int,Double,TypedObject}Location => FinalObjectLocation if (!source.isFinal()) { return false; } } if (destination instanceof IntLocation) { return (source instanceof IntLocation); } else if (destination instanceof DoubleLocation) { return (source instanceof DoubleLocation || (layout.isAllowedIntToDouble() && source instanceof IntLocation)); } else if (destination instanceof LongLocation) { return (source instanceof LongLocation || (layout.isAllowedIntToLong() && source instanceof IntLocation)); } else if (destination instanceof BooleanLocation) { return (source instanceof BooleanLocation); } else if (destination instanceof TypedObjectLocation) { return source instanceof TypedObjectLocation && ((TypedObjectLocation<?>) destination).getType().isAssignableFrom(((TypedObjectLocation<?>) source).getType()); } else if (destination instanceof ValueLocation) { return false; } else { assert destination instanceof ObjectLocation || destination instanceof DualLocation; return true; } }