diff 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
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/InitializationTest.java	Wed Aug 26 14:13:43 2015 +0200
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/InitializationTest.java	Wed Aug 26 15:22:31 2015 +0200
@@ -37,6 +37,7 @@
 import com.oracle.truffle.api.instrument.*;
 import com.oracle.truffle.api.nodes.*;
 import com.oracle.truffle.api.source.Source;
+import com.oracle.truffle.api.source.SourceSection;
 import com.oracle.truffle.api.vm.EventConsumer;
 import com.oracle.truffle.api.vm.TruffleVM;
 import java.io.IOException;
@@ -47,6 +48,9 @@
  * It has been reported that calling {@link Env#importSymbol(java.lang.String)} in
  * {@link TruffleLanguage TruffleLanguage.createContext(env)} yields a {@link NullPointerException}.
  * <p>
+ * The other report was related to specifying an abstract language class in the RootNode and
+ * problems with debugging later on. That is what the other part of this test - once it obtains
+ * Debugger instance simulates.
  */
 public class InitializationTest {
     @Test
@@ -65,19 +69,28 @@
 
         assertNotNull("Debugger found", arr[0]);
 
-        Debugger d = arr[0];
-        Breakpoint b = d.setLineBreakpoint(0, source.createLineLocation(1), true);
-        b.setCondition("true");
+        try {
+            Debugger d = arr[0];
+            Breakpoint b = d.setLineBreakpoint(0, source.createLineLocation(1), true);
+            assertTrue(b.isEnabled());
+            b.setCondition("true");
 
-        vm.eval(source);
+            vm.eval(source);
+        } catch (InstrumentOKException ex) {
+            // OK
+            return;
+        }
+        fail("We should properly call up to TestLanguage.createAdvancedInstrumentRootFactory");
     }
 
     private static final class MMRootNode extends RootNode {
         @Child ANode node;
 
-        MMRootNode() {
-            super(AbstractLanguage.class, null, null);
+        MMRootNode(SourceSection ss) {
+            super(AbstractLanguage.class, ss, null);
             node = new ANode(42);
+            adoptChildren();
+            node.probe().tagAs(StandardSyntaxTag.STATEMENT, this);
         }
 
         @Override
@@ -86,13 +99,55 @@
         }
     }
 
-    private static final class ANode extends Node {
+    private static class ANode extends Node {
         private final int constant;
 
         public ANode(int constant) {
             this.constant = constant;
         }
 
+        @Override
+        public SourceSection getSourceSection() {
+            return getRootNode().getSourceSection();
+        }
+
+        @Override
+        public boolean isInstrumentable() {
+            return true;
+        }
+
+        @Override
+        public ProbeNode.WrapperNode createWrapperNode() {
+            class WN extends ANode implements ProbeNode.WrapperNode {
+                private ProbeNode probeNode;
+
+                public WN(int constant) {
+                    super(constant);
+                }
+
+                @Override
+                public Node getChild() {
+                    return ANode.this;
+                }
+
+                @Override
+                public Probe getProbe() {
+                    return probeNode.getProbe();
+                }
+
+                @Override
+                public void insertProbe(ProbeNode pn) {
+                    this.probeNode = pn;
+                }
+
+                @Override
+                public String instrumentationInfo() {
+                    throw new UnsupportedOperationException();
+                }
+            }
+            return new WN(constant);
+        }
+
         Object constant() {
             return constant;
         }
@@ -114,7 +169,7 @@
 
         @Override
         protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
-            return Truffle.getRuntime().createCallTarget(new MMRootNode());
+            return Truffle.getRuntime().createCallTarget(new MMRootNode(code.createSection("1st line", 1)));
         }
 
         @Override
@@ -149,7 +204,7 @@
 
         @Override
         public AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws DebugSupportException {
-            throw new UnsupportedOperationException();
+            throw new InstrumentOKException();
         }
 
         @Override
@@ -162,4 +217,8 @@
             throw new UnsupportedOperationException();
         }
     }
+
+    private static final class InstrumentOKException extends RuntimeException {
+        static final long serialVersionUID = 1L;
+    }
 }