Mercurial > hg > truffle
view truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLExpressionWrapperNode.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 | dc83cc1f94f2 |
children | 68a0c3dcea10 |
line wrap: on
line source
/* * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 * * Subject to the condition set forth below, permission is hereby granted to any * person obtaining a copy of this software, associated documentation and/or * data (collectively the "Software"), free of charge and under any and all * copyright rights in the Software, and any and all patent rights owned or * freely licensable by each licensor hereunder covering either (i) the * unmodified Software as contributed to or provided by such licensor, or (ii) * the Larger Works (as defined below), to deal in both * * (a) the Software, and * * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if * one is included with the Software each a "Larger Work" to which the Software * is contributed by such licensors), * * without restriction, including without limitation the rights to copy, create * derivative works of, display, perform, and distribute the Software and make, * use, sell, offer for sale, import, export, have made, and have sold the * Software and the Larger Work(s), and to sublicense the foregoing rights on * either these or other terms. * * This license is subject to the following condition: * * The above copyright notice and either this complete permission notice or at a * minimum a reference to the UPL must be included in all copies or substantial * portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package com.oracle.truffle.sl.nodes.instrument; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.instrument.EventHandlerNode; import com.oracle.truffle.api.instrument.Instrument; import com.oracle.truffle.api.instrument.KillException; import com.oracle.truffle.api.instrument.Probe; import com.oracle.truffle.api.instrument.WrapperNode; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.nodes.UnexpectedResultException; import com.oracle.truffle.sl.nodes.SLExpressionNode; import com.oracle.truffle.sl.nodes.SLTypesGen; import com.oracle.truffle.sl.runtime.SLFunction; /** * A Truffle node that can be inserted into a Simple AST (assumed not to have executed yet) to * enable "instrumentation" of an {@link SLExpressionNode}. Tools wishing to interact with AST * execution may attach {@link Instrument}s to the {@link Probe} uniquely associated with the * wrapper, and to which this wrapper routes execution events. */ @NodeInfo(cost = NodeCost.NONE) public final class SLExpressionWrapperNode extends SLExpressionNode implements WrapperNode { @Child private SLExpressionNode child; @Child private EventHandlerNode eventHandlerNode; /** * Constructor. * * @param child The {@link SLExpressionNode} that this wrapper is wrapping */ public SLExpressionWrapperNode(SLExpressionNode child) { super(child.getSourceSection()); assert !(child instanceof SLExpressionWrapperNode); this.child = child; } public String instrumentationInfo() { return "Wrapper node for SL Expressions"; } @Override public boolean isInstrumentable() { return false; } @Override public SLExpressionNode getNonWrapperNode() { return child; } public void insertEventHandlerNode(EventHandlerNode eventHandler) { this.eventHandlerNode = eventHandler; } public Probe getProbe() { return eventHandlerNode.getProbe(); } public Node getChild() { return child; } @Override public Object executeGeneric(VirtualFrame vFrame) { eventHandlerNode.enter(child, vFrame); Object result; try { result = child.executeGeneric(vFrame); eventHandlerNode.returnValue(child, vFrame, result); } catch (KillException e) { throw (e); } catch (Exception e) { eventHandlerNode.returnExceptional(child, vFrame, e); throw (e); } return result; } @Override public long executeLong(VirtualFrame vFrame) throws UnexpectedResultException { return SLTypesGen.expectLong(executeGeneric(vFrame)); } @Override public boolean executeBoolean(VirtualFrame vFrame) throws UnexpectedResultException { return SLTypesGen.expectBoolean(executeGeneric(vFrame)); } @Override public SLFunction executeFunction(VirtualFrame vFrame) throws UnexpectedResultException { eventHandlerNode.enter(child, vFrame); SLFunction result; try { result = child.executeFunction(vFrame); eventHandlerNode.returnValue(child, vFrame, result); } catch (Exception e) { eventHandlerNode.returnExceptional(child, vFrame, e); throw (e); } return result; } }