comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrument.java @ 21355:442b57a7f208

Truffle/Instrumentation: change the signature for creation of Advanced instruments, refactor how the callback listener is managed.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 12 May 2015 16:06:00 -0700
parents 575032310b2c
children e34bc00733d1
comparison
equal deleted inserted replaced
21354:575032310b2c 21355:442b57a7f208
129 /** 129 /**
130 * Creates an <em>Advanced Instrument</em>: this Instrument executes efficiently, subject to 130 * Creates an <em>Advanced Instrument</em>: this Instrument executes efficiently, subject to
131 * full Truffle optimization, a client-provided AST fragment every time the Probed node is 131 * full Truffle optimization, a client-provided AST fragment every time the Probed node is
132 * entered. 132 * entered.
133 * 133 *
134 * @param resultListener optional client callback for results/failure notification
134 * @param rootFactory provider of AST fragments on behalf of the client 135 * @param rootFactory provider of AST fragments on behalf of the client
135 * @param instrumentInfo optional description of the instrument's role, intended for debugging. 136 * @param instrumentInfo optional description of the instrument's role, intended for debugging.
136 * @return a new instrument, ready for attachment at a probe 137 * @return a new instrument, ready for attachment at a probe
137 */ 138 */
138 public static Instrument create(AdvancedInstrumentRootFactory rootFactory, String instrumentInfo) { 139 public static Instrument create(AdvancedInstrumentResultListener resultListener, AdvancedInstrumentRootFactory rootFactory, String instrumentInfo) {
139 return new AdvancedInstrument(rootFactory, instrumentInfo); 140 return new AdvancedInstrument(resultListener, rootFactory, instrumentInfo);
140 } 141 }
141 142
142 // TODO (mlvdv) experimental 143 // TODO (mlvdv) experimental
143 /** 144 /**
144 * For implementation testing. 145 * For implementation testing.
379 * within a Probe's <em>instrumentation chain</em>, and thus directly in the executing Truffle 380 * within a Probe's <em>instrumentation chain</em>, and thus directly in the executing Truffle
380 * AST with potential for full optimization. 381 * AST with potential for full optimization.
381 */ 382 */
382 private static final class AdvancedInstrument extends Instrument { 383 private static final class AdvancedInstrument extends Instrument {
383 384
385 private final AdvancedInstrumentResultListener resultListener;
384 /** 386 /**
385 * Client-provided supplier of new node instances to attach. 387 * Client-provided supplier of new node instances to attach.
386 */ 388 */
387 private final AdvancedInstrumentRootFactory rootFactory; 389 private final AdvancedInstrumentRootFactory rootFactory;
388 390
389 private AdvancedInstrument(AdvancedInstrumentRootFactory rootFactory, String instrumentInfo) { 391 private AdvancedInstrument(AdvancedInstrumentResultListener resultListener, AdvancedInstrumentRootFactory rootFactory, String instrumentInfo) {
390 super(instrumentInfo); 392 super(instrumentInfo);
393 this.resultListener = resultListener;
391 this.rootFactory = rootFactory; 394 this.rootFactory = rootFactory;
392 395
393 } 396 }
394 397
395 @Override 398 @Override
426 super(nextNode); 429 super(nextNode);
427 } 430 }
428 431
429 public void enter(Node node, VirtualFrame vFrame) { 432 public void enter(Node node, VirtualFrame vFrame) {
430 if (instrumentRoot == null) { 433 if (instrumentRoot == null) {
431 final AdvancedInstrumentRoot newInstrumentRoot = AdvancedInstrument.this.rootFactory.createInstrumentRoot(AdvancedInstrument.this.probe, node); 434 try {
432 if (newInstrumentRoot != null) { 435 final AdvancedInstrumentRoot newInstrumentRoot = AdvancedInstrument.this.rootFactory.createInstrumentRoot(AdvancedInstrument.this.probe, node);
433 instrumentRoot = newInstrumentRoot; 436 if (newInstrumentRoot != null) {
434 adoptChildren(); 437 instrumentRoot = newInstrumentRoot;
435 AdvancedInstrument.this.probe.invalidateProbeUnchanged(); 438 adoptChildren();
439 AdvancedInstrument.this.probe.invalidateProbeUnchanged();
440 }
441 } catch (RuntimeException ex) {
442 if (resultListener != null) {
443 resultListener.notifyFailure(node, vFrame, ex);
444 }
436 } 445 }
437 } 446 }
438 if (instrumentRoot != null) { 447 if (instrumentRoot != null) {
439 final AdvancedInstrumentResultListener resultListener = AdvancedInstrument.this.rootFactory.resultListener();
440 try { 448 try {
441 final Object result = instrumentRoot.executeRoot(node, vFrame); 449 final Object result = instrumentRoot.executeRoot(node, vFrame);
442 if (resultListener != null) { 450 if (resultListener != null) {
443 resultListener.notifyResult(node, vFrame, result); 451 resultListener.notifyResult(node, vFrame, result);
444 } 452 }