comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/InitializationTest.java @ 22110:c2cb9f1c8688

Replacing the langClass.newInstance() hack in Debugger with proper way to obtain the language instance
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 26 Aug 2015 15:22:31 +0200
parents b5eaddcdf86a
children dc83cc1f94f2 ffadd23c63c8 3aad794eec0e
comparison
equal deleted inserted replaced
22109:b5eaddcdf86a 22110:c2cb9f1c8688
35 import com.oracle.truffle.api.debug.ExecutionEvent; 35 import com.oracle.truffle.api.debug.ExecutionEvent;
36 import com.oracle.truffle.api.frame.*; 36 import com.oracle.truffle.api.frame.*;
37 import com.oracle.truffle.api.instrument.*; 37 import com.oracle.truffle.api.instrument.*;
38 import com.oracle.truffle.api.nodes.*; 38 import com.oracle.truffle.api.nodes.*;
39 import com.oracle.truffle.api.source.Source; 39 import com.oracle.truffle.api.source.Source;
40 import com.oracle.truffle.api.source.SourceSection;
40 import com.oracle.truffle.api.vm.EventConsumer; 41 import com.oracle.truffle.api.vm.EventConsumer;
41 import com.oracle.truffle.api.vm.TruffleVM; 42 import com.oracle.truffle.api.vm.TruffleVM;
42 import java.io.IOException; 43 import java.io.IOException;
43 44
44 /** 45 /**
45 * Bug report validating test. 46 * Bug report validating test.
46 * <p> 47 * <p>
47 * It has been reported that calling {@link Env#importSymbol(java.lang.String)} in 48 * It has been reported that calling {@link Env#importSymbol(java.lang.String)} in
48 * {@link TruffleLanguage TruffleLanguage.createContext(env)} yields a {@link NullPointerException}. 49 * {@link TruffleLanguage TruffleLanguage.createContext(env)} yields a {@link NullPointerException}.
49 * <p> 50 * <p>
51 * The other report was related to specifying an abstract language class in the RootNode and
52 * problems with debugging later on. That is what the other part of this test - once it obtains
53 * Debugger instance simulates.
50 */ 54 */
51 public class InitializationTest { 55 public class InitializationTest {
52 @Test 56 @Test
53 public void accessProbeForAbstractLanguage() throws IOException { 57 public void accessProbeForAbstractLanguage() throws IOException {
54 final Debugger[] arr = {null}; 58 final Debugger[] arr = {null};
63 67
64 vm.eval(source); 68 vm.eval(source);
65 69
66 assertNotNull("Debugger found", arr[0]); 70 assertNotNull("Debugger found", arr[0]);
67 71
68 Debugger d = arr[0]; 72 try {
69 Breakpoint b = d.setLineBreakpoint(0, source.createLineLocation(1), true); 73 Debugger d = arr[0];
70 b.setCondition("true"); 74 Breakpoint b = d.setLineBreakpoint(0, source.createLineLocation(1), true);
71 75 assertTrue(b.isEnabled());
72 vm.eval(source); 76 b.setCondition("true");
77
78 vm.eval(source);
79 } catch (InstrumentOKException ex) {
80 // OK
81 return;
82 }
83 fail("We should properly call up to TestLanguage.createAdvancedInstrumentRootFactory");
73 } 84 }
74 85
75 private static final class MMRootNode extends RootNode { 86 private static final class MMRootNode extends RootNode {
76 @Child ANode node; 87 @Child ANode node;
77 88
78 MMRootNode() { 89 MMRootNode(SourceSection ss) {
79 super(AbstractLanguage.class, null, null); 90 super(AbstractLanguage.class, ss, null);
80 node = new ANode(42); 91 node = new ANode(42);
92 adoptChildren();
93 node.probe().tagAs(StandardSyntaxTag.STATEMENT, this);
81 } 94 }
82 95
83 @Override 96 @Override
84 public Object execute(VirtualFrame frame) { 97 public Object execute(VirtualFrame frame) {
85 return node.constant(); 98 return node.constant();
86 } 99 }
87 } 100 }
88 101
89 private static final class ANode extends Node { 102 private static class ANode extends Node {
90 private final int constant; 103 private final int constant;
91 104
92 public ANode(int constant) { 105 public ANode(int constant) {
93 this.constant = constant; 106 this.constant = constant;
107 }
108
109 @Override
110 public SourceSection getSourceSection() {
111 return getRootNode().getSourceSection();
112 }
113
114 @Override
115 public boolean isInstrumentable() {
116 return true;
117 }
118
119 @Override
120 public ProbeNode.WrapperNode createWrapperNode() {
121 class WN extends ANode implements ProbeNode.WrapperNode {
122 private ProbeNode probeNode;
123
124 public WN(int constant) {
125 super(constant);
126 }
127
128 @Override
129 public Node getChild() {
130 return ANode.this;
131 }
132
133 @Override
134 public Probe getProbe() {
135 return probeNode.getProbe();
136 }
137
138 @Override
139 public void insertProbe(ProbeNode pn) {
140 this.probeNode = pn;
141 }
142
143 @Override
144 public String instrumentationInfo() {
145 throw new UnsupportedOperationException();
146 }
147 }
148 return new WN(constant);
94 } 149 }
95 150
96 Object constant() { 151 Object constant() {
97 return constant; 152 return constant;
98 } 153 }
112 return env; 167 return env;
113 } 168 }
114 169
115 @Override 170 @Override
116 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { 171 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
117 return Truffle.getRuntime().createCallTarget(new MMRootNode()); 172 return Truffle.getRuntime().createCallTarget(new MMRootNode(code.createSection("1st line", 1)));
118 } 173 }
119 174
120 @Override 175 @Override
121 protected Object findExportedSymbol(Object context, String globalName, boolean onlyExplicit) { 176 protected Object findExportedSymbol(Object context, String globalName, boolean onlyExplicit) {
122 return null; 177 return null;
147 throw new UnsupportedOperationException(); 202 throw new UnsupportedOperationException();
148 } 203 }
149 204
150 @Override 205 @Override
151 public AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws DebugSupportException { 206 public AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws DebugSupportException {
152 throw new UnsupportedOperationException(); 207 throw new InstrumentOKException();
153 } 208 }
154 209
155 @Override 210 @Override
156 public Visualizer getVisualizer() { 211 public Visualizer getVisualizer() {
157 throw new UnsupportedOperationException(); 212 throw new UnsupportedOperationException();
160 @Override 215 @Override
161 public void enableASTProbing(ASTProber astProber) { 216 public void enableASTProbing(ASTProber astProber) {
162 throw new UnsupportedOperationException(); 217 throw new UnsupportedOperationException();
163 } 218 }
164 } 219 }
220
221 private static final class InstrumentOKException extends RuntimeException {
222 static final long serialVersionUID = 1L;
223 }
165 } 224 }