Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/Cached.java @ 22503:828c67903db2
Moving profiles into their own project to ensure the core API doesn't reference these utility classes.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 17 Dec 2015 10:01:38 +0100 |
parents | a63bda98cfdb |
children |
comparison
equal
deleted
inserted
replaced
22502:d2b4fe945c23 | 22503:828c67903db2 |
---|---|
24 */ | 24 */ |
25 package com.oracle.truffle.api.dsl; | 25 package com.oracle.truffle.api.dsl; |
26 | 26 |
27 import com.oracle.truffle.api.CompilerAsserts; | 27 import com.oracle.truffle.api.CompilerAsserts; |
28 import com.oracle.truffle.api.nodes.Node; | 28 import com.oracle.truffle.api.nodes.Node; |
29 import com.oracle.truffle.api.profiles.BranchProfile; | |
30 | 29 |
31 import java.lang.annotation.ElementType; | 30 import java.lang.annotation.ElementType; |
32 import java.lang.annotation.Retention; | 31 import java.lang.annotation.Retention; |
33 import java.lang.annotation.RetentionPolicy; | 32 import java.lang.annotation.RetentionPolicy; |
34 import java.lang.annotation.Target; | 33 import java.lang.annotation.Target; |
91 * @Specialization | 90 * @Specialization |
92 * void doCached(int operand, {@code @Cached}("operand") int cachedOperand) { | 91 * void doCached(int operand, {@code @Cached}("operand") int cachedOperand) { |
93 * CompilerAsserts.compilationConstant(cachedOperand); | 92 * CompilerAsserts.compilationConstant(cachedOperand); |
94 * ... | 93 * ... |
95 * } | 94 * } |
96 * | 95 * |
97 * Example executions: | 96 * Example executions: |
98 * execute(1) => doCached(1, 1) // new instantiation, localOperand is bound to 1 | 97 * execute(1) => doCached(1, 1) // new instantiation, localOperand is bound to 1 |
99 * execute(0) => doCached(0, 1) | 98 * execute(0) => doCached(0, 1) |
100 * execute(2) => doCached(2, 1) | 99 * execute(2) => doCached(2, 1) |
101 * | 100 * |
117 * @Specialization(guards = "operand == cachedOperand") | 116 * @Specialization(guards = "operand == cachedOperand") |
118 * void doCached(int operand, {@code @Cached}("operand") int cachedOperand) { | 117 * void doCached(int operand, {@code @Cached}("operand") int cachedOperand) { |
119 * CompilerAsserts.compilationConstant(cachedOperand); | 118 * CompilerAsserts.compilationConstant(cachedOperand); |
120 * ... | 119 * ... |
121 * } | 120 * } |
122 * | 121 * |
123 * Example executions: | 122 * Example executions: |
124 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 | 123 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 |
125 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 | 124 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 |
126 * execute(1) => doCached(1, 1) | 125 * execute(1) => doCached(1, 1) |
127 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 | 126 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 |
145 * @Specialization(guards = "operand == cachedOperand") | 144 * @Specialization(guards = "operand == cachedOperand") |
146 * void doCached(int operand, {@code @Cached}("operand") int cachedOperand) { | 145 * void doCached(int operand, {@code @Cached}("operand") int cachedOperand) { |
147 * CompilerAsserts.compilationConstant(cachedOperand); | 146 * CompilerAsserts.compilationConstant(cachedOperand); |
148 * ... | 147 * ... |
149 * } | 148 * } |
150 * | 149 * |
151 * @Specialization(contains = "doCached") | 150 * @Specialization(contains = "doCached") |
152 * void doNormal(int operand) {...} | 151 * void doNormal(int operand) {...} |
153 * | 152 * |
154 * Example executions with contains = "doCached": | 153 * Example executions with contains = "doCached": |
155 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 | 154 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 |
156 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 | 155 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 |
157 * execute(1) => doCached(1, 1) | 156 * execute(1) => doCached(1, 1) |
158 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 | 157 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 |
159 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow; doCached gets removed. | 158 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow; doCached gets removed. |
160 * execute(1) => doNormal(1) | 159 * execute(1) => doNormal(1) |
161 * | 160 * |
162 * Example executions without contains = "doCached": | 161 * Example executions without contains = "doCached": |
163 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 | 162 * execute(0) => doCached(0, 0) // new instantiation, cachedOperand is bound to 0 |
164 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 | 163 * execute(1) => doCached(1, 1) // new instantiation, cachedOperand is bound to 1 |
165 * execute(1) => doCached(1, 1) | 164 * execute(1) => doCached(1, 1) |
166 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 | 165 * execute(2) => doCached(2, 2) // new instantiation, cachedOperand is bound to 2 |
167 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow | 166 * execute(3) => doNormal(3) // new instantiation of doNormal due to limit overflow |
168 * execute(1) => doCached(1, 1) | 167 * execute(1) => doCached(1, 1) |
169 * | 168 * |
170 * </code> | 169 * </code> |
171 * | 170 * |
172 * </li> | 171 * </li> |
173 * <li> | 172 * <li> |
174 * This next example shows how methods from the enclosing node can be used to initialize cached | 173 * This next example shows how methods from the enclosing node can be used to initialize cached |
176 * | 175 * |
177 * <pre> | 176 * <pre> |
178 * @Specialization | 177 * @Specialization |
179 * void s(int operand, {@code @Cached}("transformLocal(operand)") int cachedOperand) { | 178 * void s(int operand, {@code @Cached}("transformLocal(operand)") int cachedOperand) { |
180 * } | 179 * } |
181 * | 180 * |
182 * int transformLocal(int operand) { | 181 * int transformLocal(int operand) { |
183 * return operand & 0x42; | 182 * return operand & 0x42; |
184 * } | 183 * } |
185 * | 184 * |
186 * </li> | 185 * </li> |
192 * <pre> | 191 * <pre> |
193 * @Specialization | 192 * @Specialization |
194 * void s(Object operand, {@code @Cached}("new()") OtherNode someNode) { | 193 * void s(Object operand, {@code @Cached}("new()") OtherNode someNode) { |
195 * someNode.execute(operand); | 194 * someNode.execute(operand); |
196 * } | 195 * } |
197 * | 196 * |
198 * static class OtherNode extends Node { | 197 * static class OtherNode extends Node { |
199 * | 198 * |
200 * public String execute(Object value) { | 199 * public String execute(Object value) { |
201 * throw new UnsupportedOperationException(); | 200 * throw new UnsupportedOperationException(); |
202 * } | 201 * } |
203 * } | 202 * } |
204 * | 203 * |
206 * | 205 * |
207 * </li> | 206 * </li> |
208 * <li> | 207 * <li> |
209 * Java types without public constructor but with a static factory methods can be initialized by | 208 * Java types without public constructor but with a static factory methods can be initialized by |
210 * just referencing its static factory method and its parameters. In this case | 209 * just referencing its static factory method and its parameters. In this case |
211 * {@link BranchProfile#create()} is used to instantiate the {@link BranchProfile} instance. | 210 * {@link com.oracle.truffle.api.profiles.BranchProfile#create()} is used to instantiate the |
211 * {@link com.oracle.truffle.api.profiles.BranchProfile} instance. | |
212 * | 212 * |
213 * <pre> | 213 * <pre> |
214 * @Specialization | 214 * @Specialization |
215 * void s(int operand, {@code @Cached}("create()") BranchProfile profile) { | 215 * void s(int operand, {@code @Cached}("create()") BranchProfile profile) { |
216 * } | 216 * } |