diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 20130:8dc73c226c63

Truffle: cache NodeClass lookup in Node.
author Christian Humer <christian.humer@gmail.com>
date Thu, 02 Apr 2015 01:26:31 +0200
parents f792b4270cb1
children 4b12d5355811
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Thu Apr 02 01:22:41 2015 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Thu Apr 02 01:26:31 2015 +0200
@@ -40,6 +40,7 @@
  */
 public abstract class Node implements NodeInterface, Cloneable {
 
+    private final NodeClass nodeClass;
     @CompilationFinal private Node parent;
     @CompilationFinal private SourceSection sourceSection;
 
@@ -66,6 +67,7 @@
     protected Node(SourceSection sourceSection) {
         CompilerAsserts.neverPartOfCompilation();
         this.sourceSection = sourceSection;
+        this.nodeClass = NodeClass.get(getClass());
         if (TruffleOptions.TraceASTJSON) {
             JSONHelper.dumpNewNode(this);
         }
@@ -88,6 +90,10 @@
         this.sourceSection = section;
     }
 
+    NodeClass getNodeClass() {
+        return nodeClass;
+    }
+
     /**
      * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by
      * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method
@@ -344,7 +350,7 @@
     public final Iterable<Node> getChildren() {
         return new Iterable<Node>() {
             public Iterator<Node> iterator() {
-                return NodeUtil.makeIterator(Node.this);
+                return nodeClass.makeIterator(Node.this);
             }
         };
     }