Package 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 Modifier and Type Class Description static classShapeImpl.BaseAllocator-
Nested classes/interfaces inherited from class com.oracle.truffle.api.object.Shape
Shape.Allocator, Shape.Pred<T>
-
-
Field Summary
Fields Modifier and Type Field Description static Shape.Pred<Property>ALLMatch all filter.protected intdepthprotected booleanhasPrimitiveArrayprotected LayoutImpllayoutprotected AssumptionleafAssumptionprotected intobjectArrayCapacityprotected intobjectArraySizeprotected intobjectFieldSizeprotected ObjectTypeobjectTypeprotected ShapeImplparentprotected intprimitiveArrayCapacityprotected intprimitiveArraySizeprotected intprimitiveFieldSizeprotected Property[]propertyArrayprotected intpropertyCountprotected static DebugCounterpropertyListAllocCountprotected static DebugCounterpropertyListShareCountprotected PropertyMappropertyMapprotected AssumptionvalidAssumption
-
Constructor Summary
Constructors Modifier Constructor Description protectedShapeImpl(Layout layout, ObjectType operations, java.lang.Object sharedData, int id)protectedShapeImpl(Layout layout, ShapeImpl parent, ObjectType operations, java.lang.Object sharedData, PropertyMap propertyMap, Transition transition, Shape.Allocator allocator, int id)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddDirectTransition(Transition transition, ShapeImpl next)voidaddIndirectTransition(Transition transition, ShapeImpl next)ShapeImpladdProperty(Property property)Add a new property in the map, yielding a new or cached Shape object.ShapeImpl.BaseAllocatorallocator()Obtain anShape.Allocatorinstance for the purpose of allocating locations.ShapeImplappend(Property oldProperty)Append the property, relocating it to the next allocated location.ShapeImplapplyTransition(Transition transition, boolean append)ShapeImplchangeType(ObjectType newOps)Change the shape's type, yielding a new shape.booleancheck(DynamicObject subject)Check whether this shape is identical to the given shape.protected ShapeImplcloneOnto(ShapeImpl newParent)Create a separate clone of a shape.protected ShapeImplcloneRoot(ShapeImpl from, java.lang.Object newSharedData)ShapeImplcopyOverPropertiesInternal(Shape destination)For copying over properties after exchanging the prototype of an object.DynamicObjectFactorycreateFactory()Create aDynamicObjectFactoryfor creating instances of this shape.ShapeImplcreateSeparateShape(java.lang.Object newSharedData)Clone off a separate shape with new shared data.protected abstract ShapeImplcreateShape(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 ShapeImplfindCommonAncestor(ShapeImpl left, ShapeImpl right)Find lowest common ancestor of two related shapes.java.lang.ObjectgetData()Get the shape's custom data.intgetDepth()intgetId()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.PropertygetLastProperty()Get the last added property.LayoutImplgetLayout()Get the shape's layout.AssumptiongetLeafAssumption()Get an assumption that the shape is a leaf.java.lang.ObjectgetMutex()Get mutex object shared by related shapes, i.e.intgetObjectArrayCapacity()intgetObjectArraySize()intgetObjectFieldSize()ObjectTypegetObjectType()Get the shape's operations.ShapeImplgetParent()intgetPrimitiveArrayCapacity()intgetPrimitiveArraySize()intgetPrimitiveFieldSize()java.lang.Iterable<Property>getProperties()AnIterableover the shape's properties in insertion order.PropertygetProperty(java.lang.Object key)Get a property entry by string name.intgetPropertyCount()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.PropertyMapgetPropertyMap()ShapeImplgetRoot()Get the root shape.ShapeImplgetShapeFromProperty(Property prop)Get the (parent) shape that holds the given property.ShapeImplgetShapeFromProperty(java.lang.Object propertyName)Get the (parent) shape that holds the given property.java.lang.ObjectgetSharedData()Get the shape's shared data.TransitiongetTransitionFromParent()java.util.Map<Transition,ShapeImpl>getTransitionMapForRead()AssumptiongetValidAssumption()Get an assumption that the shape is valid.booleanhasPrimitiveArray()booleanhasProperty(java.lang.Object name)Check whether the shape has a property with the given key.booleanhasTransitionWithKey(java.lang.Object key)Query whether the shape has a transition with the given key.voidinvalidateValidAssumption()booleanisLeaf()Check whether this shape is a leaf in the transition graph, i.e.booleanisRelated(Shape other)Are these two shapes related, i.e.booleanisValid()Check whether this shape is valid.DynamicObjectnewInstance()Create a newDynamicObjectinstance with this shape.ShapeImplremoveProperty(Property prop)Remove the given property from the shape.ShapeImplreplaceProperty(Property oldProperty, Property newProperty)Duplicate shape exchanging existing property with new property.ShapeImplreservePrimitiveExtensionArray()Reserve the primitive extension array field.java.lang.StringtoString()java.lang.StringtoStringLimit(int limit)ShapetryMerge(Shape other)
-
-
-
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:ShapeGet the last added property.- Specified by:
getLastPropertyin classShape
-
getObjectArraySize
public final int getObjectArraySize()
- Specified by:
getObjectArraySizein classShape
-
getObjectFieldSize
public final int getObjectFieldSize()
- Specified by:
getObjectFieldSizein classShape
-
getPrimitiveFieldSize
public final int getPrimitiveFieldSize()
- Specified by:
getPrimitiveFieldSizein classShape
-
getObjectArrayCapacity
public final int getObjectArrayCapacity()
- Specified by:
getObjectArrayCapacityin classShape
-
getPrimitiveArrayCapacity
public final int getPrimitiveArrayCapacity()
- Specified by:
getPrimitiveArrayCapacityin classShape
-
getPrimitiveArraySize
public final int getPrimitiveArraySize()
- Specified by:
getPrimitiveArraySizein classShape
-
hasPrimitiveArray
public final boolean hasPrimitiveArray()
- Specified by:
hasPrimitiveArrayin classShape
-
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:
getPropertyin classShape- 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:
addPropertyin classShape- Parameters:
property- the property to add- Returns:
- the new Shape
-
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?
-
getPropertyList
public final java.util.List<Property> getPropertyList(Shape.Pred<Property> filter)
Get a list of all properties that this Shape stores.- Specified by:
getPropertyListin classShape- Returns:
- list of properties
-
getPropertyList
public final java.util.List<Property> getPropertyList()
Description copied from class:ShapeGet a list of all properties that this Shape stores.- Specified by:
getPropertyListin classShape- 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:
getPropertyListInternalin classShape- 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:
getKeyListin classShape- Returns:
- list of property names
-
getKeyList
public final java.util.List<java.lang.Object> getKeyList()
Description copied from class:ShapeGet a list of all property keys in insertion order.- Specified by:
getKeyListin classShape
-
getKeys
public java.lang.Iterable<java.lang.Object> getKeys()
Description copied from class:ShapeGet all property keys in insertion order.
-
isValid
public final boolean isValid()
Description copied from class:ShapeCheck whether this shape is valid.
-
getValidAssumption
public final Assumption getValidAssumption()
Description copied from class:ShapeGet an assumption that the shape is valid.- Specified by:
getValidAssumptionin classShape
-
invalidateValidAssumption
public final void invalidateValidAssumption()
-
isLeaf
public final boolean isLeaf()
Description copied from class:ShapeCheck whether this shape is a leaf in the transition graph, i.e. transitionless.
-
getLeafAssumption
public final Assumption getLeafAssumption()
Description copied from class:ShapeGet an assumption that the shape is a leaf.- Specified by:
getLeafAssumptionin classShape
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toStringLimit
public java.lang.String toStringLimit(int limit)
-
getParent
public final ShapeImpl getParent()
-
getDepth
public final int getDepth()
-
hasProperty
public final boolean hasProperty(java.lang.Object name)
Description copied from class:ShapeCheck whether the shape has a property with the given key.- Specified by:
hasPropertyin classShape
-
removeProperty
public final ShapeImpl removeProperty(Property prop)
Description copied from class:ShapeRemove the given property from the shape.- Specified by:
removePropertyin classShape
-
append
public final ShapeImpl append(Property oldProperty)
Description copied from class:ShapeAppend the property, relocating it to the next allocated location.
-
applyTransition
public final ShapeImpl applyTransition(Transition transition, boolean append)
-
allocator
public final ShapeImpl.BaseAllocator allocator()
Description copied from class:ShapeObtain anShape.Allocatorinstance for the purpose of allocating locations.
-
replaceProperty
public final ShapeImpl replaceProperty(Property oldProperty, Property newProperty)
Duplicate shape exchanging existing property with new property.- Specified by:
replacePropertyin classShape
-
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:
copyOverPropertiesInternalin classShape
-
getPropertyCount
public final int getPropertyCount()
Description copied from class:ShapeGet number of properties in this shape.- Specified by:
getPropertyCountin classShape
-
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:ShapeGet the shape's operations.- Specified by:
getObjectTypein classShape
-
check
public final boolean check(DynamicObject subject)
Description copied from class:ShapeCheck whether this shape is identical to the given shape.
-
getLayout
public final LayoutImpl getLayout()
Description copied from class:ShapeGet the shape's layout.
-
getData
public final java.lang.Object getData()
Description copied from class:ShapeGet the shape's custom data.
-
getSharedData
public final java.lang.Object getSharedData()
Description copied from class:ShapeGet the shape's shared data.- Specified by:
getSharedDatain classShape
-
hasTransitionWithKey
public final boolean hasTransitionWithKey(java.lang.Object key)
Description copied from class:ShapeQuery whether the shape has a transition with the given key.- Specified by:
hasTransitionWithKeyin classShape
-
createSeparateShape
public final ShapeImpl createSeparateShape(java.lang.Object newSharedData)
Clone off a separate shape with new shared data.- Specified by:
createSeparateShapein classShape
-
changeType
public final ShapeImpl changeType(ObjectType newOps)
Description copied from class:ShapeChange the shape's type, yielding a new shape.- Specified by:
changeTypein classShape
-
reservePrimitiveExtensionArray
public final ShapeImpl reservePrimitiveExtensionArray()
Description copied from class:ShapeReserve the primitive extension array field.- Specified by:
reservePrimitiveExtensionArrayin classShape
-
getProperties
public final java.lang.Iterable<Property> getProperties()
Description copied from class:ShapeAnIterableover the shape's properties in insertion order.- Specified by:
getPropertiesin classShape
-
newInstance
public final DynamicObject newInstance()
Description copied from class:ShapeCreate a newDynamicObjectinstance with this shape.- Specified by:
newInstancein classShape
-
createFactory
public final DynamicObjectFactory createFactory()
Description copied from class:ShapeCreate aDynamicObjectFactoryfor creating instances of this shape.- Specified by:
createFactoryin classShape
-
getMutex
public java.lang.Object getMutex()
Description copied from class:ShapeGet mutex object shared by related shapes, i.e. shapes with a common root.
-
-