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 class
ShapeImpl.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>
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 Modifier Constructor Description 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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 anShape.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 aDynamicObjectFactory
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()
AnIterable
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(Property prop)
Get the (parent) shape that holds the given property.ShapeImpl
getShapeFromProperty(java.lang.Object propertyName)
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 newDynamicObject
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)
-
-
-
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 classShape
-
getObjectArraySize
public final int getObjectArraySize()
- Specified by:
getObjectArraySize
in classShape
-
getObjectFieldSize
public final int getObjectFieldSize()
- Specified by:
getObjectFieldSize
in classShape
-
getPrimitiveFieldSize
public final int getPrimitiveFieldSize()
- Specified by:
getPrimitiveFieldSize
in classShape
-
getObjectArrayCapacity
public final int getObjectArrayCapacity()
- Specified by:
getObjectArrayCapacity
in classShape
-
getPrimitiveArrayCapacity
public final int getPrimitiveArrayCapacity()
- Specified by:
getPrimitiveArrayCapacity
in classShape
-
getPrimitiveArraySize
public final int getPrimitiveArraySize()
- Specified by:
getPrimitiveArraySize
in classShape
-
hasPrimitiveArray
public final boolean hasPrimitiveArray()
- Specified by:
hasPrimitiveArray
in 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:
getProperty
in 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:
addProperty
in 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:
getPropertyList
in classShape
- 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 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:
getPropertyListInternal
in 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:
getKeyList
in classShape
- 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 classShape
-
getKeys
public java.lang.Iterable<java.lang.Object> getKeys()
Description copied from class:Shape
Get all property keys in insertion order.
-
isValid
public final boolean isValid()
Description copied from class:Shape
Check whether this shape is valid.
-
getValidAssumption
public final Assumption getValidAssumption()
Description copied from class:Shape
Get an assumption that the shape is valid.- Specified by:
getValidAssumption
in classShape
-
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.
-
getLeafAssumption
public final Assumption getLeafAssumption()
Description copied from class:Shape
Get an assumption that the shape is a leaf.- Specified by:
getLeafAssumption
in classShape
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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:Shape
Check whether the shape has a property with the given key.- Specified by:
hasProperty
in classShape
-
removeProperty
public final ShapeImpl removeProperty(Property prop)
Description copied from class:Shape
Remove the given property from the shape.- Specified by:
removeProperty
in classShape
-
append
public final ShapeImpl append(Property oldProperty)
Description copied from class:Shape
Append 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:Shape
Obtain anShape.Allocator
instance 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:
replaceProperty
in 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:
copyOverPropertiesInternal
in classShape
-
getPropertyCount
public final int getPropertyCount()
Description copied from class:Shape
Get number of properties in this shape.- Specified by:
getPropertyCount
in 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:Shape
Get the shape's operations.- Specified by:
getObjectType
in classShape
-
check
public final boolean check(DynamicObject subject)
Description copied from class:Shape
Check whether this shape is identical to the given shape.
-
getLayout
public final LayoutImpl getLayout()
Description copied from class:Shape
Get the shape's layout.
-
getData
public final java.lang.Object getData()
Description copied from class:Shape
Get the shape's custom data.
-
getSharedData
public final java.lang.Object getSharedData()
Description copied from class:Shape
Get the shape's shared data.- Specified by:
getSharedData
in classShape
-
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 classShape
-
createSeparateShape
public final ShapeImpl createSeparateShape(java.lang.Object newSharedData)
Clone off a separate shape with new shared data.- Specified by:
createSeparateShape
in classShape
-
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 classShape
-
reservePrimitiveExtensionArray
public final ShapeImpl reservePrimitiveExtensionArray()
Description copied from class:Shape
Reserve the primitive extension array field.- Specified by:
reservePrimitiveExtensionArray
in classShape
-
getProperties
public final java.lang.Iterable<Property> getProperties()
Description copied from class:Shape
AnIterable
over the shape's properties in insertion order.- Specified by:
getProperties
in classShape
-
newInstance
public final DynamicObject newInstance()
Description copied from class:Shape
Create a newDynamicObject
instance with this shape.- Specified by:
newInstance
in classShape
-
createFactory
public final DynamicObjectFactory createFactory()
Description copied from class:Shape
Create aDynamicObjectFactory
for creating instances of this shape.- Specified by:
createFactory
in classShape
-
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.
-
-