Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLStatementWrapperNode.java @ 18485:e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sun, 23 Nov 2014 16:07:23 -0800 |
parents | |
children | d1c1cd2530d7 |
comparison
equal
deleted
inserted
replaced
18484:e97e1f07a3d6 | 18485:e3c95cbbb50c |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.sl.nodes.instrument; | |
24 | |
25 import com.oracle.truffle.api.frame.*; | |
26 import com.oracle.truffle.api.instrument.*; | |
27 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; | |
28 import com.oracle.truffle.api.nodes.*; | |
29 import com.oracle.truffle.sl.nodes.*; | |
30 | |
31 /** | |
32 * A Truffle node that can be inserted into a Simple AST (assumed not to have executed yet) to | |
33 * enable "instrumentation" of a {@link SLStatementNode}. Tools wishing to interact with AST | |
34 * execution may attach {@link Instrument}s to the {@link Probe} uniquely associated with the | |
35 * wrapper, and to which this wrapper routes execution events. | |
36 */ | |
37 @NodeInfo(cost = NodeCost.NONE) | |
38 public final class SLStatementWrapperNode extends SLStatementNode implements WrapperNode { | |
39 | |
40 @Child private SLStatementNode child; | |
41 @Child private ProbeNode probeNode; | |
42 | |
43 public SLStatementWrapperNode(SLStatementNode child) { | |
44 super(child.getSourceSection()); | |
45 assert !(child instanceof SLStatementWrapperNode); | |
46 this.child = child; | |
47 } | |
48 | |
49 public String instrumentationInfo() { | |
50 return "Wrapper node for SL Statements"; | |
51 } | |
52 | |
53 @Override | |
54 public SLStatementNode getNonWrapperNode() { | |
55 return child; | |
56 } | |
57 | |
58 public void insertProbe(ProbeNode newProbeNode) { | |
59 this.probeNode = newProbeNode; | |
60 } | |
61 | |
62 public Probe getProbe() { | |
63 try { | |
64 return probeNode.getProbe(); | |
65 } catch (IllegalStateException e) { | |
66 throw new IllegalStateException("A lite-Probed wrapper has no explicit Probe"); | |
67 } | |
68 } | |
69 | |
70 @Override | |
71 public Node getChild() { | |
72 return child; | |
73 } | |
74 | |
75 @Override | |
76 public void executeVoid(VirtualFrame frame) { | |
77 probeNode.enter(child, frame); | |
78 | |
79 try { | |
80 child.executeVoid(frame); | |
81 probeNode.returnVoid(child, frame); | |
82 } catch (KillException e) { | |
83 throw (e); | |
84 } catch (Exception e) { | |
85 probeNode.returnExceptional(child, frame, e); | |
86 throw (e); | |
87 } | |
88 } | |
89 | |
90 @Override | |
91 public Probe probe() { | |
92 throw new IllegalStateException("Cannot call probe() on a wrapper."); | |
93 } | |
94 | |
95 @Override | |
96 public void probeLite(TruffleEventReceiver eventReceiver) { | |
97 throw new IllegalStateException("Cannot call probeLite() on a wrapper."); | |
98 } | |
99 } |