/** * Replaces this node with another node. If there is a source section (see * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. * * @param newNode the new node that is the replacement * @return the new node */ public final <T extends Node> T replace(T newNode) { return replace(newNode, ""); }
/** * Replaces this node with another node. If there is a source section (see * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. * * @param newNode the new node that is the replacement * @return the new node * @since 0.8 or earlier */ public final <T extends Node> T replace(T newNode) { return replace(newNode, ""); }
/** * Replaces this node with another node. If there is a source section (see * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. * * @param newNode the new node that is the replacement * @return the new node * @since 0.8 or earlier */ public final <T extends Node> T replace(T newNode) { return replace(newNode, ""); }
public T call() { Node prev = getPrevious(uninitialized); if (prev == null) { newNode.adoptChildren0(uninitialized, null); return uninitialized.replace(newNode, "Uninitialized monomorphic"); } else { return appendPolymorphic(uninitialized, newNode); } } });
public T call() { assert newNode != null; if (getNext(thisNode) != null || getPrevious(thisNode) != null) { // already polymorphic -> append return appendPolymorphic(findUninitialized(thisNode), newNode); } else if (includes(thisNode, newNode)) { // included -> remains monomorphic newNode.adoptChildren0(thisNode, null); return thisNode.replace(newNode, message); } else { // goto polymorphic return null; } } });
@SuppressWarnings("unchecked") private Node materializeSyntaxNodes(Node instrumentableNode, SourceSection sourceSection) { if (instrumentableNode instanceof InstrumentableNode) { InstrumentableNode currentNode = (InstrumentableNode) instrumentableNode; assert currentNode.isInstrumentable(); Set<Class<? extends Tag>> materializeTags = (Set<Class<? extends Tag>>) (materializeLimitedTags == null ? providedTags : materializeLimitedTags); InstrumentableNode materializedNode = currentNode.materializeInstrumentableNodes(materializeTags); if (currentNode != materializedNode) { if (!(materializedNode instanceof Node)) { throw new IllegalStateException("The returned materialized syntax node is not a Truffle Node."); } if (((Node) materializedNode).getParent() != null) { throw new IllegalStateException("The returned materialized syntax node is already adopted."); } SourceSection newSourceSection = ((Node) materializedNode).getSourceSection(); if (!Objects.equals(sourceSection, newSourceSection)) { throw new IllegalStateException(String.format("The source section of the materialized syntax node must match the source section of the original node. %s != %s.", sourceSection, newSourceSection)); } return ((Node) currentNode).replace((Node) materializedNode); } } return instrumentableNode; }
@SuppressWarnings("unchecked") private Node materializeSyntaxNodes(Node instrumentableNode, SourceSection sourceSection) { if (instrumentableNode instanceof InstrumentableNode) { InstrumentableNode currentNode = (InstrumentableNode) instrumentableNode; assert currentNode.isInstrumentable(); Set<Class<? extends Tag>> materializeTags = (Set<Class<? extends Tag>>) (materializeLimitedTags == null ? providedTags : materializeLimitedTags); InstrumentableNode materializedNode = currentNode.materializeInstrumentableNodes(materializeTags); if (currentNode != materializedNode) { if (!(materializedNode instanceof Node)) { throw new IllegalStateException("The returned materialized syntax node is not a Truffle Node."); } if (((Node) materializedNode).getParent() != null) { throw new IllegalStateException("The returned materialized syntax node is already adopted."); } SourceSection newSourceSection = ((Node) materializedNode).getSourceSection(); if (!Objects.equals(sourceSection, newSourceSection)) { throw new IllegalStateException(String.format("The source section of the materialized syntax node must match the source section of the original node. %s != %s.", sourceSection, newSourceSection)); } return ((Node) currentNode).replace((Node) materializedNode); } } return instrumentableNode; }
node.replace(wrapperNode, "Insert instrumentation wrapper node.");
originalNode.replace(wrapperNode, "Insert instrumentation wrapper node.");
@SuppressWarnings("deprecation") static void removeWrapper(ProbeNode node) { if (TRACE) { trace("Remove wrapper for %s%n", node.getContext().getInstrumentedSourceSection()); } com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode wrapperNode = node.findWrapper(); ((Node) wrapperNode).replace(wrapperNode.getDelegateNode()); }
@SuppressWarnings("deprecation") static void removeWrapper(ProbeNode node) { if (TRACE) { trace("Remove wrapper for %s%n", node.getContext().getInstrumentedSourceSection()); } com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode wrapperNode = node.findWrapper(); ((Node) wrapperNode).replace(wrapperNode.getDelegateNode()); }
private static <T extends Node & DSLNode> T appendPolymorphic(Node uninitialized, T newNode) { Class<?>[] includes = newNode.getMetadata0().getIncludes(); Node cur = getPrevious(uninitialized); Node prev = uninitialized; int depth = 0; Class<?>[] types = null; while (cur != null) { if (containsClass(includes, cur)) { cur.replace(prev, "Included in other specialization"); cur = prev; } else { depth++; types = mergeTypes((DSLNode) cur, types); } prev = cur; cur = getPrevious(cur); } assert prev.getCost() == NodeCost.POLYMORPHIC; updateSourceSection(prev, newNode); if (depth <= 1) { newNode.adoptChildren0(prev, null); return prev.replace(newNode, "Polymorphic to monomorphic."); } else { newNode.adoptChildren0(null, uninitialized); ((DSLNode) prev).updateTypes0(mergeTypes(newNode, types)); return uninitialized.replace(newNode, "Appended polymorphic"); } }
public T call() { assert getNext(oldNode) == null; assert getPrevious(oldNode) == null; assert newNodeDSL != null; Node uninitialized = (Node) uninitializedDSL; Node newNode = (Node) newNodeDSL; polymorphic.adoptChildren0(oldNode, (Node) currentCopy); updateSourceSection(oldNode, uninitialized); // new specialization updateSourceSection(oldNode, newNode); newNodeDSL.adoptChildren0(null, uninitialized); currentCopy.adoptChildren0(null, newNode); oldNode.replace(polymorphic, message); assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized; assert uninitializedDSL.getNext0() == null; return polymorphic; } });
this.replace(wrapperNode);