Class StaticShape<T>
java.lang.Object
com.oracle.truffle.api.staticobject.StaticShape<T>
- Type Parameters:
T
- the default or the user-defined factory interface to allocate static objects
A StaticShape is an immutable descriptor of the layout of a static object and is a good entry
point to learn about the Static Object Model. Here is an overview:
newBuilder(TruffleLanguage)
returns aStaticShape.Builder
object that can be used to register static properties and to generate a new static shape by calling one of its build methods.getFactory()
returns an implementation of the default or the user-defined factory interface that must be used to allocate static objects with the current shape.- Property values stored in a static object of a given shape can be accessed by the
StaticProperty
instances registered to the builder that generated that shape or one of its parent shapes. Note that static shapes do not store the list of static properties associated to them. It is up to the user to store this information when required, for example in a class that contains references to the static shape and the list of static properties.
StaticShape cannot be subclassed by custom implementations and, when required, it allows static properties to check that the receiver object matches the expected shape.
- Since:
- 21.3.0
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builder class to constructStaticShape
instances. -
Method Summary
Modifier and TypeMethodDescriptionfinal T
Returns an instance of the default or the user-defined factory interface that must be used to allocate static objects with the current shape.static StaticShape.Builder
newBuilder
(TruffleLanguage<?> language) Creates a new static shape builder.
-
Method Details
-
newBuilder
Creates a new static shape builder. The builder instance is not thread-safe and must not be used from multiple threads at the same time. Users of the Static Object Model are expected to define custom subtypes ofStaticProperty
or useDefaultStaticProperty
, a trivial default implementation. In both cases, static properties must be registered to a static shape builder usingStaticShape.Builder.property(StaticProperty, Class, boolean)
. Then, after allocating aStaticShape
instance with one of theStaticShape.Builder.build()
methods and allocating a static object using the factory class provided bygetFactory()
, users can call the accessor methods defined inStaticProperty
to get and set property values stored in a static object instance.- Parameters:
language
- an instance of theTruffleLanguage
that uses the Static Object Model- Returns:
- a new static shape builder
- Throws:
NullPointerException
- if language is null- Since:
- 21.3.0
- See Also:
-
getFactory
Returns an instance of the default or the user-defined factory interface that must be used to allocate static objects with the current shape.- Since:
- 21.3.0
- See Also:
-