Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLStatementWrapper.java @ 16595:618d92152d3c
SL: Added support for instrumentation.
author | David Piorkowski <david.piorkowski@oracle.com> |
---|---|
date | Thu, 24 Jul 2014 16:14:44 -0700 |
parents | |
children | 7833417c8172 |
rev | line source |
---|---|
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
1 /* |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
4 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
8 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
14 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
18 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
21 * questions. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
22 */ |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.nodes.instrument; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
24 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.truffle.api.CompilerDirectives.SlowPath; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
26 import com.oracle.truffle.api.frame.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.instrument.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.nodes.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.sl.nodes.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.sl.runtime.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
31 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
32 /** |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
33 * SLStatmentWrapper is a Truffle AST node that gets inserted as the parent to the node that it is |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
34 * wrapping. Any debugging instruments are attached to this wrapper through {@link Probe}s (which |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
35 * themselves contain the instruments). It is through this mechanism that tools can interact |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
36 * directly with the AST. <br/> |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
37 * SLStatmentWrapper specifically wraps {@link SLStatementWrapper}s and overrides the executeVoid |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
38 * function of {@link SLStatementNode} to operate on the child of the wrapper instead of the wrapper |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
39 * itself. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
40 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
41 */ |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
42 public final class SLStatementWrapper extends SLStatementNode implements Wrapper { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
43 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
44 @Child private SLStatementNode child; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
45 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
46 private final Probe probe; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
47 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
48 public SLStatementWrapper(SLContext context, SLStatementNode child) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
49 super(child.getSourceSection()); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
50 assert !(child instanceof SLStatementWrapper); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
51 this.child = insert(child); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
52 this.probe = context.getProbe(child.getSourceSection()); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
53 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
54 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
55 @Override |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
56 public SLStatementNode getNonWrapperNode() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
57 return child; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
58 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
59 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
60 public Node getChild() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
61 return child; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
62 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
63 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
64 public Probe getProbe() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
65 return probe; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
66 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
67 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
68 @SlowPath |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
69 public boolean isTaggedAs(SyntaxTag tag) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
70 return probe.isTaggedAs(tag); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
71 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
72 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
73 @SlowPath |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
74 public Iterable<SyntaxTag> getSyntaxTags() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
75 return probe.getSyntaxTags(); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
76 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
77 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
78 @SlowPath |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
79 public void tagAs(SyntaxTag tag) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
80 probe.tagAs(tag); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
81 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
82 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
83 @Override |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
84 public void executeVoid(VirtualFrame frame) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
85 this.tagAs(StandardSyntaxTag.STATEMENT); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
86 probe.enter(child, frame); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
87 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
88 try { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
89 child.executeVoid(frame); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
90 probe.leave(child, frame); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
91 } catch (KillException e) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
92 throw (e); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
93 } catch (Exception e) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
94 probe.leaveExceptional(child, frame, e); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
95 throw (e); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
96 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
97 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
98 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
99 } |