Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTestNodes.java @ 22214:3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
- introduce the Instrumenter class, held by the TruffleVM to support instrumentation services
- reimplement Probe-realated services (formerly statics in Probe.java) to be provided by the Instrumenter- add new Accessors
- change the TruffleVM startup sequence
- change the APIs of the Debugger and many other classes
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Mon, 14 Sep 2015 22:59:51 -0700 |
parents | 5bc7f7b867ab |
children | 1c0f490984d5 |
comparison
equal
deleted
inserted
replaced
22136:1d804d691dc7 | 22214:3aad794eec0e |
---|---|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | 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 | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.api.test.instrument; | 23 package com.oracle.truffle.api.test.instrument; |
24 | |
25 import java.lang.reflect.*; | |
24 | 26 |
25 import com.oracle.truffle.api.*; | 27 import com.oracle.truffle.api.*; |
26 import com.oracle.truffle.api.frame.*; | 28 import com.oracle.truffle.api.frame.*; |
27 import com.oracle.truffle.api.instrument.*; | 29 import com.oracle.truffle.api.instrument.*; |
28 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; | 30 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; |
29 import com.oracle.truffle.api.nodes.*; | 31 import com.oracle.truffle.api.nodes.*; |
30 import com.oracle.truffle.api.test.TestingLanguage; | 32 import com.oracle.truffle.api.test.TestingLanguage; |
33 import com.oracle.truffle.api.vm.TruffleVM; | |
31 | 34 |
32 /** | 35 /** |
33 * Tests instrumentation where a client can attach a node that gets attached into the AST. | 36 * Tests instrumentation where a client can attach a node that gets attached into the AST. |
34 */ | 37 */ |
35 class InstrumentationTestNodes { | 38 class InstrumentationTestNodes { |
39 | |
40 static Instrumenter createInstrumenter() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | |
41 TruffleVM vm = TruffleVM.newVM().build(); | |
42 final Field field = TruffleVM.class.getDeclaredField("instrumenter"); | |
43 field.setAccessible(true); | |
44 final Instrumenter instrument = (Instrumenter) field.get(vm); | |
45 return instrument; | |
46 } | |
36 | 47 |
37 abstract static class TestLanguageNode extends Node { | 48 abstract static class TestLanguageNode extends Node { |
38 public abstract Object execute(VirtualFrame vFrame); | 49 public abstract Object execute(VirtualFrame vFrame); |
39 | 50 |
40 @Override | 51 @Override |
140 * completes an AST. The root nodes serves as our entry point into a program. | 151 * completes an AST. The root nodes serves as our entry point into a program. |
141 */ | 152 */ |
142 static class TestRootNode extends RootNode { | 153 static class TestRootNode extends RootNode { |
143 @Child private TestLanguageNode body; | 154 @Child private TestLanguageNode body; |
144 | 155 |
156 final Instrumenter instrumenter; | |
157 | |
145 /** | 158 /** |
146 * This constructor emulates the global machinery that applies registered probers to every | 159 * This constructor emulates the global machinery that applies registered probers to every |
147 * newly created AST. Global registry is not used, since that would interfere with other | 160 * newly created AST. Global registry is not used, since that would interfere with other |
148 * tests run in the same environment. | 161 * tests run in the same environment. |
149 */ | 162 */ |
150 public TestRootNode(TestLanguageNode body) { | 163 public TestRootNode(TestLanguageNode body, Instrumenter instrumenter) { |
151 super(TestingLanguage.class, null, null); | 164 super(TestingLanguage.class, null, null); |
165 this.instrumenter = instrumenter; | |
152 this.body = body; | 166 this.body = body; |
153 } | 167 } |
154 | 168 |
155 @Override | 169 @Override |
156 public Object execute(VirtualFrame vFrame) { | 170 public Object execute(VirtualFrame vFrame) { |
162 return true; | 176 return true; |
163 } | 177 } |
164 | 178 |
165 @Override | 179 @Override |
166 public void applyInstrumentation() { | 180 public void applyInstrumentation() { |
167 Probe.applyASTProbers(body); | 181 Method method; |
182 try { | |
183 method = Instrumenter.class.getDeclaredMethod("applyInstrumentation", Node.class); | |
184 method.setAccessible(true); | |
185 method.invoke(instrumenter, body); | |
186 } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | |
187 throw new RuntimeException("InstrumentationTestNodes"); | |
188 } | |
168 } | 189 } |
169 } | 190 } |
170 | 191 |
171 static class TestAdvancedInstrumentCounterRoot extends AdvancedInstrumentRoot { | 192 static class TestAdvancedInstrumentCounterRoot extends AdvancedInstrumentRoot { |
172 | 193 |