Class DynamicObject

java.lang.Object
com.oracle.truffle.api.object.DynamicObject
All Implemented Interfaces:
TruffleObject

public abstract class DynamicObject extends Object implements TruffleObject
Represents a dynamic object, members of which can be dynamically added and removed at run time. To use it, extend 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);
 
 
Since:
0.8 or earlier
See Also:
  • Constructor Details

    • DynamicObject

      protected DynamicObject(Shape shape)
      Constructor for 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);
       
      Parameters:
      shape - the initial shape of this object
      Throws:
      IllegalArgumentException - if called with an illegal (incompatible) shape
      Since:
      19.0
  • Method Details