Mercurial > hg > truffle
diff truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/WrapperNode.java @ 22226:c896a8e70777
Truffle/Instrumentation:
Redesign instrumentation node classes to reduce the public API exposure.
- ProbeNode is no longer public
- Public interface InstrumentationNode.TruffleEvents is now abstract class EventHandlerNode with package private constructor
- Interface ProbeNode.WrapperNode is no longer inside ProbeNode and has been expanded slightly so ProbeNode can be package private
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sun, 20 Sep 2015 15:51:39 -0700 |
parents | |
children | c1c9c6d79f40 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/WrapperNode.java Sun Sep 20 15:51:39 2015 -0700 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2013, 2015, 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.TruffleLanguage; +import com.oracle.truffle.api.nodes.Node; + +/** + * A {@link Node} instance that must be inserted into a Truffle AST in order to enable + * {@linkplain Instrument instrumentation} at a particular Guest Language (GL) node. Implementations + * must ensure that {@link TruffleLanguage#isInstrumentable(Node)} returns {@code false}. + * <p> + * The implementation must be GL-specific. A wrapper <em>decorates</em> a GL AST node (the wrapper's + * <em>child</em>) by acting as a transparent <em>proxy</em> with respect to the GL's execution + * semantics. + * <p> + * Instrumentation at the wrapped node is implemented by an instance of {@link EventHandlerNode} + * attached as a second child of the {@link WrapperNode}. + * <p> + * A wrapper is obliged to notify its attached {@link EventHandlerNode} when execution events occur + * at the wrapped AST node during program execution. + * <p> + * When a GL AST is cloned, the {@link WrapperNode}, its {@link EventHandlerNode} and any + * {@linkplain Instrument instrumentation} are also cloned; they are in effect part of the GL AST. + * An instance of {@link Probe} represents abstractly the instrumentation at a particular location + * in a GL AST; it tracks all the copies of the Wrapper and attached instrumentation, and acts as a + * single point of access for tools. + * <p> + * Implementation guidelines: + * <ol> + * <li>Each GL implementation must implement a WrapperNode implementation for each AST context in + * which Instrumentation is to be supported.</li> + * <li>The wrapper type should descend from the <em>GL-specific node class</em>.</li> + * <li>Must have a field: {@code @Child private <GL>Node child;}</li> + * <li>Must have a field: {@code @Child private EventHandlerNode eventHandlerNode;}</li> + * <li>The wrapper must act as a <em>proxy</em> for its child, which means implementing every + * possible <em>execute-</em> method that gets called on guest language AST node types by their + * parents, and passing along each call to its child.</li> + * <li>Method {@code Probe getProbe()} should be implemented as {@code eventHandlerNode.getProbe();} + * <li>Method {@code insertProbe(EventHandlerNode)} should be implemented as + * {@code this.eventHandlerNode=insert(eventHandlerNode);}</li> + * <li>Most importantly, Wrappers must be implemented so that Truffle optimization will reduce their + * runtime overhead to zero when there are no attached {@link Instrument}s.</li> + * </ol> + * <p> + * + * @see Instrument + */ +public interface WrapperNode extends InstrumentationNode { + + /** + * Gets the node being "wrapped", i.e. the AST node for which + * {@linkplain InstrumentationNode.EventHandlerNode execution events} will be reported through + * the Instrumentation Framework. + */ + Node getChild(); + + /** + * Gets the {@link Probe} responsible for installing this wrapper. + */ + Probe getProbe(); + + /** + * Implementation support for completing a newly created wrapper node. + */ + void insertEventHandlerNode(EventHandlerNode eventHandlerNode); +}