Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 10590:6eb8d63cea34
Added a feature to trace rewrites of truffle nodes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 26 Jun 2013 17:21:59 +0200 |
parents | 29e9a5d18c70 |
children | 99b58803d6d9 |
comparison
equal
deleted
inserted
replaced
10541:9599e1a01812 | 10590:6eb8d63cea34 |
---|---|
24 | 24 |
25 import java.lang.annotation.*; | 25 import java.lang.annotation.*; |
26 import java.util.*; | 26 import java.util.*; |
27 | 27 |
28 import com.oracle.truffle.api.*; | 28 import com.oracle.truffle.api.*; |
29 import com.oracle.truffle.api.nodes.NodeInfo.Kind; | |
29 | 30 |
30 /** | 31 /** |
31 * Abstract base class for all Truffle nodes. | 32 * Abstract base class for all Truffle nodes. |
32 */ | 33 */ |
33 public abstract class Node implements Cloneable { | 34 public abstract class Node implements Cloneable { |
197 * | 198 * |
198 * @param newNode the replacement node | 199 * @param newNode the replacement node |
199 * @param reason the reason the replace supplied | 200 * @param reason the reason the replace supplied |
200 */ | 201 */ |
201 protected void onReplace(Node newNode, String reason) { | 202 protected void onReplace(Node newNode, String reason) { |
203 if (TruffleOptions.TraceRewrites) { | |
204 Class<? extends Node> from = getClass(); | |
205 Class<? extends Node> to = newNode.getClass(); | |
206 | |
207 if (TruffleOptions.TraceRewritesFilterFromKind != null) { | |
208 if (filterByKind(from, TruffleOptions.TraceRewritesFilterFromKind)) { | |
209 return; | |
210 } | |
211 } | |
212 | |
213 if (TruffleOptions.TraceRewritesFilterToKind != null) { | |
214 if (filterByKind(to, TruffleOptions.TraceRewritesFilterToKind)) { | |
215 return; | |
216 } | |
217 } | |
218 | |
219 String filter = TruffleOptions.TraceRewritesFilterClass; | |
220 if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { | |
221 return; | |
222 } | |
223 | |
224 // CheckStyle: stop system..print check | |
225 System.out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s.%n", this.toString(), formatNodeInfo(from), formatNodeInfo(to), reason); | |
226 // CheckStyle: resume system..print check | |
227 } | |
228 } | |
229 | |
230 private static String formatNodeInfo(Class<? extends Node> clazz) { | |
231 NodeInfo nodeInfo = clazz.getAnnotation(NodeInfo.class); | |
232 String kind = "?"; | |
233 if (nodeInfo != null) { | |
234 switch (nodeInfo.kind()) { | |
235 case GENERIC: | |
236 kind = "G"; | |
237 break; | |
238 case SPECIALIZED: | |
239 kind = "S"; | |
240 break; | |
241 case UNINITIALIZED: | |
242 kind = "U"; | |
243 break; | |
244 default: | |
245 kind = "?"; | |
246 break; | |
247 } | |
248 } | |
249 return kind + " " + clazz.getSimpleName(); | |
250 } | |
251 | |
252 private static boolean filterByKind(Class<?> clazz, Kind kind) { | |
253 NodeInfo info = clazz.getAnnotation(NodeInfo.class); | |
254 if (info != null) { | |
255 return info.kind() != kind; | |
256 } | |
257 return true; | |
258 } | |
259 | |
260 private static boolean filterByContainsClassName(Class<? extends Node> from, String filter) { | |
261 Class<?> currentFrom = from; | |
262 while (currentFrom != null) { | |
263 if (currentFrom.getName().contains(filter)) { | |
264 return false; | |
265 } | |
266 currentFrom = currentFrom.getSuperclass(); | |
267 } | |
268 return true; | |
202 } | 269 } |
203 | 270 |
204 /** | 271 /** |
205 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all | 272 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all |
206 * child nodes. | 273 * child nodes. |