Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 14564:5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 17 Mar 2014 14:29:45 +0100 |
parents | c5411233cdf8 |
children | 6681b9eb3f4c |
comparison
equal
deleted
inserted
replaced
14108:98d38009bb2b | 14564:5d1308c78ddc |
---|---|
27 import java.io.*; | 27 import java.io.*; |
28 import java.lang.annotation.*; | 28 import java.lang.annotation.*; |
29 import java.util.*; | 29 import java.util.*; |
30 | 30 |
31 import com.oracle.truffle.api.*; | 31 import com.oracle.truffle.api.*; |
32 import com.oracle.truffle.api.nodes.NodeInfo.Kind; | |
33 | 32 |
34 /** | 33 /** |
35 * Abstract base class for all Truffle nodes. | 34 * Abstract base class for all Truffle nodes. |
36 */ | 35 */ |
37 public abstract class Node implements Cloneable { | 36 public abstract class Node implements Cloneable { |
80 } | 79 } |
81 } | 80 } |
82 this.sourceSection = section; | 81 this.sourceSection = section; |
83 } | 82 } |
84 | 83 |
85 public Kind getKind() { | 84 public NodeCost getCost() { |
86 NodeInfo info = getClass().getAnnotation(NodeInfo.class); | 85 NodeInfo info = getClass().getAnnotation(NodeInfo.class); |
87 if (info != null) { | 86 if (info != null) { |
88 return info.kind(); | 87 return info.cost(); |
89 } | 88 } |
90 return Kind.SPECIALIZED; | 89 return NodeCost.MONOMORPHIC; |
91 } | 90 } |
92 | 91 |
93 /** | 92 /** |
94 * Clears any previously assigned guest language source code from this node. | 93 * Clears any previously assigned guest language source code from this node. |
95 */ | 94 */ |
275 traceRewrite(newNode, reason); | 274 traceRewrite(newNode, reason); |
276 } | 275 } |
277 } | 276 } |
278 | 277 |
279 private void traceRewrite(Node newNode, String reason) { | 278 private void traceRewrite(Node newNode, String reason) { |
279 | |
280 if (TruffleOptions.TraceRewritesFilterFromCost != null) { | |
281 if (filterByKind(this, TruffleOptions.TraceRewritesFilterFromCost)) { | |
282 return; | |
283 } | |
284 } | |
285 | |
286 if (TruffleOptions.TraceRewritesFilterToCost != null) { | |
287 if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) { | |
288 return; | |
289 } | |
290 } | |
291 | |
292 String filter = TruffleOptions.TraceRewritesFilterClass; | |
280 Class<? extends Node> from = getClass(); | 293 Class<? extends Node> from = getClass(); |
281 Class<? extends Node> to = newNode.getClass(); | 294 Class<? extends Node> to = newNode.getClass(); |
282 | |
283 if (TruffleOptions.TraceRewritesFilterFromKind != null) { | |
284 if (filterByKind(from, TruffleOptions.TraceRewritesFilterFromKind)) { | |
285 return; | |
286 } | |
287 } | |
288 | |
289 if (TruffleOptions.TraceRewritesFilterToKind != null) { | |
290 if (filterByKind(to, TruffleOptions.TraceRewritesFilterToKind)) { | |
291 return; | |
292 } | |
293 } | |
294 | |
295 String filter = TruffleOptions.TraceRewritesFilterClass; | |
296 if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { | 295 if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { |
297 return; | 296 return; |
298 } | 297 } |
299 | 298 |
300 PrintStream out = System.out; | 299 PrintStream out = System.out; |
301 out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s.%n", this.toString(), formatNodeInfo(from), formatNodeInfo(to), reason); | 300 out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s.%n", this.toString(), formatNodeInfo(this), formatNodeInfo(newNode), reason); |
302 } | 301 } |
303 | 302 |
304 private static String formatNodeInfo(Class<? extends Node> clazz) { | 303 private static String formatNodeInfo(Node node) { |
305 NodeInfo nodeInfo = clazz.getAnnotation(NodeInfo.class); | 304 String cost = "?"; |
306 String kind = "?"; | 305 switch (node.getCost()) { |
307 if (nodeInfo != null) { | 306 case NONE: |
308 switch (nodeInfo.kind()) { | 307 cost = "G"; |
309 case GENERIC: | 308 break; |
310 kind = "G"; | 309 case MONOMORPHIC: |
311 break; | 310 cost = "M"; |
312 case SPECIALIZED: | 311 break; |
313 kind = "S"; | 312 case POLYMORPHIC: |
314 break; | 313 cost = "P"; |
315 case UNINITIALIZED: | 314 break; |
316 kind = "U"; | 315 case MEGAMORPHIC: |
317 break; | 316 cost = "G"; |
318 case POLYMORPHIC: | 317 break; |
319 kind = "P"; | 318 default: |
320 break; | 319 cost = "?"; |
321 default: | 320 break; |
322 kind = "?"; | 321 } |
323 break; | 322 return cost + " " + node.getClass().getSimpleName(); |
324 } | 323 } |
325 } | 324 |
326 return kind + " " + clazz.getSimpleName(); | 325 private static boolean filterByKind(Node node, NodeCost cost) { |
327 } | 326 return node.getCost() == cost; |
328 | |
329 private static boolean filterByKind(Class<?> clazz, Kind kind) { | |
330 NodeInfo info = clazz.getAnnotation(NodeInfo.class); | |
331 if (info != null) { | |
332 return info.kind() != kind; | |
333 } | |
334 return true; | |
335 } | 327 } |
336 | 328 |
337 private static boolean filterByContainsClassName(Class<? extends Node> from, String filter) { | 329 private static boolean filterByContainsClassName(Class<? extends Node> from, String filter) { |
338 Class<?> currentFrom = from; | 330 Class<?> currentFrom = from; |
339 while (currentFrom != null) { | 331 while (currentFrom != null) { |