view graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Probe.java @ 15605:bb9473723904

Truffle/Instrumentation: - Merge instrumentation support into the general execution context; remove separate Instrumentation interface and implementation - Generalize the ?tagging? mechanism for extensibility: the enum PhylumTag is now an interface, and the standard tags moved to the new enum StandardTag - A new ?trap? mechanism interrupts program execution at any probed node holding a specified PhylumTag; this replaces some other special-purpose code. - Refine several interface by factoring out callback methods and simplifying collaboration among key implementation classes.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Mon, 12 May 2014 20:17:25 -0700
parents 0c6d8a08e31b
children 8c34e2cc4add
line wrap: on
line source

/*
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package com.oracle.truffle.api.instrument;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.*;

/**
 * A collector of {@link ExecutionEvents} at a specific site (node) in a Truffle AST (generated by a
 * {@link Wrapper} inserted into the AST) for the purpose of <em>instrumentation</em>. For probes
 * associated with programmer-facing tools, there should be no more than one probe associated with a
 * particular piece of source code syntax (i.e. a {@link SourceSection}).
 * <p>
 * Any {@linkplain PhylumTag tags} associated with a particular piece of source code syntax are
 * managed by the probe.
 * <p>
 * When ASTs are copied, it is presumed that the probe for a site is shared by all AST nodes
 * representing that site.
 * <p>
 * A probe holds zero or more {@link Instrument}s, which can be added and removed dynamically.
 * Events reported to a probe are propagated to every attached instrument; the order is undefined.
 * <p>
 * Probe methods must be amenable to Truffle/Graal inlining on the assumption that the collection of
 * attached instruments seldom changes. The assumption is invalidated when instruments are added or
 * removed, but some instruments may change their internal state in such a way that the assumption
 * should also be invalidated.
 * <p>
 * <strong>Disclaimer:</strong> experimental interface under development. In particular, the
 * <em>notify</em> methods must be migrated to another interface.
 *
 * @see Instrument
 * @see Wrapper
 */
public interface Probe extends PhylumTagged {

    /**
     * The source location with which this probe is (presumably uniquely) associated.
     */
    SourceSection getSourceLocation();

    /**
     * Mark this probe as being associated with an AST node in some category useful for debugging
     * and other tools.
     */
    void tagAs(PhylumTag tag);

    /**
     * Adds an instrument to this probe.
     */
    void addInstrument(Instrument newInstrument);

    /**
     * Removes an instrument from this probe.
     */
    void removeInstrument(Instrument oldInstrument);

    // TODO (mlvdv) migrate the remaining methods to another interface.

    /**
     * @see ExecutionEvents#enter(Node, VirtualFrame)
     */
    void notifyEnter(Node astNode, VirtualFrame frame);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame)
     */
    void notifyLeave(Node astNode, VirtualFrame frame);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, boolean)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, boolean result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, byte)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, byte result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, short)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, short result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, int)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, int result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, long)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, long result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, char)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, char result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, float)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, float result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, double)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, double result);

    /**
     * @see ExecutionEvents#leave(Node, VirtualFrame, Object)
     */
    void notifyLeave(Node astNode, VirtualFrame frame, Object result);

    /**
     * @see ExecutionEvents#leaveExceptional(Node, VirtualFrame, Exception)
     */
    void notifyLeaveExceptional(Node astNode, VirtualFrame frame, Exception e);

}