comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/AdvancedInstrumentTest.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
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.instrument; 23 package com.oracle.truffle.api.test.instrument;
24 24
25 import static org.junit.Assert.assertEquals;
26
27 import org.junit.Test;
28
25 import com.oracle.truffle.api.CallTarget; 29 import com.oracle.truffle.api.CallTarget;
26 import com.oracle.truffle.api.Truffle; 30 import com.oracle.truffle.api.Truffle;
27 import com.oracle.truffle.api.TruffleRuntime; 31 import com.oracle.truffle.api.TruffleRuntime;
28 import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot; 32 import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot;
29 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; 33 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory;
30 import com.oracle.truffle.api.instrument.Instrument; 34 import com.oracle.truffle.api.instrument.Instrument;
35 import com.oracle.truffle.api.instrument.Instrumenter;
31 import com.oracle.truffle.api.instrument.Probe; 36 import com.oracle.truffle.api.instrument.Probe;
32 import com.oracle.truffle.api.nodes.Node; 37 import com.oracle.truffle.api.nodes.Node;
33 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdditionNode; 38 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdditionNode;
34 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdvancedInstrumentCounterRoot; 39 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdvancedInstrumentCounterRoot;
35 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestRootNode; 40 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestRootNode;
36 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestValueNode; 41 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestValueNode;
37 import static org.junit.Assert.assertEquals;
38 import org.junit.Test;
39 42
40 /** 43 /**
41 * Tests the kind of instrumentation where a client can provide an AST fragment to be 44 * Tests the kind of instrumentation where a client can provide an AST fragment to be
42 * <em>spliced</em> directly into the AST. 45 * <em>spliced</em> directly into the AST.
43 */ 46 */
44 public class AdvancedInstrumentTest { 47 public class AdvancedInstrumentTest {
45 48
46 @Test 49 @Test
47 public void testAdvancedInstrumentListener() { 50 public void testAdvancedInstrumentListener() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
51 final Instrumenter instrumenter = InstrumentationTestNodes.createInstrumenter();
52
48 // Create a simple addition AST 53 // Create a simple addition AST
49 final TruffleRuntime runtime = Truffle.getRuntime(); 54 final TruffleRuntime runtime = Truffle.getRuntime();
50 final TestValueNode leftValueNode = new TestValueNode(6); 55 final TestValueNode leftValueNode = new TestValueNode(6);
51 final TestValueNode rightValueNode = new TestValueNode(7); 56 final TestValueNode rightValueNode = new TestValueNode(7);
52 final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode); 57 final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode);
53 final TestRootNode rootNode = new TestRootNode(addNode); 58 final TestRootNode rootNode = new TestRootNode(addNode, instrumenter);
54 final CallTarget callTarget1 = runtime.createCallTarget(rootNode); 59 final CallTarget callTarget1 = runtime.createCallTarget(rootNode);
55 60
56 // Ensure it executes correctly 61 // Ensure it executes correctly
57 assertEquals(13, callTarget1.call()); 62 assertEquals(13, callTarget1.call());
58 63
59 // Probe the addition node 64 // Probe the addition node
60 final Probe probe = addNode.probe(); 65 final Probe probe = instrumenter.probe(addNode);
61 66
62 assertEquals(13, callTarget1.call()); 67 assertEquals(13, callTarget1.call());
63 68
64 // Attach a null factory; it never actually attaches a node. 69 // Attach a null factory; it never actually attaches a node.
65 final Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { 70 final Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() {