Mercurial > hg > truffle
diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ExecutionContext.java @ 15779:8c34e2cc4add
Truffle/Instrumentation: significant reorganization of the instrumentation framework's implementation and connection to the runtime ExecutionContext, with some new features, including a Tag-based "trap" mechanisms.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Mon, 19 May 2014 17:14:36 -0700 |
parents | bb9473723904 |
children | eb947cc7bff9 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ExecutionContext.java Tue May 13 18:31:18 2014 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ExecutionContext.java Mon May 19 17:14:36 2014 -0700 @@ -27,31 +27,131 @@ import java.util.*; import com.oracle.truffle.api.instrument.*; +import com.oracle.truffle.api.instrument.impl.*; import com.oracle.truffle.api.source.*; /** * Access to information and basic services in the runtime context for a Truffle-implemented guest * language. * <p> - * <strong>Disclaimer:</strong> this interface is under development and will change. + * <strong>Disclaimer:</strong> this class is under development and will change. */ -public interface ExecutionContext { +public abstract class ExecutionContext { + + private final ProbeManager probeManager = new ProbeManager(); + private final SourceManager sourceManager = new SourceManager(); + private final List<SourceListener> sourceListeners = new ArrayList<>(); + private Visualizer visualizer = new DefaultVisualizer(); + + protected ExecutionContext() { + } + + public void initialize() { + setSourceCallback(new SourceCallback() { + + public void startLoading(Source source) { + for (SourceListener listener : sourceListeners) { + listener.loadStarting(source); + } + } + + public void endLoading(Source source) { + for (SourceListener listener : sourceListeners) { + listener.loadEnding(source); + } + } + }); + } + + /** + * Gets access to source management services. + */ + public final SourceManager getSourceManager() { + return sourceManager; + } + + /** + * Registers a tool interested in being notified about the loading of {@link Source}s. + */ + public final void addSourceListener(SourceListener listener) { + assert listener != null; + sourceListeners.add(listener); + } + + /** + * Registers a tool interested in being notified about the insertion of a newly created + * {@link Probe} into a Truffle AST. + */ + public final void addProbeListener(ProbeListener listener) { + probeManager.addProbeListener(listener); + } + + /** + * Return the (possibly newly created) {@link Probe} uniquely associated with a particular + * source code location. A newly created probe carries no tags. + * + * @return a probe uniquely associated with an extent of guest language source code. + */ + public final Probe getProbe(SourceSection sourceSection) { + return probeManager.getProbe(sourceSection); + } + + /** + * Returns all existing probes with specific tag, or all probes if {@code tag = null}; empty + * collection if no probes found. + */ + public final Collection<Probe> findProbesTaggedAs(PhylumTag tag) { + return probeManager.findProbesTaggedAs(tag); + } + + /** + * Returns all existing probes with first character on a specified line; empty collection if no + * probes found. + */ + public final Collection<Probe> findProbesByLine(SourceLineLocation lineLocation) { + return probeManager.findProbesByLine(lineLocation); + } + + /** + * Sets a trap that will make a callback at any AST location where a existing probe holds a + * specified tag; only one trap may be set at a time. + * + * @throws IllegalStateException if a trap is already set + */ + public final void setPhylumTrap(PhylumTrap trap) throws IllegalStateException { + // TODO (mlvdv) consider allowing multiple traps (without inhibiting Truffle inlining) + probeManager.setPhylumTrap(trap); + } + + /** + * Clears a trap that will halt execution; only one trap may be set at a time. + * + * @throws IllegalStateException if no trap is set. + */ + public final void clearPhylumTrap() { + probeManager.clearPhylumTrap(); + } + + /** + * Access to information visualization services for the specific language. + */ + public final Visualizer getVisualizer() { + return visualizer; + } + + /** + * Assign guest language-specific visualization support for tools. This must be assigned outside + * the implementation context to avoid build circularities. + */ + public final void setVisualizer(Visualizer visualizer) { + this.visualizer = visualizer; + } /** * Gets the name of the language, possibly with version number. in short enough form that it * might be used for an interactive prompt. */ - String getLanguageShortName(); - - /** - * Gets access to source management services. - */ - SourceManager getSourceManager(); - - /** - * Registers a tool interested in being notified of events related to the loading of sources. - */ - void addSourceListener(SourceListener listener); + public abstract String getLanguageShortName(); /** * Add instrumentation to subsequently constructed Truffle ASTs for the guest language; every @@ -60,51 +160,19 @@ * @throws IllegalStateException if AST instrumentation not enabled * @throws IllegalArgumentException if prober not usable for the guest language implementation. */ - void addNodeProber(ASTNodeProber nodeProber) throws IllegalStateException, IllegalArgumentException; - - /** - * Registers a tool interested in being notified about the insertion of a newly created - * {@link Probe} into a Truffle AST. - */ - void addProbeListener(ProbeListener listener); - - /** - * Return the (possibly newly created) {@link Probe} uniquely associated with a particular - * source code location. A newly created probe carries no tags. - * - * @return a probe uniquely associated with an extent of guest language source code. - */ - Probe getProbe(SourceSection sourceSection); - - /** - * Returns all existing probes with specific tag, or all probes if {@code tag = null}; empty - * collection if no probes found. - */ - Collection<Probe> findProbesTaggedAs(PhylumTag tag); + public abstract void addNodeProber(ASTNodeProber nodeProber) throws IllegalStateException, IllegalArgumentException; /** - * Returns all existing probes with first character on a specified line; empty collection if no - * probes found. + * Assigns a guest language-specific manager for using {@link ASTNodeProber}s added by tools to + * instrument ASTs with {@link Probe}s at specified nodes. This must be assigned outside the + * implementation context to avoid build circularities. It must also be set before any + * instrumentation probe implementations are assigned. */ - Collection<Probe> findProbesByLine(SourceLineLocation lineLocation); + public abstract void setASTProber(ASTProber astProber); /** - * Sets a trap that will make a callback at any AST location where a existing probe holds a - * specified tag; only one trap may be set at a time. - * - * @throws IllegalStateException if a trap is already set + * Establishes source event reporting */ - void setTrap(PhylumTrap trap) throws IllegalStateException; + protected abstract void setSourceCallback(SourceCallback sourceCallback); - /** - * Clears a trap that will halt execution; only one trap may be set at a time. - * - * @throws IllegalStateException if no trap is set. - */ - void clearTrap() throws IllegalStateException; - - /** - * Access to information visualization services for the specific language. - */ - Visualizer getVisualizer(); }