Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
16463:f1d839174e71 | 16464:76081918079d |
---|---|
889 } | 889 } |
890 | 890 |
891 private static String toStringWithClass(Object obj) { | 891 private static String toStringWithClass(Object obj) { |
892 return obj == null ? "null" : obj + "(" + obj.getClass().getName() + ")"; | 892 return obj == null ? "null" : obj + "(" + obj.getClass().getName() + ")"; |
893 } | 893 } |
894 | |
895 static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) { | |
896 if (TruffleOptions.TraceRewritesFilterFromCost != null) { | |
897 if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) { | |
898 return; | |
899 } | |
900 } | |
901 | |
902 if (TruffleOptions.TraceRewritesFilterToCost != null) { | |
903 if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) { | |
904 return; | |
905 } | |
906 } | |
907 | |
908 String filter = TruffleOptions.TraceRewritesFilterClass; | |
909 Class<? extends Node> from = oldNode.getClass(); | |
910 Class<? extends Node> to = newNode.getClass(); | |
911 if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { | |
912 return; | |
913 } | |
914 | |
915 final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection(); | |
916 | |
917 PrintStream out = System.out; | |
918 out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s%s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode), | |
919 reason != null && reason.length() > 0 ? reason : "unknown", reportedSourceSection != null ? " at " + reportedSourceSection.getShortDescription() : ""); | |
920 } | |
921 | |
922 private static String formatNodeInfo(Node node) { | |
923 String cost = "?"; | |
924 switch (node.getCost()) { | |
925 case NONE: | |
926 cost = "G"; | |
927 break; | |
928 case MONOMORPHIC: | |
929 cost = "M"; | |
930 break; | |
931 case POLYMORPHIC: | |
932 cost = "P"; | |
933 break; | |
934 case MEGAMORPHIC: | |
935 cost = "G"; | |
936 break; | |
937 default: | |
938 cost = "?"; | |
939 break; | |
940 } | |
941 return cost + " " + node.getClass().getSimpleName(); | |
942 } | |
943 | |
944 private static boolean filterByKind(Node node, NodeCost cost) { | |
945 return node.getCost() == cost; | |
946 } | |
947 | |
948 private static boolean filterByContainsClassName(Class<? extends Node> from, String filter) { | |
949 Class<?> currentFrom = from; | |
950 while (currentFrom != null) { | |
951 if (currentFrom.getName().contains(filter)) { | |
952 return false; | |
953 } | |
954 currentFrom = currentFrom.getSuperclass(); | |
955 } | |
956 return true; | |
957 } | |
894 } | 958 } |