comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Probe.java @ 22003:5bc7f7b867ab

Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Sat, 18 Jul 2015 18:03:36 +0200
parents 9c8c0937da41
children 78c3d3d8d86e
comparison
equal deleted inserted replaced
22002:324997830dc9 22003:5bc7f7b867ab
28 import java.lang.ref.*; 28 import java.lang.ref.*;
29 import java.util.*; 29 import java.util.*;
30 30
31 import com.oracle.truffle.api.*; 31 import com.oracle.truffle.api.*;
32 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; 32 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
33 import com.oracle.truffle.api.impl.Accessor;
33 import com.oracle.truffle.api.instrument.InstrumentationNode.TruffleEvents; 34 import com.oracle.truffle.api.instrument.InstrumentationNode.TruffleEvents;
34 import com.oracle.truffle.api.nodes.*; 35 import com.oracle.truffle.api.nodes.*;
35 import com.oracle.truffle.api.source.*; 36 import com.oracle.truffle.api.source.*;
36 import com.oracle.truffle.api.utilities.*; 37 import com.oracle.truffle.api.utilities.*;
37 38
45 * <li>A dynamically managed collection of "attached" {@linkplain Instrument Instruments} that 46 * <li>A dynamically managed collection of "attached" {@linkplain Instrument Instruments} that
46 * receive event notifications on behalf of external clients.</li> 47 * receive event notifications on behalf of external clients.</li>
47 * </ol> 48 * </ol>
48 * <p> 49 * <p>
49 * Client-oriented documentation for the use of Probes is available online at <a 50 * Client-oriented documentation for the use of Probes is available online at <a
50 * HREF="https://wiki.openjdk.java.net/display/Graal/Finding+Probes" 51 * HREF="https://wiki.openjdk.java.net/display/Graal/Finding+Probes" >https://wiki.openjdk.java.
51 * >https://wiki.openjdk.java.net/display/Graal/Finding+Probes</a> 52 * net/display/Graal/Finding+Probes</a>
52 * <p> 53 * <p>
53 * <h4>Implementation notes:</h4> 54 * <h4>Implementation notes:</h4>
54 * <p> 55 * <p>
55 * <ul> 56 * <ul>
56 * <li>A Probe must be permanently associated with a <em>program location</em>, defined by a 57 * <li>A Probe must be permanently associated with a <em>program location</em>, defined by a
98 * @see ASTProber 99 * @see ASTProber
99 * @see ProbeListener 100 * @see ProbeListener
100 * @see SyntaxTag 101 * @see SyntaxTag
101 */ 102 */
102 public final class Probe { 103 public final class Probe {
104 private final Class<? extends TruffleLanguage> language;
103 105
104 private static final boolean TRACE = false; 106 private static final boolean TRACE = false;
105 private static final String TRACE_PREFIX = "PROBE: "; 107 private static final String TRACE_PREFIX = "PROBE: ";
106 private static final PrintStream OUT = System.out; 108 private static final PrintStream OUT = System.out;
107 109
301 @CompilationFinal private boolean isAfterTrapActive = false; 303 @CompilationFinal private boolean isAfterTrapActive = false;
302 304
303 /** 305 /**
304 * Intended for use only by {@link ProbeNode}. 306 * Intended for use only by {@link ProbeNode}.
305 */ 307 */
306 Probe(ProbeNode probeNode, SourceSection sourceSection) { 308 Probe(Class<? extends TruffleLanguage> l, ProbeNode probeNode, SourceSection sourceSection) {
307 this.sourceSection = sourceSection; 309 this.sourceSection = sourceSection;
308 probes.add(new WeakReference<>(this)); 310 probes.add(new WeakReference<>(this));
309 registerProbeNodeClone(probeNode); 311 registerProbeNodeClone(probeNode);
310 if (TRACE) { 312 if (TRACE) {
311 final String location = this.sourceSection == null ? "<unknown>" : sourceSection.getShortDescription(); 313 final String location = this.sourceSection == null ? "<unknown>" : sourceSection.getShortDescription();
312 trace("ADDED %s %s %s", "Probe@", location, getTagsDescription()); 314 trace("ADDED %s %s %s", "Probe@", location, getTagsDescription());
313 } 315 }
314 for (ProbeListener listener : probeListeners) { 316 for (ProbeListener listener : probeListeners) {
315 listener.newProbeInserted(this); 317 listener.newProbeInserted(this);
316 } 318 }
319 this.language = l;
317 } 320 }
318 321
319 /** 322 /**
320 * Is this node tagged as belonging to a particular human-sensible category of language 323 * Is this node tagged as belonging to a particular human-sensible category of language
321 * constructs? 324 * constructs?
481 sb.append(tag.toString()); 484 sb.append(tag.toString());
482 } 485 }
483 sb.append("]"); 486 sb.append("]");
484 return sb.toString(); 487 return sb.toString();
485 } 488 }
489
490 static final class AccessorInstrument extends Accessor {
491 @Override
492 protected Class<? extends TruffleLanguage> findLanguage(RootNode n) {
493 return super.findLanguage(n);
494 }
495
496 @Override
497 protected Class<? extends TruffleLanguage> findLanguage(Probe probe) {
498 return probe.language;
499 }
500 }
501
502 static final AccessorInstrument ACCESSOR = new AccessorInstrument();
486 } 503 }