# HG changeset patch # User Andreas Woess # Date 1405008509 -7200 # Node ID 76081918079d0e1e41f457cfed11066557751a45 # Parent f1d839174e71a157eefa1e81dcbbf670785193a9 Truffle: move TraceRewrites code to NodeUtil diff -r f1d839174e71 -r 76081918079d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Thu Jul 10 18:29:58 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Thu Jul 10 18:08:29 2014 +0200 @@ -24,7 +24,6 @@ */ package com.oracle.truffle.api.nodes; -import java.io.*; import java.lang.annotation.*; import java.util.*; import java.util.concurrent.*; @@ -280,9 +279,6 @@ this.parent.adoptUnadoptedHelper(newNode); } reportReplace(this, newNode, reason); - if (TruffleOptions.TraceASTJSON) { - JSONHelper.dumpReplaceChild(this, newNode, reason); - } onReplace(newNode, reason); } @@ -310,6 +306,12 @@ ((ReplaceObserver) target).nodeReplaced(oldNode, newNode, reason); } } + if (TruffleOptions.TraceRewrites) { + NodeUtil.traceRewrite(this, newNode, reason); + } + if (TruffleOptions.TraceASTJSON) { + JSONHelper.dumpReplaceChild(this, newNode, reason); + } } /** @@ -320,36 +322,7 @@ * @param reason the reason the replace supplied */ protected void onReplace(Node newNode, CharSequence reason) { - if (TruffleOptions.TraceRewrites) { - traceRewrite(newNode, reason); - } - } - - private void traceRewrite(Node newNode, CharSequence reason) { - if (TruffleOptions.TraceRewritesFilterFromCost != null) { - if (filterByKind(this, TruffleOptions.TraceRewritesFilterFromCost)) { - return; - } - } - - if (TruffleOptions.TraceRewritesFilterToCost != null) { - if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) { - return; - } - } - - String filter = TruffleOptions.TraceRewritesFilterClass; - Class from = getClass(); - Class to = newNode.getClass(); - if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { - return; - } - - final SourceSection reportedSourceSection = getEncapsulatingSourceSection(); - - PrintStream out = System.out; - out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s%s%n", this.toString(), formatNodeInfo(this), formatNodeInfo(newNode), reason != null && reason.length() > 0 ? reason - : "unknown", reportedSourceSection != null ? " at " + reportedSourceSection.getShortDescription() : ""); + // empty default } /** @@ -362,43 +335,6 @@ // empty default } - private static String formatNodeInfo(Node node) { - String cost = "?"; - switch (node.getCost()) { - case NONE: - cost = "G"; - break; - case MONOMORPHIC: - cost = "M"; - break; - case POLYMORPHIC: - cost = "P"; - break; - case MEGAMORPHIC: - cost = "G"; - break; - default: - cost = "?"; - break; - } - return cost + " " + node.getClass().getSimpleName(); - } - - private static boolean filterByKind(Node node, NodeCost cost) { - return node.getCost() == cost; - } - - private static boolean filterByContainsClassName(Class from, String filter) { - Class currentFrom = from; - while (currentFrom != null) { - if (currentFrom.getName().contains(filter)) { - return false; - } - currentFrom = currentFrom.getSuperclass(); - } - return true; - } - /** * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all * child nodes. diff -r f1d839174e71 -r 76081918079d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Jul 10 18:29:58 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Jul 10 18:08:29 2014 +0200 @@ -891,4 +891,68 @@ private static String toStringWithClass(Object obj) { return obj == null ? "null" : obj + "(" + obj.getClass().getName() + ")"; } + + 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 from = oldNode.getClass(); + Class 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", reportedSourceSection != null ? " at " + reportedSourceSection.getShortDescription() : ""); + } + + private static String formatNodeInfo(Node node) { + String cost = "?"; + switch (node.getCost()) { + case NONE: + cost = "G"; + break; + case MONOMORPHIC: + cost = "M"; + break; + case POLYMORPHIC: + cost = "P"; + break; + case MEGAMORPHIC: + cost = "G"; + break; + default: + cost = "?"; + break; + } + return cost + " " + node.getClass().getSimpleName(); + } + + private static boolean filterByKind(Node node, NodeCost cost) { + return node.getCost() == cost; + } + + private static boolean filterByContainsClassName(Class from, String filter) { + Class currentFrom = from; + while (currentFrom != null) { + if (currentFrom.getName().contains(filter)) { + return false; + } + currentFrom = currentFrom.getSuperclass(); + } + return true; + } }