public static final class Shape.Builder extends Object
Shape
instances.
The builder instance is not thread-safe and must not be used from multiple threads at the
same time.Shape.newBuilder()
Modifier and Type | Method and Description |
---|---|
Shape.Builder |
addConstantProperty(Object key,
Object value,
int flags)
Adds a property with a constant value to the shape.
|
Shape.Builder |
allowImplicitCastIntToDouble(boolean allow)
Allows values to be implicitly cast from int to double in this shape and any derived
shapes.
|
Shape.Builder |
allowImplicitCastIntToLong(boolean allow)
Allows values to be implicitly cast from int to long in this shape and any derived
shapes.
|
Shape |
build()
Builds a new shape using the configuration of this builder.
|
Shape.Builder |
dynamicType(Object dynamicType)
Sets initial dynamic object type identifier.
|
Shape.Builder |
layout(Class<? extends DynamicObject> layoutClass)
Sets custom object layout class (default:
DynamicObject base class). |
Shape.Builder |
propertyAssumptions(boolean enable)
If
true , enables the use of property assumptions for this object shape and any derived shapes (default:
false ). |
Shape.Builder |
shapeFlags(int flags)
Sets initial shape flags (default: 0).
|
Shape.Builder |
shared(boolean isShared)
If
true , makes the object shared (default: false ). |
Shape.Builder |
sharedData(Object sharedData)
Sets shared data to be associated with the root shape and any derived shapes (e.g.
|
Shape.Builder |
singleContextAssumption(Assumption assumption)
Sets an assumption that allows specializations on constant object instances with this
shape, as long as the assumption is valid.
|
public Shape.Builder layout(Class<? extends DynamicObject> layoutClass)
DynamicObject
base class).
Enables the use of dynamic object fields declared in subclasses using the
DynamicField
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);
layoutClass
- custom object layout classpublic Shape.Builder dynamicType(Object dynamicType)
DynamicObjectLibrary.setDynamicType(DynamicObject, Object)
for more
information.dynamicType
- a non-null object type identifierNullPointerException
- if the type is null
IllegalArgumentException
DynamicObjectLibrary.getDynamicType(DynamicObject)
,
DynamicObjectLibrary.setDynamicType(DynamicObject, Object)
public Shape.Builder shapeFlags(int flags)
DynamicObjectLibrary.setShapeFlags(DynamicObject, int)
for more information.flags
- an int value in the range from 0 to 255 (inclusive)IllegalArgumentException
- if the flags value is not in the supported rangeDynamicObjectLibrary.getShapeFlags(DynamicObject)
,
DynamicObjectLibrary.setShapeFlags(DynamicObject, int)
public Shape.Builder shared(boolean isShared)
true
, makes the object shared (default: false
).Shape.isShared()
,
DynamicObjectLibrary.isShared(DynamicObject)
,
DynamicObjectLibrary.markShared(DynamicObject)
public Shape.Builder propertyAssumptions(boolean enable)
true
, 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.
Shape.getPropertyAssumption(Object)
public Shape.Builder sharedData(Object sharedData)
TruffleLanguage
instance). May be null (the default).Shape.getSharedData()
public Shape.Builder singleContextAssumption(Assumption assumption)
null
in which case this feature is disabled (the default).Shape.Builder.propertyAssumptions(boolean)
public Shape.Builder addConstantProperty(Object key, Object value, int flags)
null
and
must not be equal to any previously added property's key.key
- the property's keyvalue
- the property's valueflags
- the property's flagsNullPointerException
- if the key is null
IllegalArgumentException
- if a property with the key already existsDynamicObjectLibrary.putConstant(DynamicObject, Object, Object, int)
public Shape.Builder allowImplicitCastIntToLong(boolean allow)
Shape.Builder.layout(Class)
public Shape.Builder allowImplicitCastIntToDouble(boolean allow)
Shape.Builder.layout(Class)
public Shape build()