final void replaceHelper(Node newNode, CharSequence reason) { CompilerAsserts.neverPartOfCompilation(); assert inAtomicBlock(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); } if (sourceSection != null && newNode.getSourceSection() == null) { // Pass on the source section to the new node. newNode.assignSourceSection(sourceSection); } // (aw) need to set parent *before* replace, so that (unsynchronized) getRootNode() // will always find the root node newNode.parent = this.parent; if (NodeUtil.replaceChild(this.parent, this, newNode)) { this.parent.adoptHelper(newNode); } else { this.parent.adoptUnadoptedHelper(newNode); } reportReplace(this, newNode, reason); onReplace(newNode, reason); }
public final void atomic(Runnable closure) { RootNode rootNode = getRootNode(); synchronized (rootNode != null ? rootNode : GIL) { assert enterAtomic(); try { closure.run(); } finally { assert exitAtomic(); } } }
@Override public SourceSection getInstrumentedSourceSection() { if (node == null) { return null; } else { return node.getEncapsulatingSourceSection(); } }
private static void updateSourceSection(Node oldNode, Node newNode) { if (newNode.getSourceSection() == null) { newNode.assignSourceSection(oldNode.getSourceSection()); } }
private void adoptUnadoptedHelper() { Iterable<Node> children = this.getChildren(); for (Node child : children) { if (child != null && child.getParent() == null) { this.adoptUnadoptedHelper(child); } } }
private void adoptHelper() { Iterable<Node> children = this.getChildren(); for (Node child : children) { if (child != null && child.getParent() != this) { this.adoptHelper(child); } } }
final void replaceHelper(Node newNode, CharSequence reason) { CompilerAsserts.neverPartOfCompilation("do not call Node.replaceHelper from compiled code"); assert inAtomicBlock(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); } // (aw) need to set parent *before* replace, so that (unsynchronized) getRootNode() // will always find the root node newNode.parent = this.parent; if (!NodeUtil.replaceChild(this.parent, this, newNode, true)) { this.parent.adoptUnadoptedHelper(newNode); } reportReplace(this, newNode, reason); onReplace(newNode, reason); }
@Override public void nodeProperties(PolymorphicSpecializeGraph graph, PolymorphicSpecializeGraph.DumpNode node, Map<String, ? super Object> properties) { properties.put("label", node.node.toString()); properties.put("ROOT?", node.node instanceof RootNode); properties.put("LEAF?", node.edge == null); properties.put("RootNode", node.node.getRootNode()); properties.putAll(node.node.getDebugProperties()); properties.put("SourceSection", node.node.getSourceSection()); if (Introspection.isIntrospectable(node.node)) { final List<Introspection.SpecializationInfo> specializations = Introspection.getSpecializations(node.node); for (Introspection.SpecializationInfo specialization : specializations) { properties.put(specialization.getMethodName() + ".isActive", specialization.isActive()); properties.put(specialization.getMethodName() + ".isExcluded", specialization.isExcluded()); properties.put(specialization.getMethodName() + ".instances", specialization.getInstances()); } } }
public String displayMethodName(Node node) { if (node == null) { return null; } RootNode root = node.getRootNode(); if (root == null) { return "unknown"; } return root.getCallTarget().toString(); }
public boolean visit(Node child) { if (child != null && child.getParent() == null) { newChild.adoptUnadoptedHelper(child); } return true; } });
static void adoptChildrenHelper(Node currentNode) { NodeClass clazz = currentNode.getNodeClass(); for (Object field : clazz.getNodeFields()) { if (clazz.isChildField(field)) { if (child != null) { Node node = (Node) child; if (node.getParent() != currentNode) { currentNode.adoptHelper(node); if (child != null) { Node node = (Node) child; if (node.getParent() != currentNode) { currentNode.adoptHelper(node);
static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) { if (TruffleOptions.TraceRewritesFilterFromCost != null) { if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) { return; } } if (TruffleOptions.TraceRewritesFilterToCost != null) { if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) { return; } } String filter = TruffleOptions.TraceRewritesFilterClass; Class<? extends Node> from = oldNode.getClass(); Class<? extends Node> to = newNode.getClass(); if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { return; } final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection(); PrintStream out = System.out; out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s %s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode), reason != null && reason.length() > 0 ? reason : "unknown", formatLocation(reportedSourceSection)); }
private static String extractSourceSection(OptimizedDirectCallNode node) { Node cnode = node; while (cnode.getSourceSection() == null && !(cnode instanceof RootNode)) { cnode = cnode.getParent(); if (cnode == null) { return ""; } } return getShortDescription(cnode.getSourceSection()); }
/** * Originally returned the <em>tags</em> if any, associated with a node; now unsupported. * * @since 0.8 or earlier */ public static String printSyntaxTags(final Object node) { if ((node instanceof Node) && ((Node) node).getSourceSection() != null) { return ((Node) node).getSourceSection().toString(); } return ""; }
public SourceSection getInstrumentedSourceSection() { SourceSection ss = eventContext.getInstrumentedSourceSection(); if (ss == null) { Node node = eventContext.getInstrumentedNode(); // Nodes tagged with standard tags should have a source section attached. PrintStream err = new PrintStream(env.err()); err.print("WARNING: Instrumented node " + node + " of class " + node.getClass() + " has null SourceSection."); ss = node.getEncapsulatingSourceSection(); if (ss == null) { RootNode root = node.getRootNode(); err.print("WARNING: and null encapsulating SourceSection under " + root + " of class = " + root.getClass()); } err.flush(); } return ss; }
public void probeAST(Node node) { node.accept(this); } }
public String displaySourceLocation(Node node) { if (node == null) { return "<unknown>"; } SourceSection section = node.getSourceSection(); boolean estimated = false; if (section == null) { section = node.getEncapsulatingSourceSection(); estimated = true; } return section.getShortDescription() + (estimated ? "~" : ""); }
@Override public boolean isCounted(Node node) { NodeCost cost = node.getCost(); boolean polymorphic = cost == NodeCost.POLYMORPHIC || cost == NodeCost.MEGAMORPHIC; return polymorphic; } });
public static boolean verify(Node root) { Iterable<Node> children = root.getChildren(); for (Node child : children) { if (child != null) { if (child.getParent() != root) { throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root)); } verify(child); } } return true; }
@Override public void onCompilationSuccess(OptimizedCallTarget target, TruffleInlining inliningDecision, GraphInfo graph, CompilationResultInfo result) { for (Node node : target.nodeIterable(inliningDecision)) { if (node != null && (node.getCost() == NodeCost.MEGAMORPHIC || node.getCost() == NodeCost.POLYMORPHIC)) { NodeCost cost = node.getCost(); Map<String, Object> props = new LinkedHashMap<>(); props.put("simpleName", node.getClass().getSimpleName()); props.put("subtree", "\n" + NodeUtil.printCompactTreeToString(node)); String msg = cost == NodeCost.MEGAMORPHIC ? "megamorphic" : "polymorphic"; runtime.logEvent(0, msg, node.toString(), props); } } }