Class ShapeImpl

  • Direct Known Subclasses:
    ShapeBasic

    public abstract class ShapeImpl
    extends Shape
    Shape objects create a mapping of Property objects to indexes. The mapping of those indexes to an actual store is not part of Shape's role, but JSObject's. Shapes are immutable; adding or deleting a property yields a new Shape which links to the old one. This allows inline caching to simply check the identity of an object's Shape to determine if the cache is valid. There is one exception to this immutability, the transition map, but that is used simply to assure that an identical series of property additions and deletions will yield the same Shape object.
    See Also:
    DynamicObject, Property, Locations
    • Field Detail

      • objectType

        protected final ObjectType objectType
      • objectArraySize

        protected final int objectArraySize
      • objectArrayCapacity

        protected final int objectArrayCapacity
      • objectFieldSize

        protected final int objectFieldSize
      • primitiveFieldSize

        protected final int primitiveFieldSize
      • primitiveArraySize

        protected final int primitiveArraySize
      • primitiveArrayCapacity

        protected final int primitiveArrayCapacity
      • hasPrimitiveArray

        protected final boolean hasPrimitiveArray
      • depth

        protected final int depth
      • propertyCount

        protected final int propertyCount
      • propertyArray

        protected Property[] propertyArray
      • validAssumption

        protected final Assumption validAssumption
      • leafAssumption

        protected volatile Assumption leafAssumption
      • propertyListAllocCount

        protected static final DebugCounter propertyListAllocCount
      • propertyListShareCount

        protected static final DebugCounter propertyListShareCount
    • Method Detail

      • getLastProperty

        public final Property getLastProperty()
        Description copied from class: Shape
        Get the last added property.
        Specified by:
        getLastProperty in class Shape
      • getId

        public final int getId()
        Specified by:
        getId in class Shape
      • hasPrimitiveArray

        public final boolean hasPrimitiveArray()
        Specified by:
        hasPrimitiveArray in class Shape
      • getShapeFromProperty

        public final ShapeImpl getShapeFromProperty​(java.lang.Object propertyName)
        Get the (parent) shape that holds the given property.
      • getShapeFromProperty

        public final ShapeImpl getShapeFromProperty​(Property prop)
        Get the (parent) shape that holds the given property.
      • getProperty

        public final Property getProperty​(java.lang.Object key)
        Get a property entry by string name.
        Specified by:
        getProperty in class Shape
        Parameters:
        key - the name to look up
        Returns:
        a Property object, or null if not found
      • addDirectTransition

        protected final void addDirectTransition​(Transition transition,
                                                 ShapeImpl next)
      • addIndirectTransition

        public final void addIndirectTransition​(Transition transition,
                                                ShapeImpl next)
      • getTransitionMapForRead

        public final java.util.Map<Transition,​ShapeImpl> getTransitionMapForRead()
      • getPropertyMap

        public final PropertyMap getPropertyMap()
      • addProperty

        public ShapeImpl addProperty​(Property property)
        Add a new property in the map, yielding a new or cached Shape object.
        Specified by:
        addProperty in class Shape
        Parameters:
        property - the property to add
        Returns:
        the new Shape
      • cloneRoot

        protected ShapeImpl cloneRoot​(ShapeImpl from,
                                      java.lang.Object newSharedData)
      • cloneOnto

        protected final ShapeImpl cloneOnto​(ShapeImpl newParent)
        Create a separate clone of a shape.
        Parameters:
        newParent - the cloned parent shape
      • getTransitionFromParent

        public final Transition getTransitionFromParent()
      • isRelated

        public boolean isRelated​(Shape other)
        Are these two shapes related, i.e. do they have the same root?
        Specified by:
        isRelated in class Shape
        Parameters:
        other - Shape to compare to
        Returns:
        true if one shape is an upcast of the other, or the Shapes are equal
      • getPropertyList

        public final java.util.List<Property> getPropertyList​(Shape.Pred<Property> filter)
        Get a list of all properties that this Shape stores.
        Specified by:
        getPropertyList in class Shape
        Returns:
        list of properties
      • getPropertyList

        public final java.util.List<Property> getPropertyList()
        Description copied from class: Shape
        Get a list of all properties that this Shape stores.
        Specified by:
        getPropertyList in class Shape
        Returns:
        list of properties
      • getPropertyListInternal

        public final java.util.List<Property> getPropertyListInternal​(boolean ascending)
        Returns all (also hidden) Property objects in this shape.
        Specified by:
        getPropertyListInternal in class Shape
        Parameters:
        ascending - desired order
      • getKeyList

        public final java.util.List<java.lang.Object> getKeyList​(Shape.Pred<Property> filter)
        Get a list of all (visible) property names in insertion order.
        Specified by:
        getKeyList in class Shape
        Returns:
        list of property names
      • getKeyList

        public final java.util.List<java.lang.Object> getKeyList()
        Description copied from class: Shape
        Get a list of all property keys in insertion order.
        Specified by:
        getKeyList in class Shape
      • getKeys

        public java.lang.Iterable<java.lang.Object> getKeys()
        Description copied from class: Shape
        Get all property keys in insertion order.
        Specified by:
        getKeys in class Shape
      • isValid

        public final boolean isValid()
        Description copied from class: Shape
        Check whether this shape is valid.
        Specified by:
        isValid in class Shape
      • getValidAssumption

        public final Assumption getValidAssumption()
        Description copied from class: Shape
        Get an assumption that the shape is valid.
        Specified by:
        getValidAssumption in class Shape
      • invalidateValidAssumption

        public final void invalidateValidAssumption()
      • isLeaf

        public final boolean isLeaf()
        Description copied from class: Shape
        Check whether this shape is a leaf in the transition graph, i.e. transitionless.
        Specified by:
        isLeaf in class Shape
      • getLeafAssumption

        public final Assumption getLeafAssumption()
        Description copied from class: Shape
        Get an assumption that the shape is a leaf.
        Specified by:
        getLeafAssumption in class Shape
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringLimit

        public java.lang.String toStringLimit​(int limit)
      • getParent

        public final ShapeImpl getParent()
        Specified by:
        getParent in class Shape
        Returns:
        the parent shape or null if none.
      • getDepth

        public final int getDepth()
      • hasProperty

        public final boolean hasProperty​(java.lang.Object name)
        Description copied from class: Shape
        Check whether the shape has a property with the given key.
        Specified by:
        hasProperty in class Shape
      • append

        public final ShapeImpl append​(Property oldProperty)
        Description copied from class: Shape
        Append the property, relocating it to the next allocated location.
        Specified by:
        append in class Shape
      • applyTransition

        public final ShapeImpl applyTransition​(Transition transition,
                                               boolean append)
      • findCommonAncestor

        public static ShapeImpl findCommonAncestor​(ShapeImpl left,
                                                   ShapeImpl right)
        Find lowest common ancestor of two related shapes.
      • copyOverPropertiesInternal

        public final ShapeImpl copyOverPropertiesInternal​(Shape destination)
        For copying over properties after exchanging the prototype of an object.
        Specified by:
        copyOverPropertiesInternal in class Shape
      • getPropertyCount

        public final int getPropertyCount()
        Description copied from class: Shape
        Get number of properties in this shape.
        Specified by:
        getPropertyCount in class Shape
      • getRoot

        public ShapeImpl getRoot()
        Description copied from class: Shape
        Get the root shape.
        Specified by:
        getRoot in class Shape
      • check

        public final boolean check​(DynamicObject subject)
        Description copied from class: Shape
        Check whether this shape is identical to the given shape.
        Specified by:
        check in class Shape
      • getLayout

        public final LayoutImpl getLayout()
        Description copied from class: Shape
        Get the shape's layout.
        Specified by:
        getLayout in class Shape
      • getData

        public final java.lang.Object getData()
        Description copied from class: Shape
        Get the shape's custom data.
        Specified by:
        getData in class Shape
      • getSharedData

        public final java.lang.Object getSharedData()
        Description copied from class: Shape
        Get the shape's shared data.
        Specified by:
        getSharedData in class Shape
      • hasTransitionWithKey

        public final boolean hasTransitionWithKey​(java.lang.Object key)
        Description copied from class: Shape
        Query whether the shape has a transition with the given key.
        Specified by:
        hasTransitionWithKey in class Shape
      • createSeparateShape

        public final ShapeImpl createSeparateShape​(java.lang.Object newSharedData)
        Clone off a separate shape with new shared data.
        Specified by:
        createSeparateShape in class Shape
      • changeType

        public final ShapeImpl changeType​(ObjectType newOps)
        Description copied from class: Shape
        Change the shape's type, yielding a new shape.
        Specified by:
        changeType in class Shape
      • getProperties

        public final java.lang.Iterable<Property> getProperties()
        Description copied from class: Shape
        An Iterable over the shape's properties in insertion order.
        Specified by:
        getProperties in class Shape
      • getMutex

        public java.lang.Object getMutex()
        Description copied from class: Shape
        Get mutex object shared by related shapes, i.e. shapes with a common root.
        Specified by:
        getMutex in class Shape