Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTestNodes.java @ 22219:1c0f490984d5
Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 15:36:22 -0700 |
parents | dc83cc1f94f2 3aad794eec0e |
children | 20380d1d41f2 |
comparison
equal
deleted
inserted
replaced
22160:0599e2df6a9f | 22219:1c0f490984d5 |
---|---|
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 | 24 |
25 import java.lang.reflect.Field; | |
26 import java.lang.reflect.InvocationTargetException; | |
27 import java.lang.reflect.Method; | |
28 | |
25 import com.oracle.truffle.api.CallTarget; | 29 import com.oracle.truffle.api.CallTarget; |
26 import com.oracle.truffle.api.frame.VirtualFrame; | 30 import com.oracle.truffle.api.frame.VirtualFrame; |
27 import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot; | 31 import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot; |
32 import com.oracle.truffle.api.instrument.Instrumenter; | |
28 import com.oracle.truffle.api.instrument.KillException; | 33 import com.oracle.truffle.api.instrument.KillException; |
29 import com.oracle.truffle.api.instrument.Probe; | 34 import com.oracle.truffle.api.instrument.Probe; |
30 import com.oracle.truffle.api.instrument.ProbeNode; | 35 import com.oracle.truffle.api.instrument.ProbeNode; |
31 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; | 36 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; |
32 import com.oracle.truffle.api.nodes.Node; | 37 import com.oracle.truffle.api.nodes.Node; |
33 import com.oracle.truffle.api.nodes.NodeCost; | 38 import com.oracle.truffle.api.nodes.NodeCost; |
34 import com.oracle.truffle.api.nodes.NodeInfo; | 39 import com.oracle.truffle.api.nodes.NodeInfo; |
35 import com.oracle.truffle.api.nodes.RootNode; | 40 import com.oracle.truffle.api.nodes.RootNode; |
36 import com.oracle.truffle.api.test.TestingLanguage; | 41 import com.oracle.truffle.api.test.TestingLanguage; |
42 import com.oracle.truffle.api.vm.TruffleVM; | |
37 | 43 |
38 /** | 44 /** |
39 * Tests instrumentation where a client can attach a node that gets attached into the AST. | 45 * Tests instrumentation where a client can attach a node that gets attached into the AST. |
40 */ | 46 */ |
41 class InstrumentationTestNodes { | 47 class InstrumentationTestNodes { |
48 | |
49 static Instrumenter createInstrumenter() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | |
50 TruffleVM vm = TruffleVM.newVM().build(); | |
51 final Field field = TruffleVM.class.getDeclaredField("instrumenter"); | |
52 field.setAccessible(true); | |
53 final Instrumenter instrument = (Instrumenter) field.get(vm); | |
54 return instrument; | |
55 } | |
42 | 56 |
43 abstract static class TestLanguageNode extends Node { | 57 abstract static class TestLanguageNode extends Node { |
44 public abstract Object execute(VirtualFrame vFrame); | 58 public abstract Object execute(VirtualFrame vFrame); |
45 | 59 |
46 @Override | 60 @Override |
146 * completes an AST. The root nodes serves as our entry point into a program. | 160 * completes an AST. The root nodes serves as our entry point into a program. |
147 */ | 161 */ |
148 static class TestRootNode extends RootNode { | 162 static class TestRootNode extends RootNode { |
149 @Child private TestLanguageNode body; | 163 @Child private TestLanguageNode body; |
150 | 164 |
165 final Instrumenter instrumenter; | |
166 | |
151 /** | 167 /** |
152 * This constructor emulates the global machinery that applies registered probers to every | 168 * This constructor emulates the global machinery that applies registered probers to every |
153 * newly created AST. Global registry is not used, since that would interfere with other | 169 * newly created AST. Global registry is not used, since that would interfere with other |
154 * tests run in the same environment. | 170 * tests run in the same environment. |
155 */ | 171 */ |
156 public TestRootNode(TestLanguageNode body) { | 172 public TestRootNode(TestLanguageNode body, Instrumenter instrumenter) { |
157 super(TestingLanguage.class, null, null); | 173 super(TestingLanguage.class, null, null); |
174 this.instrumenter = instrumenter; | |
158 this.body = body; | 175 this.body = body; |
159 } | 176 } |
160 | 177 |
161 @Override | 178 @Override |
162 public Object execute(VirtualFrame vFrame) { | 179 public Object execute(VirtualFrame vFrame) { |
168 return true; | 185 return true; |
169 } | 186 } |
170 | 187 |
171 @Override | 188 @Override |
172 public void applyInstrumentation() { | 189 public void applyInstrumentation() { |
173 Probe.applyASTProbers(body); | 190 Method method; |
191 try { | |
192 method = Instrumenter.class.getDeclaredMethod("applyInstrumentation", Node.class); | |
193 method.setAccessible(true); | |
194 method.invoke(instrumenter, body); | |
195 } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | |
196 throw new RuntimeException("InstrumentationTestNodes"); | |
197 } | |
174 } | 198 } |
175 } | 199 } |
176 | 200 |
177 static class TestAdvancedInstrumentCounterRoot extends AdvancedInstrumentRoot { | 201 static class TestAdvancedInstrumentCounterRoot extends AdvancedInstrumentRoot { |
178 | 202 |