Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/AdvancedInstrumentTest.java @ 21353:876e710523c5
Truffle/Instrumentation: rename "Tool Eval" Instrument kind to "Advanced" Instrument kind
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 12 May 2015 12:57:47 -0700 |
parents | graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/ToolEvalInstrumentTest.java@78a4b44420cf |
children | 575032310b2c |
comparison
equal
deleted
inserted
replaced
21345:a818a6a57ef4 | 21353:876e710523c5 |
---|---|
1 /* | |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.test.instrument; | |
24 | |
25 import static org.junit.Assert.*; | |
26 | |
27 import org.junit.*; | |
28 | |
29 import com.oracle.truffle.api.*; | |
30 import com.oracle.truffle.api.instrument.*; | |
31 import com.oracle.truffle.api.nodes.*; | |
32 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdditionNode; | |
33 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestRootNode; | |
34 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestValueNode; | |
35 import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdvancedInstrumentCounterRoot; | |
36 | |
37 /** | |
38 * Tests the kind of instrumentation where a client can provide an AST fragment to be | |
39 * <em>spliced</em> directly into the AST. | |
40 */ | |
41 public class AdvancedInstrumentTest { | |
42 | |
43 @Test | |
44 public void testSpliceInstrumentListener() { | |
45 // Create a simple addition AST | |
46 final TruffleRuntime runtime = Truffle.getRuntime(); | |
47 final TestValueNode leftValueNode = new TestValueNode(6); | |
48 final TestValueNode rightValueNode = new TestValueNode(7); | |
49 final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode); | |
50 final TestRootNode rootNode = new TestRootNode(addNode); | |
51 final CallTarget callTarget1 = runtime.createCallTarget(rootNode); | |
52 | |
53 // Ensure it executes correctly | |
54 assertEquals(13, callTarget1.call()); | |
55 | |
56 // Probe the addition node | |
57 final Probe probe = addNode.probe(); | |
58 | |
59 assertEquals(13, callTarget1.call()); | |
60 | |
61 // Attach a null listener; it never actually attaches a node. | |
62 final Instrument instrument = Instrument.create(new AdvancedInstrumentRootFactory() { | |
63 | |
64 public AdvancedInstrumentRoot createInstrumentRoot(Probe p, Node n) { | |
65 return null; | |
66 } | |
67 }, null); | |
68 probe.attach(instrument); | |
69 | |
70 assertEquals(13, callTarget1.call()); | |
71 | |
72 final TestAdvancedInstrumentCounterRoot counter = new TestAdvancedInstrumentCounterRoot(); | |
73 | |
74 // Attach a listener that splices an execution counter into the AST. | |
75 probe.attach(Instrument.create(new AdvancedInstrumentRootFactory() { | |
76 | |
77 public AdvancedInstrumentRoot createInstrumentRoot(Probe p, Node n) { | |
78 return counter; | |
79 } | |
80 }, null)); | |
81 assertEquals(0, counter.getCount()); | |
82 | |
83 assertEquals(13, callTarget1.call()); | |
84 | |
85 assertEquals(1, counter.getCount()); | |
86 | |
87 } | |
88 | |
89 } |