Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/AdvancedInstrumentTest.java @ 21355:442b57a7f208
Truffle/Instrumentation: change the signature for creation of Advanced instruments, refactor how the callback listener is managed.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 12 May 2015 16:06:00 -0700 |
parents | 575032310b2c |
children | e34bc00733d1 |
comparison
equal
deleted
inserted
replaced
21354:575032310b2c | 21355:442b57a7f208 |
---|---|
39 * <em>spliced</em> directly into the AST. | 39 * <em>spliced</em> directly into the AST. |
40 */ | 40 */ |
41 public class AdvancedInstrumentTest { | 41 public class AdvancedInstrumentTest { |
42 | 42 |
43 @Test | 43 @Test |
44 public void testSpliceInstrumentListener() { | 44 public void testAdvancedInstrumentListener() { |
45 // Create a simple addition AST | 45 // Create a simple addition AST |
46 final TruffleRuntime runtime = Truffle.getRuntime(); | 46 final TruffleRuntime runtime = Truffle.getRuntime(); |
47 final TestValueNode leftValueNode = new TestValueNode(6); | 47 final TestValueNode leftValueNode = new TestValueNode(6); |
48 final TestValueNode rightValueNode = new TestValueNode(7); | 48 final TestValueNode rightValueNode = new TestValueNode(7); |
49 final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode); | 49 final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode); |
57 final Probe probe = addNode.probe(); | 57 final Probe probe = addNode.probe(); |
58 | 58 |
59 assertEquals(13, callTarget1.call()); | 59 assertEquals(13, callTarget1.call()); |
60 | 60 |
61 // Attach a null factory; it never actually attaches a node. | 61 // Attach a null factory; it never actually attaches a node. |
62 final Instrument instrument = Instrument.create(new AdvancedInstrumentRootFactory(null) { | 62 final Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { |
63 | 63 |
64 @Override | |
65 public AdvancedInstrumentRoot createInstrumentRoot(Probe p, Node n) { | 64 public AdvancedInstrumentRoot createInstrumentRoot(Probe p, Node n) { |
66 return null; | 65 return null; |
67 } | 66 } |
68 }, null); | 67 }, "test AdvancedInstrument"); |
69 probe.attach(instrument); | 68 probe.attach(instrument); |
70 | 69 |
71 assertEquals(13, callTarget1.call()); | 70 assertEquals(13, callTarget1.call()); |
72 | 71 |
73 final TestAdvancedInstrumentCounterRoot counter = new TestAdvancedInstrumentCounterRoot(); | 72 final TestAdvancedInstrumentCounterRoot counter = new TestAdvancedInstrumentCounterRoot(); |
74 | 73 |
75 // Attach a factory that splices an execution counter into the AST. | 74 // Attach a factory that splices an execution counter into the AST. |
76 probe.attach(Instrument.create(new AdvancedInstrumentRootFactory(null) { | 75 probe.attach(Instrument.create(null, new AdvancedInstrumentRootFactory() { |
77 | 76 |
78 @Override | |
79 public AdvancedInstrumentRoot createInstrumentRoot(Probe p, Node n) { | 77 public AdvancedInstrumentRoot createInstrumentRoot(Probe p, Node n) { |
80 return counter; | 78 return counter; |
81 } | 79 } |
82 }, null)); | 80 }, "test AdvancedInstrument")); |
83 assertEquals(0, counter.getCount()); | 81 assertEquals(0, counter.getCount()); |
84 | 82 |
85 assertEquals(13, callTarget1.call()); | 83 assertEquals(13, callTarget1.call()); |
86 | 84 |
87 assertEquals(1, counter.getCount()); | 85 assertEquals(1, counter.getCount()); |
88 | |
89 } | 86 } |
90 | |
91 } | 87 } |