Class ShapeImpl

java.lang.Object
com.oracle.truffle.api.object.Shape
com.oracle.truffle.object.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:
  • Field Details

    • layout

      protected final LayoutImpl layout
    • objectType

      protected final ObjectType objectType
    • parent

      protected final ShapeImpl parent
    • propertyMap

      protected final PropertyMap propertyMap
    • 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
    • ALL

      public static final Shape.Pred<Property> ALL
      Match all filter.
    • propertyListAllocCount

      protected static final DebugCounter propertyListAllocCount
    • propertyListShareCount

      protected static final DebugCounter propertyListShareCount
  • Constructor Details

  • Method Details

    • createShape

      protected abstract ShapeImpl createShape(Layout layout, Object sharedData, ShapeImpl parent, ObjectType operations, PropertyMap propertyMap, Transition transition, Shape.Allocator allocator, int id)
    • 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
    • getObjectArraySize

      public final int getObjectArraySize()
      Specified by:
      getObjectArraySize in class Shape
    • getObjectFieldSize

      public final int getObjectFieldSize()
      Specified by:
      getObjectFieldSize in class Shape
    • getPrimitiveFieldSize

      public final int getPrimitiveFieldSize()
      Specified by:
      getPrimitiveFieldSize in class Shape
    • getObjectArrayCapacity

      public final int getObjectArrayCapacity()
      Specified by:
      getObjectArrayCapacity in class Shape
    • getPrimitiveArrayCapacity

      public final int getPrimitiveArrayCapacity()
      Specified by:
      getPrimitiveArrayCapacity in class Shape
    • getPrimitiveArraySize

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

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

      public final ShapeImpl getShapeFromProperty(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(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 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, 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 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 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 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 List<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 List<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 Iterable<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 String toString()
      Overrides:
      toString in class Object
    • toStringLimit

      public 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(Object name)
      Description copied from class: Shape
      Check whether the shape has a property with the given key.
      Specified by:
      hasProperty in class Shape
    • removeProperty

      public final ShapeImpl removeProperty(Property prop)
      Description copied from class: Shape
      Remove the given property from the shape.
      Specified by:
      removeProperty 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)
    • allocator

      public final ShapeImpl.BaseAllocator allocator()
      Description copied from class: Shape
      Obtain an Shape.Allocator instance for the purpose of allocating locations.
      Specified by:
      allocator in class Shape
    • replaceProperty

      public final ShapeImpl replaceProperty(Property oldProperty, Property newProperty)
      Duplicate shape exchanging existing property with new property.
      Specified by:
      replaceProperty in class Shape
    • 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
    • diff

      public static List<Property> diff(Shape oldShape, Shape newShape)
      Find difference between two shapes.
      See Also:
    • getObjectType

      public ObjectType getObjectType()
      Description copied from class: Shape
      Get the shape's operations.
      Specified by:
      getObjectType 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 Object getData()
      Description copied from class: Shape
      Get the shape's custom data.
      Specified by:
      getData in class Shape
    • getSharedData

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

      public final boolean hasTransitionWithKey(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(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
    • reservePrimitiveExtensionArray

      public final ShapeImpl reservePrimitiveExtensionArray()
      Description copied from class: Shape
      Reserve the primitive extension array field.
      Specified by:
      reservePrimitiveExtensionArray in class Shape
    • getProperties

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

      public final DynamicObject newInstance()
      Description copied from class: Shape
      Create a new DynamicObject instance with this shape.
      Specified by:
      newInstance in class Shape
    • createFactory

      public final DynamicObjectFactory createFactory()
      Description copied from class: Shape
      Create a DynamicObjectFactory for creating instances of this shape.
      Specified by:
      createFactory in class Shape
    • getMutex

      public 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
    • tryMerge

      public Shape tryMerge(Shape other)
      Specified by:
      tryMerge in class Shape