Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/InitializationTest.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 d3bdaa91bc82 |
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.vm; | 23 package com.oracle.truffle.api.test.vm; |
24 | 24 |
25 import static org.junit.Assert.assertNotNull; | |
26 import static org.junit.Assert.assertNull; | |
27 import static org.junit.Assert.assertTrue; | |
28 import static org.junit.Assert.fail; | |
29 | |
30 import java.io.IOException; | |
31 | |
32 import org.junit.Test; | |
33 | |
25 import com.oracle.truffle.api.CallTarget; | 34 import com.oracle.truffle.api.CallTarget; |
26 import com.oracle.truffle.api.Truffle; | 35 import com.oracle.truffle.api.Truffle; |
27 import com.oracle.truffle.api.TruffleLanguage; | 36 import com.oracle.truffle.api.TruffleLanguage; |
28 import com.oracle.truffle.api.TruffleLanguage.Env; | 37 import com.oracle.truffle.api.TruffleLanguage.Env; |
29 import com.oracle.truffle.api.debug.Breakpoint; | 38 import com.oracle.truffle.api.debug.Breakpoint; |
30 import com.oracle.truffle.api.debug.DebugSupportException; | |
31 import com.oracle.truffle.api.debug.DebugSupportProvider; | 39 import com.oracle.truffle.api.debug.DebugSupportProvider; |
32 import com.oracle.truffle.api.debug.Debugger; | 40 import com.oracle.truffle.api.debug.Debugger; |
33 import com.oracle.truffle.api.debug.ExecutionEvent; | 41 import com.oracle.truffle.api.debug.ExecutionEvent; |
34 import com.oracle.truffle.api.frame.MaterializedFrame; | 42 import com.oracle.truffle.api.frame.MaterializedFrame; |
35 import com.oracle.truffle.api.frame.VirtualFrame; | 43 import com.oracle.truffle.api.frame.VirtualFrame; |
36 import com.oracle.truffle.api.instrument.ASTProber; | 44 import com.oracle.truffle.api.instrument.ASTProber; |
37 import com.oracle.truffle.api.instrument.AdvancedInstrumentResultListener; | 45 import com.oracle.truffle.api.instrument.AdvancedInstrumentResultListener; |
38 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; | 46 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; |
47 import com.oracle.truffle.api.instrument.Instrumenter; | |
39 import com.oracle.truffle.api.instrument.Probe; | 48 import com.oracle.truffle.api.instrument.Probe; |
40 import com.oracle.truffle.api.instrument.ProbeNode; | 49 import com.oracle.truffle.api.instrument.ProbeNode; |
41 import com.oracle.truffle.api.instrument.StandardSyntaxTag; | 50 import com.oracle.truffle.api.instrument.StandardSyntaxTag; |
42 import com.oracle.truffle.api.instrument.ToolSupportProvider; | 51 import com.oracle.truffle.api.instrument.ToolSupportProvider; |
43 import com.oracle.truffle.api.instrument.Visualizer; | 52 import com.oracle.truffle.api.instrument.Visualizer; |
44 import com.oracle.truffle.api.nodes.Node; | 53 import com.oracle.truffle.api.nodes.Node; |
54 import com.oracle.truffle.api.nodes.NodeVisitor; | |
45 import com.oracle.truffle.api.nodes.RootNode; | 55 import com.oracle.truffle.api.nodes.RootNode; |
46 import com.oracle.truffle.api.source.Source; | 56 import com.oracle.truffle.api.source.Source; |
47 import com.oracle.truffle.api.source.SourceSection; | 57 import com.oracle.truffle.api.source.SourceSection; |
48 import com.oracle.truffle.api.vm.EventConsumer; | 58 import com.oracle.truffle.api.vm.EventConsumer; |
49 import com.oracle.truffle.api.vm.TruffleVM; | 59 import com.oracle.truffle.api.vm.TruffleVM; |
50 import java.io.IOException; | |
51 import static org.junit.Assert.assertNotNull; | |
52 import static org.junit.Assert.assertNull; | |
53 import static org.junit.Assert.assertTrue; | |
54 import static org.junit.Assert.fail; | |
55 import org.junit.Test; | |
56 | 60 |
57 /** | 61 /** |
58 * Bug report validating test. | 62 * Bug report validating test. |
59 * <p> | 63 * <p> |
60 * It has been reported that calling {@link Env#importSymbol(java.lang.String)} in | 64 * It has been reported that calling {@link Env#importSymbol(java.lang.String)} in |
100 | 104 |
101 MMRootNode(SourceSection ss) { | 105 MMRootNode(SourceSection ss) { |
102 super(AbstractLanguage.class, ss, null); | 106 super(AbstractLanguage.class, ss, null); |
103 node = new ANode(42); | 107 node = new ANode(42); |
104 adoptChildren(); | 108 adoptChildren(); |
105 node.probe().tagAs(StandardSyntaxTag.STATEMENT, this); | |
106 } | 109 } |
107 | 110 |
108 @Override | 111 @Override |
109 public Object execute(VirtualFrame frame) { | 112 public Object execute(VirtualFrame frame) { |
110 return node.constant(); | 113 return node.constant(); |
111 } | 114 } |
115 | |
116 @Override | |
117 public void applyInstrumentation() { | |
118 super.applyInstrumentation(node); | |
119 } | |
112 } | 120 } |
113 | 121 |
114 private static class ANode extends Node { | 122 private static class ANode extends Node { |
115 private final int constant; | 123 private final int constant; |
116 | 124 |
128 return true; | 136 return true; |
129 } | 137 } |
130 | 138 |
131 @Override | 139 @Override |
132 public ProbeNode.WrapperNode createWrapperNode() { | 140 public ProbeNode.WrapperNode createWrapperNode() { |
133 class WN extends ANode implements ProbeNode.WrapperNode { | 141 return new ANodeWrapper(this); |
134 private ProbeNode probeNode; | |
135 | |
136 public WN(int constant) { | |
137 super(constant); | |
138 } | |
139 | |
140 @Override | |
141 public Node getChild() { | |
142 return ANode.this; | |
143 } | |
144 | |
145 @Override | |
146 public Probe getProbe() { | |
147 return probeNode.getProbe(); | |
148 } | |
149 | |
150 @Override | |
151 public void insertProbe(ProbeNode pn) { | |
152 this.probeNode = pn; | |
153 } | |
154 | |
155 @Override | |
156 public String instrumentationInfo() { | |
157 throw new UnsupportedOperationException(); | |
158 } | |
159 } | |
160 return new WN(constant); | |
161 } | 142 } |
162 | 143 |
163 Object constant() { | 144 Object constant() { |
164 return constant; | 145 return constant; |
165 } | 146 } |
166 | 147 |
148 } | |
149 | |
150 private static class ANodeWrapper extends ANode implements ProbeNode.WrapperNode { | |
151 @Child ANode child; | |
152 private ProbeNode probeNode; | |
153 | |
154 ANodeWrapper(ANode node) { | |
155 super(1); // dummy | |
156 this.child = node; | |
157 } | |
158 | |
159 @Override | |
160 public Node getChild() { | |
161 return child; | |
162 } | |
163 | |
164 @Override | |
165 public Probe getProbe() { | |
166 return probeNode.getProbe(); | |
167 } | |
168 | |
169 @Override | |
170 public void insertProbe(ProbeNode pn) { | |
171 this.probeNode = pn; | |
172 } | |
173 | |
174 @Override | |
175 public String instrumentationInfo() { | |
176 throw new UnsupportedOperationException(); | |
177 } | |
167 } | 178 } |
168 | 179 |
169 private abstract static class AbstractLanguage extends TruffleLanguage<Object> { | 180 private abstract static class AbstractLanguage extends TruffleLanguage<Object> { |
170 } | 181 } |
171 | 182 |
172 @TruffleLanguage.Registration(mimeType = "application/x-abstrlang", name = "AbstrLang", version = "0.1") | 183 @TruffleLanguage.Registration(mimeType = "application/x-abstrlang", name = "AbstrLang", version = "0.1") |
173 public static final class TestLanguage extends AbstractLanguage implements DebugSupportProvider { | 184 public static final class TestLanguage extends AbstractLanguage implements DebugSupportProvider { |
174 public static final TestLanguage INSTANCE = new TestLanguage(); | 185 public static final TestLanguage INSTANCE = new TestLanguage(); |
175 | 186 |
187 private final ASTProber prober = new ASTProber() { | |
188 | |
189 public void probeAST(final Instrumenter instrumenter, Node startNode) { | |
190 startNode.accept(new NodeVisitor() { | |
191 | |
192 public boolean visit(Node node) { | |
193 | |
194 if (node instanceof ANode) { | |
195 instrumenter.probe(node).tagAs(StandardSyntaxTag.STATEMENT, null); | |
196 } | |
197 return true; | |
198 } | |
199 }); | |
200 } | |
201 }; | |
202 | |
176 @Override | 203 @Override |
177 protected Object createContext(Env env) { | 204 protected Object createContext(Env env) { |
178 assertNull("Not defined symbol", env.importSymbol("unknown")); | 205 assertNull("Not defined symbol", env.importSymbol("unknown")); |
179 return env; | 206 return env; |
180 } | 207 } |
197 @Override | 224 @Override |
198 protected boolean isObjectOfLanguage(Object object) { | 225 protected boolean isObjectOfLanguage(Object object) { |
199 throw new UnsupportedOperationException(); | 226 throw new UnsupportedOperationException(); |
200 } | 227 } |
201 | 228 |
229 @SuppressWarnings("deprecation") | |
202 @Override | 230 @Override |
203 protected ToolSupportProvider getToolSupport() { | 231 protected ToolSupportProvider getToolSupport() { |
204 throw new UnsupportedOperationException(); | 232 throw new UnsupportedOperationException(); |
205 } | 233 } |
206 | 234 |
235 @SuppressWarnings("deprecation") | |
207 @Override | 236 @Override |
208 protected DebugSupportProvider getDebugSupport() { | 237 protected DebugSupportProvider getDebugSupport() { |
209 return this; | 238 throw new UnsupportedOperationException(); |
210 } | 239 } |
211 | 240 |
212 @Override | 241 @Override |
213 public Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws DebugSupportException { | 242 public Object evalInContext(Source source, Node node, MaterializedFrame mFrame) { |
214 throw new UnsupportedOperationException(); | 243 throw new UnsupportedOperationException(); |
215 } | 244 } |
216 | 245 |
217 @Override | 246 @Override |
218 public AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws DebugSupportException { | 247 public AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) { |
219 throw new InstrumentOKException(); | 248 throw new InstrumentOKException(); |
220 } | 249 } |
221 | 250 |
222 @Override | 251 @Override |
223 public Visualizer getVisualizer() { | 252 public Visualizer getVisualizer() { |
224 throw new UnsupportedOperationException(); | 253 throw new UnsupportedOperationException(); |
225 } | 254 } |
226 | 255 |
256 @Override | |
257 protected ASTProber getDefaultASTProber() { | |
258 return prober; | |
259 } | |
260 | |
261 @SuppressWarnings("deprecation") | |
227 @Override | 262 @Override |
228 public void enableASTProbing(ASTProber astProber) { | 263 public void enableASTProbing(ASTProber astProber) { |
229 throw new UnsupportedOperationException(); | 264 throw new UnsupportedOperationException(); |
230 } | 265 } |
231 } | 266 } |