/** * Set shape to an immediate child of the current shape, optionally growing the extension array. * Typically this would add a single property. Cannot shrink or grow more than one property at a * time. * * @see #setShapeAndResize(Shape, Shape) * @since 0.17 or earlier */ @Override public final void setShapeAndGrow(Shape oldShape, Shape newShape) { assert getShape() == oldShape : "wrong old shape"; if (oldShape != newShape) { assert checkSetShape(oldShape, newShape); growStore(oldShape, newShape); setShape(newShape); assert checkExtensionArrayInvariants(newShape); } }
void reshapeAfterDelete(final Shape newShape, final Shape deletedParentShape) { DynamicObject original = this.cloneWithShape(getShape()); setShapeAndResize(newShape); copyProperties(original, deletedParentShape); }
/** @since 0.17 or earlier */ public String debugDump(int level) { return debugDump(0, level); }
/** * Simpler version of {@link #resizeStore} when the object is only increasing in size. */ private void growStore(Shape oldShape, Shape newShape) { growObjectStore(oldShape, newShape); if (((ShapeImpl) newShape).hasPrimitiveArray) { growPrimitiveStore(oldShape, newShape); } }
/** @since 0.17 or earlier */ protected void reshapeAfterDelete(DynamicObjectImpl object, ShapeImpl oldShape, ShapeImpl newShape, ShapeImpl deletedParentShape) { DynamicObject original = object.cloneWithShape(oldShape); object.setShapeAndResize(newShape); object.copyProperties(original, deletedParentShape); }
@Override public final void setShapeAndResize(Shape oldShape, Shape newShape) { assert getShape() == oldShape : "wrong old shape"; if (oldShape != newShape) { setShape(newShape); resizeStore(oldShape, newShape); assert checkExtensionArrayInvariants(newShape); } }
/** * Set shape to an immediate child of the current shape, optionally growing the extension array. * Typically this would add a single property. Cannot shrink or grow more than one property at a * time. * * @see #setShapeAndResize(Shape, Shape) * @since 0.17 or earlier */ @Override public final void setShapeAndGrow(Shape oldShape, Shape newShape) { assert getShape() == oldShape : "wrong old shape"; if (oldShape != newShape) { assert checkSetShape(oldShape, newShape); growStore(oldShape, newShape); setShapeImpl(newShape); assert checkExtensionArrayInvariants(newShape); } }
/** @since 0.17 or earlier */ @SuppressWarnings("deprecation") public Object getTypeIdentifier() { return getShape(); }
/** @since 0.17 or earlier */ @Override public final void setShapeAndResize(Shape oldShape, Shape newShape) { assert getShape() == oldShape : "wrong old shape"; assert !oldShape.isShared(); if (oldShape != newShape) { resizeStore(oldShape, newShape); setShapeImpl(newShape); assert checkExtensionArrayInvariants(newShape); } }
/** @since 0.17 or earlier */ public final void setShapeAndResize(Shape newShape) { setShapeAndResize(getShape(), newShape); }
@Override @TruffleBoundary public boolean changeFlags(Object id, int newFlags) { Shape oldShape = getShape(); Property existing = oldShape.getProperty(id); if (existing != null) { if (existing.getFlags() != newFlags) { Property newProperty = existing.copyWithFlags(newFlags); Shape newShape = oldShape.replaceProperty(existing, newProperty); this.setShape(newShape); } return true; } else { return false; } }
public String debugDump(int level, int levelStop) { List<Property> properties = this.getShape().getPropertyListInternal(true); StringBuilder sb = new StringBuilder(properties.size() * 10); sb.append("{\n"); for (Property property : properties) { indent(sb, level + 1); sb.append(property.getKey()); sb.append('[').append(property.getLocation()).append(']'); Object value = property.get(this, false); if (value instanceof DynamicObjectImpl) { if (level < levelStop) { value = ((DynamicObjectImpl) value).debugDump(level + 1, levelStop); } else { value = value.toString(); } } sb.append(": "); sb.append(value); if (property != properties.get(properties.size() - 1)) { sb.append(","); } sb.append("\n"); } indent(sb, level); sb.append("}"); return sb.toString(); }
@Override @TruffleBoundary public void define(Object id, Object value, int flags, LocationFactory locationFactory) { ShapeImpl oldShape = getShape(); Property existing = oldShape.getProperty(id); if (existing == null) { updateShape(); oldShape = getShape(); Shape newShape = oldShape.addProperty(Property.create(id, locationFactory.createLocation(oldShape, value), flags)); updateShape(); newShape.getLastProperty().setGeneric(this, value, oldShape, newShape); } else { defineExisting(id, value, flags, existing, oldShape); } }
@Override protected final DynamicObject cloneWithShape(Shape currentShape) { assert this.getShape() == currentShape; final DynamicObjectBasic clone = (DynamicObjectBasic) super.clone(); if (this.getObjectStore(currentShape) != null) { clone.setObjectStore(this.getObjectStore(currentShape).clone(), currentShape); } if (((ShapeImpl) currentShape).hasPrimitiveArray() && this.getPrimitiveStore(currentShape) != null) { clone.setPrimitiveStore(this.getPrimitiveStore(currentShape).clone(), currentShape); } return clone; }
@Override @TruffleBoundary public boolean delete(Object id) { ShapeImpl oldShape = getShape(); Property existing = oldShape.getProperty(id); if (existing != null) { ShapeImpl newShape = oldShape.removeProperty(existing); this.reshapeAfterDelete(newShape, ShapeImpl.findCommonAncestor(oldShape, newShape)); // TODO ancestor should be the parent of found property's shape return true; } else { return false; } }
/** @since 0.17 or earlier */ @TruffleBoundary public boolean changeFlags(Object key, int newFlags) { Shape oldShape = getShape(); Property existing = oldShape.getProperty(key); if (existing != null) { if (existing.getFlags() != newFlags) { Property newProperty = existing.copyWithFlags(newFlags); Shape newShape = oldShape.replaceProperty(existing, newProperty); setShapeImpl(newShape); } return true; } else { return false; } }
/** @since 0.17 or earlier */ @Override public final DynamicObject copy(Shape currentShape) { return cloneWithShape(currentShape); }
/** * @param ancestor common ancestor shape between from and to object shapes * @since 0.17 or earlier */ public final void copyProperties(DynamicObject fromObject, Shape ancestor) { copyProperties(fromObject); }
/** * Check whether fast transition is valid. * * @see #setShapeAndGrow */ private boolean checkSetShape(Shape oldShape, Shape newShape) { Shape currentShape = getShape(); assert oldShape != newShape : "Wrong old shape assumption?"; assert newShape != currentShape : "Redundant shape change? shape=" + currentShape; return true; }