public abstract class DynamicObject extends Object implements TruffleObject
DynamicObject
and use DynamicObjectLibrary
for object accesses.
When constructing a DynamicObject
, it has
to be initialized with an empty initial shape. Initial shapes are created using
Shape.newBuilder()
and should ideally be shared per TruffleLanguage instance to allow
shape caches to be shared across contexts.
Subclasses can provide in-object dynamic field slots using the DynamicObject.DynamicField
annotation
and Shape.Builder.layout
.
Example:
public class MyObject extends DynamicObject implements TruffleObject {
public MyObject(Shape shape) {
super(shape);
}
}
Shape initialShape = Shape.newBuilder().layout(MyObject.class).build();
MyObject obj = new MyObject(initialShape);
DynamicObject.DynamicObject(Shape)
,
DynamicObjectLibrary
,
Shape
,
Shape.newBuilder()
Modifier and Type | Class and Description |
---|---|
protected static interface |
DynamicObject.DynamicField
Using this annotation, subclasses can define additional dynamic fields to be used by the
object layout.
|
Modifier | Constructor and Description |
---|---|
protected |
DynamicObject(Shape shape)
Constructor for
DynamicObject subclasses. |
Modifier and Type | Method and Description |
---|---|
protected Object |
clone()
The
DynamicObject.clone() method is not supported by DynamicObject at this point in time,
so it always throws CloneNotSupportedException , even if the Cloneable
interface is implemented in a subclass. |
Shape |
getShape()
Get the object's current shape.
|
protected DynamicObject(Shape shape)
DynamicObject
subclasses. Initializes the object with the provided
shape. The shape must have been constructed with a layout class assignable from this class (i.e., the concrete subclass, a superclass thereof,
including DynamicObject
) and must not have any instance properties (but may have
constant properties).
Examples:
Shape shape =Shape.newBuilder()
.build
(); DynamicObject myObject = new MyObject(shape);
Shape shape =Shape.newBuilder()
.layout
(MyObject.class).build
(); DynamicObject myObject = new MyObject(shape);
shape
- the initial shape of this objectIllegalArgumentException
- if called with an illegal (incompatible) shapepublic final Shape getShape()
Shape
protected Object clone() throws CloneNotSupportedException
DynamicObject.clone()
method is not supported by DynamicObject
at this point in time,
so it always throws CloneNotSupportedException
, even if the Cloneable
interface is implemented in a subclass.
Subclasses may however override this method and create a copy of this object by constructing
a new object and copying any properties over manually.clone
in class Object
CloneNotSupportedException