Class DynamicObject.PutConstantNode
java.lang.Object
com.oracle.truffle.api.nodes.Node
com.oracle.truffle.api.object.DynamicObject.PutConstantNode
- All Implemented Interfaces:
NodeInterface, Cloneable
- Enclosing class:
DynamicObject
Sets the value of an existing property or adds a new property if no such property exists.
Additional variants allow setting property flags, only setting the property if it's either
absent or present, and setting constant properties stored in the shape.
- Since:
- 25.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.Child, Node.Children -
Method Summary
Modifier and TypeMethodDescriptioncreate()final voidexecute(DynamicObject receiver, Object key, Object value) Same asexecuteWithFlags(DynamicObject, Object, Object, int), except the property is added with 0 flags, and if the property already exists, its flags will not be updated.final booleanexecuteIfAbsent(DynamicObject receiver, Object key, Object value) Likeexecute(DynamicObject, Object, Object)but only if the property is absent.final booleanexecuteIfPresent(DynamicObject receiver, Object key, Object value) Likeexecute(DynamicObject, Object, Object)but only if the property is present.final voidexecuteWithFlags(DynamicObject receiver, Object key, Object value, int propertyFlags) Adds a property with a constant value or replaces an existing one.final booleanexecuteWithFlagsIfAbsent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteWithFlags(DynamicObject, Object, Object, int)but only if the property is absent.final booleanexecuteWithFlagsIfPresent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteWithFlags(DynamicObject, Object, Object, int)but only if the property is present.Methods inherited from class Node
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, reportReplace, toString
-
Method Details
-
execute
Same asexecuteWithFlags(DynamicObject, Object, Object, int), except the property is added with 0 flags, and if the property already exists, its flags will not be updated. -
executeIfPresent
Likeexecute(DynamicObject, Object, Object)but only if the property is present. -
executeIfAbsent
Likeexecute(DynamicObject, Object, Object)but only if the property is absent. -
executeWithFlags
public final void executeWithFlags(DynamicObject receiver, Object key, Object value, int propertyFlags) Adds a property with a constant value or replaces an existing one. If the property already exists, its flags will be updated. The constant value is stored in the shape rather than the object instance and a new shape will be allocated if it does not already exist. A typical use case for this method is setting the initial default value of a declared, but yet uninitialized, property. This defers storage allocation and type speculation until the first actual value is set.Warning: this method will lead to a shape transition every time a new value is set and should be used sparingly (with at most one constant value per property) since it could cause an excessive amount of shapes to be created.
Note: the value is strongly referenced from the shape property map. It should ideally be a value type or light-weight object without any references to guest language objects in order to prevent potential memory leaks from holding onto the Shape in inline caches. The Shape transition itself is weak, so the previous shapes will not hold strongly on the value.
Usage example:
abstract static class DeclarePropertyNode extends Node { abstract void execute(DynamicObject receiver, Object key); @Specialization static void doCached(MyDynamicObjectSubclass receiver, Symbol key, @Cached DynamicObject.PutConstantNode putConstantNode) { // declare property putConstantNode.execute(receiver, key, NULL_VALUE); } }abstract static class InitializePropertyNode extends Node { abstract void execute(DynamicObject receiver, Object key, Object value); @Specialization static void doCached(MyDynamicObjectSubclass receiver, Symbol key, Object value, @Cached DynamicObject.PutNode putNode) { // initialize property putNode.execute(receiver, key, value); } }- Parameters:
key- property identifiervalue- the constant value to be setpropertyFlags- property flags or 0- See Also:
-
executeWithFlagsIfPresent
public final boolean executeWithFlagsIfPresent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteWithFlags(DynamicObject, Object, Object, int)but only if the property is present. -
executeWithFlagsIfAbsent
public final boolean executeWithFlagsIfAbsent(DynamicObject receiver, Object key, Object value, int propertyFlags) LikeexecuteWithFlags(DynamicObject, Object, Object, int)but only if the property is absent. -
create
- Since:
- 25.1
-
getUncached
- Since:
- 25.1
-