com.oracle.truffle.object

## 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:
  `DynamicObject`, `Property`, `Locations`

### Nested Class Summary

Nested Classes
`static class` `ShapeImpl.BaseAllocator`

### Nested classes/interfaces inherited from class com.oracle.truffle.api.object.Shape

`Shape.Allocator, Shape.Pred<T>`

### Field Summary

Fields
`static Shape.Pred<Property>` `ALL` Match all filter.
`protected int` `depth`
`protected boolean` `hasPrimitiveArray`
`protected LayoutImpl` `layout`
`protected Assumption` `leafAssumption`
`protected int` `objectArrayCapacity`
`protected int` `objectArraySize`
`protected int` `objectFieldSize`
`protected ObjectType` `objectType`
`protected ShapeImpl` `parent`
`protected int` `primitiveArrayCapacity`
`protected int` `primitiveArraySize`
`protected int` `primitiveFieldSize`
`protected Property[]` `propertyArray`
`protected int` `propertyCount`
`protected static DebugCounter` `propertyListAllocCount`
`protected static DebugCounter` `propertyListShareCount`
`protected PropertyMap` `propertyMap`
`protected Assumption` `validAssumption`

### Constructor Summary

Constructors
`protected` `ShapeImpl(Layout layout, ObjectType operations, java.lang.Object sharedData, int id)`
`protected` `ShapeImpl(Layout layout, ShapeImpl parent, ObjectType operations, java.lang.Object sharedData, PropertyMap propertyMap, Transition transition, Shape.Allocator allocator, int id)`

### Method Summary

Methods
`protected void` `addDirectTransition(Transition transition, ShapeImpl next)`
`void` `addIndirectTransition(Transition transition, ShapeImpl next)`
`ShapeImpl` `addProperty(Property property)` Add a new property in the map, yielding a new or cached Shape object.
`ShapeImpl.BaseAllocator` `allocator()` Obtain an `Shape.Allocator` instance for the purpose of allocating locations.
`ShapeImpl` `append(Property oldProperty)` Append the property, relocating it to the next allocated location.
`ShapeImpl` `applyTransition(Transition transition, boolean append)`
`ShapeImpl` `changeType(ObjectType newOps)` Change the shape's type, yielding a new shape.
`boolean` `check(DynamicObject subject)` Check whether this shape is identical to the given shape.
`protected ShapeImpl` `cloneOnto(ShapeImpl newParent)` Create a separate clone of a shape.
`protected ShapeImpl` `cloneRoot(ShapeImpl from, java.lang.Object newSharedData)`
`ShapeImpl` `copyOverPropertiesInternal(Shape destination)` For copying over properties after exchanging the prototype of an object.
`DynamicObjectFactory` `createFactory()` Create a `DynamicObjectFactory` for creating instances of this shape.
`ShapeImpl` `createSeparateShape(java.lang.Object newSharedData)` Clone off a separate shape with new shared data.
`protected abstract ShapeImpl` `createShape(Layout layout, java.lang.Object sharedData, ShapeImpl parent, ObjectType operations, PropertyMap propertyMap, Transition transition, Shape.Allocator allocator, int id)`
`static java.util.List<Property>` `diff(Shape oldShape, Shape newShape)` Find difference between two shapes.
`static ShapeImpl` `findCommonAncestor(ShapeImpl left, ShapeImpl right)` Find lowest common ancestor of two related shapes.
`java.lang.Object` `getData()` Get the shape's custom data.
`int` `getDepth()`
`int` `getId()`
`java.util.List<java.lang.Object>` `getKeyList()` Get a list of all property keys in insertion order.
`java.util.List<java.lang.Object>` `getKeyList(Shape.Pred<Property> filter)` Get a list of all (visible) property names in insertion order.
`java.lang.Iterable<java.lang.Object>` `getKeys()` Get all property keys in insertion order.
`Property` `getLastProperty()` Get the last added property.
`LayoutImpl` `getLayout()` Get the shape's layout.
`Assumption` `getLeafAssumption()` Get an assumption that the shape is a leaf.
`java.lang.Object` `getMutex()` Get mutex object shared by related shapes, i.e.
`int` `getObjectArrayCapacity()`
`int` `getObjectArraySize()`
`int` `getObjectFieldSize()`
`ObjectType` `getObjectType()` Get the shape's operations.
`ShapeImpl` `getParent()`
`int` `getPrimitiveArrayCapacity()`
`int` `getPrimitiveArraySize()`
`int` `getPrimitiveFieldSize()`
`java.lang.Iterable<Property>` `getProperties()` An `Iterable` over the shape's properties in insertion order.
`Property` `getProperty(java.lang.Object key)` Get a property entry by string name.
`int` `getPropertyCount()` Get number of properties in this shape.
`java.util.List<Property>` `getPropertyList()` Get a list of all properties that this Shape stores.
`java.util.List<Property>` `getPropertyList(Shape.Pred<Property> filter)` Get a list of all properties that this Shape stores.
`java.util.List<Property>` `getPropertyListInternal(boolean ascending)` Returns all (also hidden) Property objects in this shape.
`PropertyMap` `getPropertyMap()`
`ShapeImpl` `getRoot()` Get the root shape.
`ShapeImpl` `getShapeFromProperty(java.lang.Object propertyName)` Get the (parent) shape that holds the given property.
`ShapeImpl` `getShapeFromProperty(Property prop)` Get the (parent) shape that holds the given property.
`java.lang.Object` `getSharedData()` Get the shape's shared data.
`Transition` `getTransitionFromParent()`
`java.util.Map<Transition,ShapeImpl>` `getTransitionMapForRead()`
`Assumption` `getValidAssumption()` Get an assumption that the shape is valid.
`boolean` `hasPrimitiveArray()`
`boolean` `hasProperty(java.lang.Object name)` Check whether the shape has a property with the given key.
`boolean` `hasTransitionWithKey(java.lang.Object key)` Query whether the shape has a transition with the given key.
`void` `invalidateValidAssumption()`
`boolean` `isLeaf()` Check whether this shape is a leaf in the transition graph, i.e.
`boolean` `isRelated(Shape other)` Are these two shapes related, i.e.
`boolean` `isValid()` Check whether this shape is valid.
`DynamicObject` `newInstance()` Create a new `DynamicObject` instance with this shape.
`ShapeImpl` `removeProperty(Property prop)` Remove the given property from the shape.
`ShapeImpl` `replaceProperty(Property oldProperty, Property newProperty)` Duplicate shape exchanging existing property with new property.
`ShapeImpl` `reservePrimitiveExtensionArray()` Reserve the primitive extension array field.
`java.lang.String` `toString()`
`java.lang.String` `toStringLimit(int limit)`
`Shape` `tryMerge(Shape other)`

### Methods inherited from class com.oracle.truffle.api.object.Shape

`accept`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### 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 Detail

#### ShapeImpl

    protected ShapeImpl(Layout layout,
             ShapeImpl parent,
             ObjectType operations,
             java.lang.Object sharedData,
             PropertyMap propertyMap,
             Transition transition,
             Shape.Allocator allocator,
             int id)

#### ShapeImpl

    protected ShapeImpl(Layout layout,
             ObjectType operations,
             java.lang.Object sharedData,
             int id)

### Method Detail

#### createShape

    protected abstract ShapeImpl createShape(Layout layout,
                        java.lang.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(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`

#### 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 java.util.List<Property> diff(Shape oldShape,
                                Shape newShape)

Find difference between two shapes.

See Also:
  `ObjectStorageOptions.TraceReshape`

#### 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 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`

#### 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 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`

#### 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 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`

#### tryMerge

    public Shape tryMerge(Shape other)

Specified by:
  `tryMerge` in class `Shape`