diff 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
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTestNodes.java	Wed Sep 16 12:27:08 2015 +0200
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTestNodes.java	Wed Sep 16 15:36:22 2015 -0700
@@ -22,9 +22,14 @@
  */
 package com.oracle.truffle.api.test.instrument;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 import com.oracle.truffle.api.CallTarget;
 import com.oracle.truffle.api.frame.VirtualFrame;
 import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot;
+import com.oracle.truffle.api.instrument.Instrumenter;
 import com.oracle.truffle.api.instrument.KillException;
 import com.oracle.truffle.api.instrument.Probe;
 import com.oracle.truffle.api.instrument.ProbeNode;
@@ -34,12 +39,21 @@
 import com.oracle.truffle.api.nodes.NodeInfo;
 import com.oracle.truffle.api.nodes.RootNode;
 import com.oracle.truffle.api.test.TestingLanguage;
+import com.oracle.truffle.api.vm.TruffleVM;
 
 /**
  * Tests instrumentation where a client can attach a node that gets attached into the AST.
  */
 class InstrumentationTestNodes {
 
+    static Instrumenter createInstrumenter() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+        TruffleVM vm = TruffleVM.newVM().build();
+        final Field field = TruffleVM.class.getDeclaredField("instrumenter");
+        field.setAccessible(true);
+        final Instrumenter instrument = (Instrumenter) field.get(vm);
+        return instrument;
+    }
+
     abstract static class TestLanguageNode extends Node {
         public abstract Object execute(VirtualFrame vFrame);
 
@@ -148,13 +162,16 @@
     static class TestRootNode extends RootNode {
         @Child private TestLanguageNode body;
 
+        final Instrumenter instrumenter;
+
         /**
          * This constructor emulates the global machinery that applies registered probers to every
          * newly created AST. Global registry is not used, since that would interfere with other
          * tests run in the same environment.
          */
-        public TestRootNode(TestLanguageNode body) {
+        public TestRootNode(TestLanguageNode body, Instrumenter instrumenter) {
             super(TestingLanguage.class, null, null);
+            this.instrumenter = instrumenter;
             this.body = body;
         }
 
@@ -170,7 +187,14 @@
 
         @Override
         public void applyInstrumentation() {
-            Probe.applyASTProbers(body);
+            Method method;
+            try {
+                method = Instrumenter.class.getDeclaredMethod("applyInstrumentation", Node.class);
+                method.setAccessible(true);
+                method.invoke(instrumenter, body);
+            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+                throw new RuntimeException("InstrumentationTestNodes");
+            }
         }
     }