# HG changeset patch # User Michael Van De Vanter # Date 1428903436 25200 # Node ID ca13a009e38b98ce80faf8127ccbec97c6de6c7c # Parent c7f1ab98d95021e811efcfe6293e1d52156ad08d Truffle/Instrumentation: Javadoc on Instrument now includes more thorough notes describing the implementation; client-oriented notes have been rewritten into a documentation page: https://wiki.openjdk.java.net/display/Graal/Listening+for+Execution+Events diff -r c7f1ab98d950 -r ca13a009e38b graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrument.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrument.java Sat Apr 11 00:16:29 2015 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrument.java Sun Apr 12 22:37:16 2015 -0700 @@ -25,142 +25,67 @@ package com.oracle.truffle.api.instrument; import com.oracle.truffle.api.*; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.instrument.InstrumentationNode.TruffleEvents; -import com.oracle.truffle.api.instrument.impl.*; import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.api.source.*; -// TODO (mlvdv) migrate some of this to external documentation. // TODO (mlvdv) move all this to a factory implemented in .impl (together with Probe), // then break out some of the nested classes into package privates. /** - * A dynamically added/removed binding between a {@link Probe}, which provides notification of - * execution events taking place at a {@link Node} in a Guest Language (GL) Truffle AST, - * and a listener, which consumes notifications on behalf of an external tool. There are at - * present two kinds of listeners that be used: - *
    - *
  1. {@link SimpleInstrumentListener} is the simplest and is intended for tools that require no - * access to the internal execution state of the Truffle execution, only that execution has - * passed through a particular location in the program. Information about that location is made - * available via the {@link Probe} argument in notification methods, including the - * {@linkplain SourceSection source location} of the node and any {@linkplain SyntaxTag tags} that - * have been applied to the node.
  2. - *
  3. {@link StandardInstrumentListener} reports the same events and {@link Probe} argument, but - * additionally provides access to the execution state via the explicit {@link Node} and - * {@link Frame} at the current execution site.
  4. - *
- *

- *

Summary: How to "instrument" an AST location:

- *

+ * A binding between: *

    - *
  1. Create an implementation of a listener interface.
  2. - *
  3. Create an Instrument via factory methods - * {@link Instrument#create(SimpleInstrumentListener, String)} or - * {@link Instrument#create(StandardInstrumentListener, String)}.
  4. - *
  5. "Attach" the Instrument to a Probe via {@link Probe#attach(Instrument)}, at which point event - * notifications begin to arrive at the listener.
  6. - *
  7. When no longer needed, "detach" the Instrument via {@link StandardInstrument#dispose()}, at - * which point event notifications to the listener cease, and the Instrument becomes unusable.
  8. - *
- *

- *

Options for creating listeners:

- *

- *

    - *
  1. Implement one of the listener interfaces: {@link SimpleInstrumentListener} or - * {@link StandardInstrumentListener} . Their event handling methods account for both the entry into - * an AST node (about to call) and three possible kinds of execution return from an AST - * node.
  2. - *
  3. Extend one of the helper implementations: {@link DefaultSimpleInstrumentListener} or - * {@link DefaultStandardInstrumentListener}. These provide no-op implementation of every listener - * method, so only the methods of interest need to be overridden.
  4. + *
  5. A {@link Probe}: a source of execution events taking place at a program location in + * an executing Truffle AST, and
  6. + *
  7. A listener: a consumer of execution events on behalf of an external client. *
*

- *

General guidelines for {@link StandardInstrumentListener} implementation:

+ * Client-oriented documentation for the use of Instruments is available online at Listening for + * Execution Events *

- * Unlike the listener interface {@link SimpleInstrumentListener}, which isolates implementations - * from Truffle internals (and is thus Truffle-safe), implementations of - * {@link StandardInstrumentListener} can interact directly with (and potentially affect) Truffle - * execution in general and Truffle optimization in particular. For example, it is possible to - * implement a debugger with this interface. - *

+ * The implementation of Instruments is complicated by the requirement that Truffle be able to clone + * ASTs at any time. In particular, any instrumentation-supporting Nodes that have been attached to + * an AST must be cloned along with the AST: AST clones are not permitted to share Nodes. *

- * As a consequence, implementations of {@link StandardInstrumentListener} effectively become part - * of the Truffle execution and must be coded according to general guidelines for Truffle - * implementations. For example: - *

+ * AST cloning is intended to be as transparent as possible to clients. This is encouraged + * by providing the {@link SimpleInstrumentListener} for clients that need know nothing more than + * the properties associated with a Probe: it's {@link SourceSection} and any associated instances + * of {@link SyntaxTag}. *

- *

Allowing for AST cloning:

+ * AST cloning is not transparent to clients that use the + * {@link StandardInstrumentListener}, since those event methods identify the concrete Node instance + * (and thus the AST instance) where the event takes place. *

- * Truffle routinely clones ASTs, which has consequences for implementations of - * {@link StandardInstrumentListener} (but not for implementations of - * {@link SimpleInstrumentListener}, from which cloning is hidden). - *

- *

- *

Access to execution state via {@link StandardInstrumentListener}:

+ *

Implementation Notes: the Life Cycle of an {@link Instrument} at a {@link Probe}

*

*

- *

- *

Activating and deactivating Instruments:

- *

- * Instruments are single-use: - *

- *

- *

Sharing listeners:

- *

- * Although an Instrument may only be attached to a single Probe, a listener can be shared among - * multiple Instruments. This can be useful for observing events that might happen at different - * locations in a single AST, for example all assignments to a particular variable. In this case a - * new Instrument would be created and attached at each assignment node, but all the Instruments - * would be created with the same listener. - *

- * Disclaimer: experimental; under development. * * @see Probe * @see TruffleEvents @@ -229,8 +154,7 @@ } /** - * Removes this instrument (and any clones) from the probe to which it attached and renders the - * instrument inert. + * Removes this instrument from the probe to which it attached and renders the instrument inert. * * @throws IllegalStateException if this instrument has already been disposed */ @@ -425,6 +349,7 @@ } } + // TODO (mlvdv) EXPERIMENTAL- UNDER DEVELOPMENT /** * An instrument that propagates events to an instance of {@link StandardInstrumentListener}. */