comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/ProbeNode.java @ 19490:745ecef4c9cd

Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 18 Feb 2015 18:07:48 -0800
parents 2f676c3ca430
children 907128d02b31
comparison
equal deleted inserted replaced
19489:c99c7a4cda7d 19490:745ecef4c9cd
22 * or visit www.oracle.com if you need additional information or have any 22 * or visit www.oracle.com if you need additional information or have any
23 * questions. 23 * questions.
24 */ 24 */
25 package com.oracle.truffle.api.instrument; 25 package com.oracle.truffle.api.instrument;
26 26
27 import com.oracle.truffle.api.*;
28 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; 27 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
29 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 28 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
30 import com.oracle.truffle.api.frame.*; 29 import com.oracle.truffle.api.frame.*;
31 import com.oracle.truffle.api.instrument.Instrument.InstrumentNode; 30 import com.oracle.truffle.api.instrument.Instrument.InstrumentNode;
32 import com.oracle.truffle.api.nodes.*; 31 import com.oracle.truffle.api.nodes.*;
174 @Child protected InstrumentNode firstInstrument; 173 @Child protected InstrumentNode firstInstrument;
175 174
176 // Never changed once set. 175 // Never changed once set.
177 @CompilationFinal private Probe probe = null; 176 @CompilationFinal private Probe probe = null;
178 177
179 /**
180 * An assumption that the state of the {@link Probe} with which this chain is associated has
181 * not changed since the last time checking such an assumption failed and a reference to a
182 * new assumption (associated with a new state of the {@link Probe} was retrieved.
183 */
184 @CompilationFinal private Assumption probeUnchangedAssumption;
185
186 private ProbeFullNode() { 178 private ProbeFullNode() {
187 this.firstInstrument = null; 179 this.firstInstrument = null;
188 } 180 }
189 181
190 @Override 182 @Override
199 return node; 191 return node;
200 } 192 }
201 193
202 private void setProbe(Probe probe) { 194 private void setProbe(Probe probe) {
203 this.probe = probe; 195 this.probe = probe;
204 this.probeUnchangedAssumption = probe.getUnchangedAssumption();
205 }
206
207 private void checkProbeUnchangedAssumption() {
208 try {
209 probeUnchangedAssumption.check();
210 } catch (InvalidAssumptionException ex) {
211 // Failure creates an implicit deoptimization
212 // Get the assumption associated with the new probe state
213 this.probeUnchangedAssumption = probe.getUnchangedAssumption();
214 }
215 } 196 }
216 197
217 @Override 198 @Override
218 @TruffleBoundary 199 @TruffleBoundary
219 void addInstrument(Instrument instrument) { 200 void addInstrument(Instrument instrument) {
233 } else { 214 } else {
234 firstInstrument = insert(modifiedChain); 215 firstInstrument = insert(modifiedChain);
235 } 216 }
236 } 217 }
237 218
238 public void enter(Node node, VirtualFrame frame) { 219 public void enter(Node node, VirtualFrame vFrame) {
220 this.probe.checkProbeUnchanged();
239 final SyntaxTagTrap trap = probe.getTrap(); 221 final SyntaxTagTrap trap = probe.getTrap();
240 if (trap != null) { 222 if (trap != null) {
241 checkProbeUnchangedAssumption(); 223 trap.tagTrappedAt(((WrapperNode) this.getParent()).getChild(), vFrame.materialize());
242 trap.tagTrappedAt(((WrapperNode) this.getParent()).getChild(), frame.materialize());
243 } 224 }
244 if (firstInstrument != null) { 225 if (firstInstrument != null) {
245 checkProbeUnchangedAssumption(); 226 firstInstrument.enter(node, vFrame);
246 firstInstrument.enter(node, frame); 227 }
247 } 228 }
248 } 229
249 230 public void returnVoid(Node node, VirtualFrame vFrame) {
250 public void returnVoid(Node node, VirtualFrame frame) { 231 this.probe.checkProbeUnchanged();
251 if (firstInstrument != null) { 232 if (firstInstrument != null) {
252 checkProbeUnchangedAssumption(); 233 firstInstrument.returnVoid(node, vFrame);
253 firstInstrument.returnVoid(node, frame); 234 }
254 } 235 }
255 } 236
256 237 public void returnValue(Node node, VirtualFrame vFrame, Object result) {
257 public void returnValue(Node node, VirtualFrame frame, Object result) { 238 this.probe.checkProbeUnchanged();
258 if (firstInstrument != null) { 239 if (firstInstrument != null) {
259 checkProbeUnchangedAssumption(); 240 firstInstrument.returnValue(node, vFrame, result);
260 firstInstrument.returnValue(node, frame, result); 241 }
261 } 242 }
262 } 243
263 244 public void returnExceptional(Node node, VirtualFrame vFrame, Exception exception) {
264 public void returnExceptional(Node node, VirtualFrame frame, Exception exception) { 245 this.probe.checkProbeUnchanged();
265 if (firstInstrument != null) { 246 if (firstInstrument != null) {
266 checkProbeUnchangedAssumption(); 247 firstInstrument.returnExceptional(node, vFrame, exception);
267 firstInstrument.returnExceptional(node, frame, exception);
268 } 248 }
269 } 249 }
270 250
271 public String instrumentationInfo() { 251 public String instrumentationInfo() {
272 return "Standard probe"; 252 return "Standard probe";
273 } 253 }
274
275 } 254 }
276 255
277 /** 256 /**
278 * Implementation of a probe that only ever has a single "instrument" associated with it. No 257 * Implementation of a probe that only ever has a single "instrument" associated with it. No
279 * {@link Instrument} is ever created; instead this method simply delegates the various enter 258 * {@link Instrument} is ever created; instead this method simply delegates the various enter
303 @TruffleBoundary 282 @TruffleBoundary
304 void removeInstrument(Instrument instrument) { 283 void removeInstrument(Instrument instrument) {
305 throw new IllegalStateException("Instruments may not be removed at a \"lite-probed\" location"); 284 throw new IllegalStateException("Instruments may not be removed at a \"lite-probed\" location");
306 } 285 }
307 286
308 public void enter(Node node, VirtualFrame frame) { 287 public void enter(Node node, VirtualFrame vFrame) {
309 eventListener.enter(node, frame); 288 eventListener.enter(node, vFrame);
310 } 289 }
311 290
312 public void returnVoid(Node node, VirtualFrame frame) { 291 public void returnVoid(Node node, VirtualFrame vFrame) {
313 eventListener.returnVoid(node, frame); 292 eventListener.returnVoid(node, vFrame);
314 } 293 }
315 294
316 public void returnValue(Node node, VirtualFrame frame, Object result) { 295 public void returnValue(Node node, VirtualFrame vFrame, Object result) {
317 eventListener.returnValue(node, frame, result); 296 eventListener.returnValue(node, vFrame, result);
318 } 297 }
319 298
320 public void returnExceptional(Node node, VirtualFrame frame, Exception exception) { 299 public void returnExceptional(Node node, VirtualFrame vFrame, Exception exception) {
321 eventListener.returnExceptional(node, frame, exception); 300 eventListener.returnExceptional(node, vFrame, exception);
322 } 301 }
323 302
324 public String instrumentationInfo() { 303 public String instrumentationInfo() {
325 return "\"Lite\" probe"; 304 return "\"Lite\" probe";
326 } 305 }