Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 16464:76081918079d
Truffle: move TraceRewrites code to NodeUtil
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Thu, 10 Jul 2014 18:08:29 +0200 |
parents | 915ebb306fcc |
children | 456abab80eb5 |
line wrap: on
line diff
--- 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<? 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", 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<? extends Node> from, String filter) { + Class<?> currentFrom = from; + while (currentFrom != null) { + if (currentFrom.getName().contains(filter)) { + return false; + } + currentFrom = currentFrom.getSuperclass(); + } + return true; + } }