Package com.oracle.truffle.api.object
Class Shape
- java.lang.Object
-
- com.oracle.truffle.api.object.Shape
-
- Direct Known Subclasses:
ShapeImpl
public abstract class Shape extends java.lang.ObjectShape objects create a mapping of Property objects to Locations. 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,Location
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShape.Allocatorstatic interfaceShape.Pred<T>Represents a predicate (boolean-valued function) of one argument.
-
Constructor Summary
Constructors Constructor Description Shape()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <R> Raccept(ShapeVisitor<R> visitor)abstract ShapeaddProperty(Property property)Add a new property in the map, yielding a new or cached Shape object.abstract Shape.Allocatorallocator()Obtain anShape.Allocatorinstance for the purpose of allocating locations.abstract Shapeappend(Property oldProperty)Append the property, relocating it to the next allocated location.abstract ShapechangeType(ObjectType newOps)Change the shape's type, yielding a new shape.abstract booleancheck(DynamicObject subject)Check whether this shape is identical to the given shape.abstract ShapecopyOverPropertiesInternal(Shape destination)For copying over properties after exchanging the prototype of an object.abstract DynamicObjectFactorycreateFactory()Create aDynamicObjectFactoryfor creating instances of this shape.abstract ShapecreateSeparateShape(java.lang.Object sharedData)Clone off a separate shape with new shared data.abstract java.lang.ObjectgetData()Get the shape's custom data.abstract intgetId()abstract java.util.List<java.lang.Object>getKeyList()Get a list of all property keys in insertion order.abstract java.util.List<java.lang.Object>getKeyList(Shape.Pred<Property> filter)Get a filtered list of property keys in insertion order.abstract java.lang.Iterable<java.lang.Object>getKeys()Get all property keys in insertion order.abstract PropertygetLastProperty()Get the last added property.abstract LayoutgetLayout()Get the shape's layout.abstract AssumptiongetLeafAssumption()Get an assumption that the shape is a leaf.abstract java.lang.ObjectgetMutex()Get mutex object shared by related shapes, i.e.abstract intgetObjectArrayCapacity()abstract intgetObjectArraySize()abstract intgetObjectFieldSize()abstract ObjectTypegetObjectType()Get the shape's operations.abstract ShapegetParent()abstract intgetPrimitiveArrayCapacity()abstract intgetPrimitiveArraySize()abstract intgetPrimitiveFieldSize()abstract java.lang.Iterable<Property>getProperties()AnIterableover the shape's properties in insertion order.abstract PropertygetProperty(java.lang.Object key)Get a property entry by key.abstract intgetPropertyCount()Get number of properties in this shape.abstract java.util.List<Property>getPropertyList()Get a list of all properties that this Shape stores.abstract java.util.List<Property>getPropertyList(Shape.Pred<Property> filter)Get a list of properties that this Shape stores.abstract java.util.List<Property>getPropertyListInternal(boolean ascending)Returns all (also hidden) property objects in this shape.abstract ShapegetRoot()Get the root shape.abstract java.lang.ObjectgetSharedData()Get the shape's shared data.abstract AssumptiongetValidAssumption()Get an assumption that the shape is valid.abstract booleanhasPrimitiveArray()abstract booleanhasProperty(java.lang.Object key)Check whether the shape has a property with the given key.abstract booleanhasTransitionWithKey(java.lang.Object key)Query whether the shape has a transition with the given key.abstract booleanisLeaf()Check whether this shape is a leaf in the transition graph, i.e.abstract booleanisRelated(Shape other)Are these two shapes related, i.e.abstract booleanisValid()Check whether this shape is valid.abstract DynamicObjectnewInstance()Create a newDynamicObjectinstance with this shape.abstract ShaperemoveProperty(Property property)Remove the given property from the shape.abstract ShapereplaceProperty(Property oldProperty, Property newProperty)Replace a property in the shape.abstract ShapereservePrimitiveExtensionArray()Reserve the primitive extension array field.abstract ShapetryMerge(Shape other)
-
-
-
Method Detail
-
getProperty
public abstract Property getProperty(java.lang.Object key)
Get a property entry by key.- Parameters:
key- the identifier to look up- Returns:
- a Property object, or null if not found
-
addProperty
public abstract Shape addProperty(Property property)
Add a new property in the map, yielding a new or cached Shape object.- Parameters:
property- the property to add- Returns:
- the new Shape
-
getProperties
public abstract java.lang.Iterable<Property> getProperties()
AnIterableover the shape's properties in insertion order.
-
getPropertyList
public abstract java.util.List<Property> getPropertyList(Shape.Pred<Property> filter)
Get a list of properties that this Shape stores.- Returns:
- list of properties
-
getPropertyList
public abstract java.util.List<Property> getPropertyList()
Get a list of all properties that this Shape stores.- Returns:
- list of properties
-
getPropertyListInternal
public abstract java.util.List<Property> getPropertyListInternal(boolean ascending)
Returns all (also hidden) property objects in this shape.- Parameters:
ascending- desired order (truefor insertion order,falsefor reverse insertion order)
-
getKeyList
public abstract java.util.List<java.lang.Object> getKeyList(Shape.Pred<Property> filter)
Get a filtered list of property keys in insertion order.
-
getKeyList
public abstract java.util.List<java.lang.Object> getKeyList()
Get a list of all property keys in insertion order.
-
getKeys
public abstract java.lang.Iterable<java.lang.Object> getKeys()
Get all property keys in insertion order.
-
getValidAssumption
public abstract Assumption getValidAssumption()
Get an assumption that the shape is valid.
-
isValid
public abstract boolean isValid()
Check whether this shape is valid.
-
getLeafAssumption
public abstract Assumption getLeafAssumption()
Get an assumption that the shape is a leaf.
-
isLeaf
public abstract boolean isLeaf()
Check whether this shape is a leaf in the transition graph, i.e. transitionless.
-
getParent
public abstract Shape getParent()
- Returns:
- the parent shape or
nullif none.
-
hasProperty
public abstract boolean hasProperty(java.lang.Object key)
Check whether the shape has a property with the given key.
-
removeProperty
public abstract Shape removeProperty(Property property)
Remove the given property from the shape.
-
replaceProperty
public abstract Shape replaceProperty(Property oldProperty, Property newProperty)
Replace a property in the shape.
-
getLastProperty
public abstract Property getLastProperty()
Get the last added property.
-
getId
public abstract int getId()
-
append
public abstract Shape append(Property oldProperty)
Append the property, relocating it to the next allocated location.
-
allocator
public abstract Shape.Allocator allocator()
Obtain anShape.Allocatorinstance for the purpose of allocating locations.
-
copyOverPropertiesInternal
public abstract Shape copyOverPropertiesInternal(Shape destination)
For copying over properties after exchanging the prototype of an object.
-
getPropertyCount
public abstract int getPropertyCount()
Get number of properties in this shape.
-
getObjectType
public abstract ObjectType getObjectType()
Get the shape's operations.
-
getRoot
public abstract Shape getRoot()
Get the root shape.
-
check
public abstract boolean check(DynamicObject subject)
Check whether this shape is identical to the given shape.
-
getLayout
public abstract Layout getLayout()
Get the shape's layout.
-
getData
public abstract java.lang.Object getData()
Get the shape's custom data.
-
getSharedData
public abstract java.lang.Object getSharedData()
Get the shape's shared data.
-
hasTransitionWithKey
public abstract boolean hasTransitionWithKey(java.lang.Object key)
Query whether the shape has a transition with the given key.
-
createSeparateShape
public abstract Shape createSeparateShape(java.lang.Object sharedData)
Clone off a separate shape with new shared data.
-
changeType
public abstract Shape changeType(ObjectType newOps)
Change the shape's type, yielding a new shape.
-
reservePrimitiveExtensionArray
public abstract Shape reservePrimitiveExtensionArray()
Reserve the primitive extension array field.
-
newInstance
public abstract DynamicObject newInstance()
Create a newDynamicObjectinstance with this shape.
-
createFactory
public abstract DynamicObjectFactory createFactory()
Create aDynamicObjectFactoryfor creating instances of this shape.
-
getMutex
public abstract java.lang.Object getMutex()
Get mutex object shared by related shapes, i.e. shapes with a common root.
-
getObjectArraySize
public abstract int getObjectArraySize()
-
getObjectFieldSize
public abstract int getObjectFieldSize()
-
getPrimitiveArraySize
public abstract int getPrimitiveArraySize()
-
getPrimitiveFieldSize
public abstract int getPrimitiveFieldSize()
-
getObjectArrayCapacity
public abstract int getObjectArrayCapacity()
-
getPrimitiveArrayCapacity
public abstract int getPrimitiveArrayCapacity()
-
hasPrimitiveArray
public abstract boolean hasPrimitiveArray()
-
isRelated
public abstract boolean isRelated(Shape other)
Are these two shapes related, i.e. do they have the same root?- Parameters:
other- Shape to compare to- Returns:
- true if one shape is an upcast of the other, or the Shapes are equal
-
accept
public <R> R accept(ShapeVisitor<R> visitor)
-
-