Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
20129:5b7db8941fd7 | 20130:8dc73c226c63 |
---|---|
38 /** | 38 /** |
39 * Abstract base class for all Truffle nodes. | 39 * Abstract base class for all Truffle nodes. |
40 */ | 40 */ |
41 public abstract class Node implements NodeInterface, Cloneable { | 41 public abstract class Node implements NodeInterface, Cloneable { |
42 | 42 |
43 private final NodeClass nodeClass; | |
43 @CompilationFinal private Node parent; | 44 @CompilationFinal private Node parent; |
44 @CompilationFinal private SourceSection sourceSection; | 45 @CompilationFinal private SourceSection sourceSection; |
45 | 46 |
46 /** | 47 /** |
47 * Marks array fields that are children of this node. | 48 * Marks array fields that are children of this node. |
64 } | 65 } |
65 | 66 |
66 protected Node(SourceSection sourceSection) { | 67 protected Node(SourceSection sourceSection) { |
67 CompilerAsserts.neverPartOfCompilation(); | 68 CompilerAsserts.neverPartOfCompilation(); |
68 this.sourceSection = sourceSection; | 69 this.sourceSection = sourceSection; |
70 this.nodeClass = NodeClass.get(getClass()); | |
69 if (TruffleOptions.TraceASTJSON) { | 71 if (TruffleOptions.TraceASTJSON) { |
70 JSONHelper.dumpNewNode(this); | 72 JSONHelper.dumpNewNode(this); |
71 } | 73 } |
72 } | 74 } |
73 | 75 |
84 if (getSourceSection() != section) { | 86 if (getSourceSection() != section) { |
85 throw new IllegalStateException("Source section is already assigned. Old: " + getSourceSection() + ", new: " + section); | 87 throw new IllegalStateException("Source section is already assigned. Old: " + getSourceSection() + ", new: " + section); |
86 } | 88 } |
87 } | 89 } |
88 this.sourceSection = section; | 90 this.sourceSection = section; |
91 } | |
92 | |
93 NodeClass getNodeClass() { | |
94 return nodeClass; | |
89 } | 95 } |
90 | 96 |
91 /** | 97 /** |
92 * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by | 98 * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by |
93 * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method | 99 * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method |
342 * @return the iterator | 348 * @return the iterator |
343 */ | 349 */ |
344 public final Iterable<Node> getChildren() { | 350 public final Iterable<Node> getChildren() { |
345 return new Iterable<Node>() { | 351 return new Iterable<Node>() { |
346 public Iterator<Node> iterator() { | 352 public Iterator<Node> iterator() { |
347 return NodeUtil.makeIterator(Node.this); | 353 return nodeClass.makeIterator(Node.this); |
348 } | 354 } |
349 }; | 355 }; |
350 } | 356 } |
351 | 357 |
352 /** | 358 /** |