changeset 20910:0b2e4d40b683

Truffle/Instrumentation: test code renaming and cleanup for the new kind of instrument, now known as a SpliceInstrument.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Mon, 13 Apr 2015 16:19:41 -0700
parents f96165ecb6f1
children 518ce9a36939
files graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTestNodes.java graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/SpliceInstrumentTest.java graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/ToolNodeInstrumentationTest.java
diffstat 4 files changed, 109 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java	Mon Apr 13 15:33:45 2015 -0700
+++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/InstrumentationPartialEvaluationTest.java	Mon Apr 13 16:19:41 2015 -0700
@@ -205,13 +205,13 @@
     }
 
     @Test
-    public void constantValueInertToolNodeInstrumentListener() {
+    public void constantValueInertSpliceInstrumentListener() {
         FrameDescriptor fd = new FrameDescriptor();
         AbstractTestNode result = new ConstantTestNode(42);
         RootTestNode root = new RootTestNode(fd, "constantValue", result);
         root.adoptChildren();
         Probe probe = result.probe();
-        // A listener that could insert a "tool node" into the AST, but which never does.
+        // A listener that could insert a SplicedNode into the AST, but which never does.
         Instrument instrument = Instrument.create(new SpliceInstrumentListener() {
 
             public SplicedNode getSpliceNode(Probe p) {
@@ -221,17 +221,18 @@
         }, null);
         probe.attach(instrument);
 
+        // It all gets compiled away
         assertPartialEvalEquals("constant42", root);
     }
 
     @Test
-    public void constantValueInertToolNode() {
+    public void constantValueInertSplicedNode() {
         FrameDescriptor fd = new FrameDescriptor();
         AbstractTestNode result = new ConstantTestNode(42);
         RootTestNode root = new RootTestNode(fd, "constantValue", result);
         root.adoptChildren();
         Probe probe = result.probe();
-        // A listener that inserts a "tool node" with empty methods into the AST.
+        // A listener that inserts a SplicedNode with empty methods into the AST.
         Instrument instrument = Instrument.create(new SpliceInstrumentListener() {
 
             public SplicedNode getSpliceNode(Probe p) {
@@ -242,6 +243,7 @@
         }, null);
         probe.attach(instrument);
 
+        // It all gets compiled away.
         assertPartialEvalEquals("constant42", root);
     }
 
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTestNodes.java	Mon Apr 13 15:33:45 2015 -0700
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTestNodes.java	Mon Apr 13 16:19:41 2015 -0700
@@ -86,7 +86,6 @@
         public Object execute(VirtualFrame vFrame) {
             probeNode.enter(child, vFrame);
             Object result;
-
             try {
                 result = child.execute(vFrame);
                 probeNode.returnValue(child, vFrame, result);
@@ -96,7 +95,6 @@
                 probeNode.returnExceptional(child, vFrame, e);
                 throw (e);
             }
-
             return result;
         }
     }
@@ -169,4 +167,17 @@
         }
     }
 
+    static class TestSplicedCounterNode extends SplicedNode {
+
+        private long count;
+
+        @Override
+        public void enter(Node node, VirtualFrame vFrame) {
+            count++;
+        }
+
+        public long getCount() {
+            return count;
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/SpliceInstrumentTest.java	Mon Apr 13 16:19:41 2015 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.api.test.instrument;
+
+import static org.junit.Assert.*;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.instrument.*;
+import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdditionNode;
+import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestRootNode;
+import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestValueNode;
+import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestSplicedCounterNode;
+
+/**
+ * Tests the kind of instrumentation where a client can provide an AST fragment to be
+ * <em>spliced</em> directly into the AST.
+ */
+public class SpliceInstrumentTest {
+
+    @Test
+    public void testSpliceInstrumentListener() {
+        // Create a simple addition AST
+        final TruffleRuntime runtime = Truffle.getRuntime();
+        final TestValueNode leftValueNode = new TestValueNode(6);
+        final TestValueNode rightValueNode = new TestValueNode(7);
+        final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode);
+        final TestRootNode rootNode = new TestRootNode(addNode);
+        final CallTarget callTarget1 = runtime.createCallTarget(rootNode);
+
+        // Ensure it executes correctly
+        assertEquals(13, callTarget1.call());
+
+        // Probe the addition node
+        final Probe probe = addNode.probe();
+
+        assertEquals(13, callTarget1.call());
+
+        // Attach a null listener; it never actually attaches a node.
+        final Instrument instrument = Instrument.create(new SpliceInstrumentListener() {
+
+            public SplicedNode getSpliceNode(Probe p) {
+                return null;
+            }
+
+        }, null);
+        probe.attach(instrument);
+
+        assertEquals(13, callTarget1.call());
+
+        final TestSplicedCounterNode counter = new TestSplicedCounterNode();
+
+        // Attach a listener that splices an execution counter into the AST.
+        probe.attach(Instrument.create(new SpliceInstrumentListener() {
+
+            public SplicedNode getSpliceNode(Probe p) {
+                return counter;
+            }
+
+        }, null));
+        assertEquals(0, counter.getCount());
+
+        assertEquals(13, callTarget1.call());
+
+        assertEquals(1, counter.getCount());
+
+    }
+
+}
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/ToolNodeInstrumentationTest.java	Mon Apr 13 15:33:45 2015 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.api.test.instrument;
-
-import static org.junit.Assert.*;
-
-import org.junit.*;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.frame.*;
-import com.oracle.truffle.api.instrument.*;
-import com.oracle.truffle.api.nodes.*;
-import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdditionNode;
-import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestRootNode;
-import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestValueNode;
-
-/**
- * Tests instrumentation where a client can attach a node that gets attached into the AST.
- */
-public class ToolNodeInstrumentationTest {
-
-    @Test
-    public void testToolNodeListener() {
-        // Create a simple addition AST
-        final TruffleRuntime runtime = Truffle.getRuntime();
-        final TestValueNode leftValueNode = new TestValueNode(6);
-        final TestValueNode rightValueNode = new TestValueNode(7);
-        final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode);
-        final TestRootNode rootNode = new TestRootNode(addNode);
-        final CallTarget callTarget1 = runtime.createCallTarget(rootNode);
-
-        // Ensure it executes correctly
-        assertEquals(13, callTarget1.call());
-
-        // Probe the addition node
-        final Probe probe = addNode.probe();
-
-        assertEquals(13, callTarget1.call());
-
-        // Attach a listener that never actually attaches a node.
-        final Instrument instrument = Instrument.create(new SpliceInstrumentListener() {
-
-            public SplicedNode getSpliceNode(Probe p) {
-                return null;
-            }
-
-        }, null);
-        probe.attach(instrument);
-
-        assertEquals(13, callTarget1.call());
-
-        final int[] count = new int[1];
-
-        // Attach a listener that never actually attaches a node.
-        probe.attach(Instrument.create(new SpliceInstrumentListener() {
-
-            public SplicedNode getSpliceNode(Probe p) {
-                return new SplicedNode() {
-
-                    @Override
-                    public void enter(Node node, VirtualFrame vFrame) {
-                        count[0] = count[0] + 1;
-                    }
-                };
-            }
-
-        }, null));
-        assertEquals(0, count[0]);
-
-        assertEquals(13, callTarget1.call());
-
-        assertEquals(1, count[0]);
-
-    }
-
-}