Package com.oracle.truffle.api.object
Class Shape.Builder
java.lang.Object
com.oracle.truffle.api.object.Shape.Builder
- Enclosing class:
Shape
Builder class to construct initial
Shape
instances.
The builder instance is not thread-safe and must not be used from multiple threads at the
same time.- Since:
- 20.2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddConstantProperty
(Object key, Object value, int flags) Adds a property with a constant value to the shape.allowImplicitCastIntToDouble
(boolean allow) Allows values to be implicitly cast from int to double in this shape and any derived shapes.allowImplicitCastIntToLong
(boolean allow) Allows values to be implicitly cast from int to long in this shape and any derived shapes.build()
Builds a new shape using the configuration of this builder.dynamicType
(Object dynamicType) Sets initial dynamic object type identifier.layout
(Class<? extends DynamicObject> layoutClass) Sets custom object layout class (default:DynamicObject
base class).propertyAssumptions
(boolean enable) Iftrue
, enables the use of property assumptions for this object shape and any derived shapes (default:false
).shapeFlags
(int flags) Sets initial shape flags (default: 0).shared
(boolean isShared) Iftrue
, makes the object shared (default:false
).sharedData
(Object sharedData) Sets shared data to be associated with the root shape and any derived shapes (e.g.singleContextAssumption
(Assumption assumption) Sets an assumption that allows specializations on constant object instances with this shape, as long as the assumption is valid.
-
Method Details
-
layout
Sets custom object layout class (default:DynamicObject
base class). Enables the use of dynamic object fields declared in subclasses using theDynamicField
annotation.Examples:
public class MyObject extends DynamicObject implements TruffleObject { @DynamicField private Object _obj1; @DynamicField private Object _obj2; @DynamicField private long _long1; @DynamicField private long _long2; public MyObject(Shape shape) { super(shape); } } Shape myObjShape = Shape.newBuilder().layout(MyObject.class).build(); MyObject obj = new MyObject(myObjShape);
- Parameters:
layoutClass
- custom object layout class- Since:
- 20.2.0
-
dynamicType
Sets initial dynamic object type identifier. SeeDynamicObjectLibrary.setDynamicType(DynamicObject, Object)
for more information.- Parameters:
dynamicType
- a non-null object type identifier- Throws:
NullPointerException
- if the type isnull
- Since:
- 20.2.0
- See Also:
-
shapeFlags
Sets initial shape flags (default: 0). Currently limited to 16 bits. SeeDynamicObjectLibrary.setShapeFlags(DynamicObject, int)
for more information.- Parameters:
flags
- an int value in the range from 0 to 65535 (inclusive)- Throws:
IllegalArgumentException
- if the flags value is not in the supported range- Since:
- 20.2.0
- See Also:
-
propertyAssumptions
Iftrue
, enables the use of property assumptions for this object shape and any derived shapes (default:false
). Property assumptions allow speculating on select properties being absent or stable across shape changes.Use of property assumptions can be beneficial in single-context mode for long-lived objects with stable properties but recurrent shape changes due to properties being added (e.g. global objects of a context), in which case a shape cache would be unstable while the property assumption allows for a stable cache.
- Since:
- 20.2.0
- See Also:
-
singleContextAssumption
Sets an assumption that allows specializations on constant object instances with this shape, as long as the assumption is valid. The assumption should be valid only if code is not shared across contexts and invalidated when this is not longer true. The assumption may benull
in which case this feature is disabled (the default).- Since:
- 20.2.0
- See Also:
-
addConstantProperty
Adds a property with a constant value to the shape. The key must not benull
and must not be equal to any previously added property's key.- Parameters:
key
- the property's keyvalue
- the property's valueflags
- the property's flags- Throws:
NullPointerException
- if the key isnull
IllegalArgumentException
- if a property with the key already exists- Since:
- 20.2.0
- See Also:
-
allowImplicitCastIntToLong
Allows values to be implicitly cast from int to long in this shape and any derived shapes.- Since:
- 20.2.0
- See Also:
-
allowImplicitCastIntToDouble
Allows values to be implicitly cast from int to double in this shape and any derived shapes.- Since:
- 20.2.0
- See Also:
-
build
Builds a new shape using the configuration of this builder.- Since:
- 20.2.0
-