Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/Cached.java @ 19300:67ab244ab689
Truffle-DSL: fix formatting issues.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 18:33:49 +0100 |
parents | 3a37116ef37f |
children | b249bdba508b |
comparison
equal
deleted
inserted
replaced
19299:8e4f683e16d9 | 19300:67ab244ab689 |
---|---|
88 * @Specialization | 88 * @Specialization |
89 * void doCached(int operand, @Local("operand") int cachedOperand) { | 89 * void doCached(int operand, @Local("operand") int cachedOperand) { |
90 * CompilerAsserts.compilationConstant(cachedOperand); | 90 * CompilerAsserts.compilationConstant(cachedOperand); |
91 * ... | 91 * ... |
92 * } | 92 * } |
93 * | 93 * |
94 * Example executions: | 94 * Example executions: |
95 * execute(1) => doCached(1, 1) // new instantiation, localOperand is bound to 1 | 95 * execute(1) => doCached(1, 1) // new instantiation, localOperand is bound to 1 |
96 * execute(0) => doCached(0, 1) | 96 * execute(0) => doCached(0, 1) |
97 * execute(2) => doCached(2, 1) | 97 * execute(2) => doCached(2, 1) |
98 * | 98 * |
136 * <code>doNormal</code> specialization uses <code>contains="doCached"</code> to specify | 136 * <code>doNormal</code> specialization uses <code>contains="doCached"</code> to specify |
137 * that all instantiations of <code>doCached</code> get removed if <code>doNormal</code> is | 137 * that all instantiations of <code>doCached</code> get removed if <code>doNormal</code> is |
138 * instantiated. Alternatively if the <code>contains</code> relation is omitted then all | 138 * instantiated. Alternatively if the <code>contains</code> relation is omitted then all |
139 * <code>doCached</code> instances remain but no new instances are created. | 139 * <code>doCached</code> instances remain but no new instances are created. |
140 * | 140 * |
141 * <pre> | 141 * <code> |
142 * @Specialization(guards = "==(operand, cachedOperand)") | 142 * @Specialization(guards = "==(operand, cachedOperand)") |
143 * void doCached(int operand, @Cached("operand") int cachedOperand) { | 143 * void doCached(int operand, @Cached("operand") int cachedOperand) { |
144 * CompilerAsserts.compilationConstant(cachedOperand); | 144 * CompilerAsserts.compilationConstant(cachedOperand); |
145 * ... | 145 * ... |
146 * } | 146 * } |
147 * | 147 * |
148 * @Specialization(contains = "doCached") | 148 * @Specialization(contains = "doCached") |
149 * void doNormal(int operand) {...} | 149 * void doNormal(int operand) {...} |
150 * | 150 * |
151 * Example executions with contains = "doCached": | 151 * Example executions with contains = "doCached": |
152 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 | 152 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 |
153 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 | 153 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 |
154 * execute(1) => doCached(1, 1) | 154 * execute(1) => doCached(1, 1) |
155 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 | 155 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 |
156 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow; doCached gets removed. | 156 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow; doCached gets removed. |
157 * execute(1) => doNormal(1) | 157 * execute(1) => doNormal(1) |
158 * | 158 * |
159 * Example executions without contains = "doCached": | 159 * Example executions without contains = "doCached": |
160 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 | 160 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 |
161 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 | 161 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 |
162 * execute(1) => doCached(1, 1) | 162 * execute(1) => doCached(1, 1) |
163 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 | 163 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 |
164 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow | 164 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow |
165 * execute(1) => doCached(1, 1) | 165 * execute(1) => doCached(1, 1) |
166 * | 166 * |
167 * </pre> | 167 * </code> |
168 * | 168 * |
169 * </li> | 169 * </li> |
170 * <li> | 170 * <li> |
171 * This next example shows how methods from the enclosing node can be used to initialize cached | 171 * This next example shows how methods from the enclosing node can be used to initialize cached |
172 * parameters. Please note that the visibility of transformLocal must not be <code>private</code>. | 172 * parameters. Please note that the visibility of transformLocal must not be <code>private</code>. |
173 * | 173 * |
174 * <pre> | 174 * <pre> |
175 * @Specialization | 175 * @Specialization |
176 * void s(int operand, @Cached("transformLocal(operand)") int cachedOperand) { | 176 * void s(int operand, @Cached("transformLocal(operand)") int cachedOperand) { |
177 * } | 177 * } |
178 * | 178 * |
179 * int transformLocal(int operand) { | 179 * int transformLocal(int operand) { |
180 * return operand & 0x42; | 180 * return operand & 0x42; |
181 * } | 181 * } |
182 * | 182 * |
183 * </li> | 183 * </li> |
189 * <pre> | 189 * <pre> |
190 * @Specialization | 190 * @Specialization |
191 * void s(Object operand, @Cached("new()") OtherNode someNode) { | 191 * void s(Object operand, @Cached("new()") OtherNode someNode) { |
192 * someNode.execute(operand); | 192 * someNode.execute(operand); |
193 * } | 193 * } |
194 * | 194 * |
195 * static class OtherNode extends Node { | 195 * static class OtherNode extends Node { |
196 * | 196 * |
197 * public String execute(Object value) { | 197 * public String execute(Object value) { |
198 * throw new UnsupportedOperationException(); | 198 * throw new UnsupportedOperationException(); |
199 * } | 199 * } |
200 * } | 200 * } |
201 * | 201 * |