annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Probe.java @ 19490:745ecef4c9cd

Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 18 Feb 2015 18:07:48 -0800
parents 2f676c3ca430
children 4d66c000d253
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
1 /*
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
4 *
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation. Oracle designates this
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
8 * particular file as subject to the "Classpath" exception as provided
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
9 * by Oracle in the LICENSE file that accompanied this code.
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
10 *
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
11 * This code is distributed in the hope that it will be useful, but WITHOUT
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
14 * version 2 for more details (a copy is included in the LICENSE file that
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
15 * accompanied this code).
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
16 *
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License version
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
18 * 2 along with this work; if not, write to the Free Software Foundation,
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
20 *
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
22 * or visit www.oracle.com if you need additional information or have any
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
23 * questions.
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
24 */
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
25 package com.oracle.truffle.api.instrument;
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
26
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
27 import java.lang.ref.*;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
28 import java.util.*;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
29
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
30 import com.oracle.truffle.api.*;
19488
2f676c3ca430 Truffle/Instrumentation: fix some optimization bugs; instrumentation PE tests now succeed after recent compiler work
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19247
diff changeset
31 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
18338
c4f374adce13 Probe interface should extend NodeInterface
Andreas Woess <andreas.woess@jku.at>
parents: 16857
diff changeset
32 import com.oracle.truffle.api.nodes.*;
16067
915ebb306fcc Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15779
diff changeset
33 import com.oracle.truffle.api.source.*;
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
34 import com.oracle.truffle.api.utilities.*;
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
35
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
36 //TODO (mlvdv) migrate some of this to external documentation.
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
37 /**
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
38 * A binding between a particular <em>location</em> in the Truffle AST representation of a running
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
39 * Guest Language (GL) program (i.e. a {@link Node}) and a dynamically managed collection of
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
40 * "attached" {@linkplain Instrument instrumentation} for use by external tools. The instrumentation
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
41 * is intended to persist at the location, even if the specific node instance is
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
42 * {@linkplain Node#replace(Node) replaced}.
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
43 * <p>
19247
128586040207 Truffle/Instrumentation: TruffleEventReceiver renamed to TruffleEventListener
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18985
diff changeset
44 * The effect of a binding is to intercept {@linkplain TruffleEventListener execution events}
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
45 * arriving at the node and notify each attached {@link Instrument} before execution is allowed to
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
46 * proceed to the child.
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
47 * <p>
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
48 * A Probe is "inserted" into a GL node via a call to {@link Node#probe()}. No more than one Probe
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
49 * can be inserted at a node.
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
50 * <p>
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
51 * The "probing" of a Truffle AST must be done after it is complete (i.e. with parent pointers
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
52 * correctly assigned), but before any executions. This is done by creating an instance of
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
53 * {@link ASTProber} and registering it via {@link #registerASTProber(ASTProber)}, after which it
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
54 * will be automatically applied to newly created ASTs.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
55 * <p>
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
56 * Each Probe may also have assigned to it any number of {@link SyntaxTag}s, for example identifying
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
57 * a node as a {@linkplain StandardSyntaxTag#STATEMENT STATEMENT}. Tags can be queried by tools to
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
58 * configure behavior relevant to each probed node.
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
59 * <p>
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
60 * Instrumentation is implemented by modifying ASTs, both by inserting nodes into each AST at probed
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
61 * locations and by attaching additional nodes that implement dynamically attached instruments.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
62 * Attached instrumentation code become, in effect, part of the GL program, and is subject to the
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
63 * same levels of optimization as other GL code. This implementation accounts properly for the fact
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
64 * that Truffle frequently <em>clones</em> ASTs, along with any attached instrumentation nodes. A
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
65 * {@link Probe}, along with attached {@link Instrument}s, represents a <em>logical</em> binding
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
66 * with a source code location, producing event notifications that are (mostly) independent of which
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
67 * AST clone is executing.
15605
bb9473723904 Truffle/Instrumentation:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15279
diff changeset
68 *
bb9473723904 Truffle/Instrumentation:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15279
diff changeset
69 * @see Instrument
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
70 * @see ASTProber
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
71 * @see ProbeListener
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
72 */
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
73 public final class Probe implements SyntaxTagged {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
74
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
75 private static final List<ASTProber> astProbers = new ArrayList<>();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
76
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
77 private static final List<ProbeListener> probeListeners = new ArrayList<>();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
78
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
79 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
80 * All Probes that have been created.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
81 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
82 private static final List<WeakReference<Probe>> probes = new ArrayList<>();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
83
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
84 private static final class FindSourceVisitor implements NodeVisitor {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
85
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
86 Source source = null;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
87
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
88 public boolean visit(Node node) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
89 final SourceSection sourceSection = node.getSourceSection();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
90 if (sourceSection != null) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
91 source = sourceSection.getSource();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
92 return false;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
93 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
94 return true;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
95 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
96 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
97
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
98 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
99 * Walks an AST, looking for the first node with an assigned {@link SourceSection} and returning
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
100 * the {@link Source}.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
101 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
102 private static Source findSource(Node node) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
103 final FindSourceVisitor visitor = new FindSourceVisitor();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
104 node.accept(visitor);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
105 return visitor.source;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
106 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
107
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
108 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
109 * Enables instrumentation at selected nodes in all subsequently constructed ASTs.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
110 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
111 public static void registerASTProber(ASTProber prober) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
112 astProbers.add(prober);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
113 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
114
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
115 public static void unregisterASTProber(ASTProber prober) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
116 astProbers.remove(prober);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
117 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
118
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
119 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
120 * Enables instrumentation in a newly created AST by applying all registered instances of
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
121 * {@link ASTProber}.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
122 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
123 public static void applyASTProbers(Node node) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
124
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
125 final Source source = findSource(node);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
126
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
127 for (ProbeListener listener : probeListeners) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
128 listener.startASTProbing(source);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
129 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
130 for (ASTProber prober : astProbers) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
131 prober.probeAST(node);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
132 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
133 for (ProbeListener listener : probeListeners) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
134 listener.endASTProbing(source);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
135 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
136 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
137
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
138 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
139 * Adds a {@link ProbeListener} to receive events.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
140 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
141 public static void addProbeListener(ProbeListener listener) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
142 assert listener != null;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
143 probeListeners.add(listener);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
144 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
145
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
146 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
147 * Removes a {@link ProbeListener}. Ignored if listener not found.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
148 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
149 public static void removeProbeListener(ProbeListener listener) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
150 probeListeners.remove(listener);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
151 }
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
152
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
153 /**
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
154 * Returns all {@link Probe}s holding a particular {@link SyntaxTag}, or the whole collection of
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
155 * probes if the specified tag is {@code null}.
16856
7833417c8172 Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents: 16391
diff changeset
156 *
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
157 * @return A collection of probes containing the given tag.
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
158 */
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
159 public static Collection<Probe> findProbesTaggedAs(SyntaxTag tag) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
160 final List<Probe> taggedProbes = new ArrayList<>();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
161 for (WeakReference<Probe> ref : probes) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
162 Probe probe = ref.get();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
163 if (probe != null) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
164 if (tag == null || probe.isTaggedAs(tag)) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
165 taggedProbes.add(ref.get());
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
166 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
167 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
168 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
169 return taggedProbes;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
170 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
171
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
172 /**
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
173 * Sets the current "tag trap"; there can be no more than one set at a time.
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
174 * <ul>
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
175 * <li>A non-null trap sets a callback to be triggered whenever execution reaches a
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
176 * {@link Probe} (either existing or subsequently created) with the specified tag.</li>
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
177 * <li>Setting the trap to null clears the existing trap.</li>
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
178 * <li>Setting a non-null trap when one is already set will clear the previously set trap.</li>
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
179 * </ul>
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
180 *
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
181 * @param newTagTrap The {@link SyntaxTagTrap} to set.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
182 */
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
183 public static void setTagTrap(SyntaxTagTrap newTagTrap) {
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
184 for (WeakReference<Probe> ref : probes) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
185 final Probe probe = ref.get();
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
186 if (probe != null) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
187 probe.setTrap(newTagTrap);
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
188 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
189 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
190 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
191
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
192 private final SourceSection sourceSection;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
193 private final ArrayList<SyntaxTag> tags = new ArrayList<>();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
194 private final List<WeakReference<ProbeNode>> probeNodeClones = new ArrayList<>();
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
195
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
196 /*
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
197 * Invalidated whenever something changes in the Probe and its Instrument chain, so need deopt
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
198 */
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
199 private final CyclicAssumption probeStateUnchangedCyclic = new CyclicAssumption("Probe state unchanged");
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
200
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
201 /*
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
202 * The assumption that nothing had changed in this probe, the last time anybody checked (when
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
203 * there may have been a deopt). Every time a check fails, gets replaced by a new unchanged
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
204 * assumption.
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
205 */
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
206 @CompilationFinal private Assumption probeStateUnchangedAssumption = probeStateUnchangedCyclic.getAssumption();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
207
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
208 // Must invalidate whenever either of these these changes.
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
209 @CompilationFinal private SyntaxTagTrap tagTrap = null;
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
210 @CompilationFinal private boolean isTrapActive = false;
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
211
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
212 /**
18985
867058575979 Truffle: Improved support for "probing" AST nodes:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18485
diff changeset
213 * Intended for use only by {@link ProbeNode}.
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
214 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
215 Probe(ProbeNode probeNode, SourceSection sourceSection) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
216 this.sourceSection = sourceSection;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
217 probes.add(new WeakReference<>(this));
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
218 registerProbeNodeClone(probeNode);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
219 for (ProbeListener listener : probeListeners) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
220 listener.newProbeInserted(this);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
221 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
222 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
223
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
224 public boolean isTaggedAs(SyntaxTag tag) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
225 assert tag != null;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
226 return tags.contains(tag);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
227 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
228
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
229 public Collection<SyntaxTag> getSyntaxTags() {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
230 return Collections.unmodifiableCollection(tags);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
231 }
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
232
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
233 /**
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
234 * Adds a {@linkplain SyntaxTag tag} to the set of tags associated with this {@link Probe};
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
235 * {@code no-op} if already in the set.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
236 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
237 public void tagAs(SyntaxTag tag, Object tagValue) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
238 assert tag != null;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
239 if (!tags.contains(tag)) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
240 tags.add(tag);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
241 for (ProbeListener listener : probeListeners) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
242 listener.probeTaggedAs(this, tag, tagValue);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
243 }
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
244 if (tagTrap != null && tag == tagTrap.getTag()) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
245 this.isTrapActive = true;
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
246 invalidateProbeUnchanged();
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
247 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
248 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
249 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
250
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
251 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
252 * Adds instrumentation at this Probe.
16857
7bfbad29d331 Truffle/Instrumentation: Javadoc cleanups and minor corrections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 16856
diff changeset
253 *
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
254 * @param instrument an instrument not yet attached to a probe
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
255 * @throws IllegalStateException if the instrument has ever been attached before
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
256 */
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
257 public void attach(Instrument instrument) throws IllegalStateException {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
258 if (instrument.isDisposed()) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
259 throw new IllegalStateException("Attempt to attach disposed instrument");
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
260 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
261 if (instrument.getProbe() != null) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
262 throw new IllegalStateException("Attampt to attach an already attached instrument");
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
263 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
264 instrument.setAttachedTo(this);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
265 for (WeakReference<ProbeNode> ref : probeNodeClones) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
266 final ProbeNode probeNode = ref.get();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
267 if (probeNode != null) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
268 probeNode.addInstrument(instrument);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
269 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
270 }
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
271 invalidateProbeUnchanged();
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
272 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
273
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
274 /**
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
275 * Gets the {@link SourceSection} associated with the Guest Language AST node being
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
276 * instrumented, possibly {@code null}.
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
277 */
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
278 public SourceSection getProbedSourceSection() {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
279 return sourceSection;
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
280 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
281
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
282 public String getShortDescription() {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
283 final String location = sourceSection == null ? "<unknown>" : sourceSection.getShortDescription();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
284 return "Probe@" + location + getTagsDescription();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
285 }
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
286
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
287 /**
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
288 * Internal method for removing and rendering inert a specific instrument previously attached at
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
289 * this Probe.
16857
7bfbad29d331 Truffle/Instrumentation: Javadoc cleanups and minor corrections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 16856
diff changeset
290 *
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
291 * @param instrument an instrument already attached
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
292 * @throws IllegalStateException if instrument not attached at this Probe
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
293 * @see Instrument#dispose()
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
294 */
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
295 void disposeInstrument(Instrument instrument) throws IllegalStateException {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
296 for (WeakReference<ProbeNode> ref : probeNodeClones) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
297 final ProbeNode probeNode = ref.get();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
298 if (probeNode != null) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
299 probeNode.removeInstrument(instrument);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
300 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
301 }
19490
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
302 invalidateProbeUnchanged();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
303 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
304
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
305 /**
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
306 * Receives notification that a new clone of the instrument chain associated with this
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
307 * {@link Probe} has been created as a side-effect of AST cloning.
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
308 */
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
309 void registerProbeNodeClone(ProbeNode probeNode) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
310 probeNodeClones.add(new WeakReference<>(probeNode));
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
311 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
312
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
313 /**
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
314 * Gets the currently active {@linkplain SyntaxTagTrap tagTrap}; {@code null} if not set.
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
315 */
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
316 SyntaxTagTrap getTrap() {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
317 checkProbeUnchanged();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
318 return isTrapActive ? tagTrap : null;
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
319 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
320
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
321 /**
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
322 * To be called wherever in the Probe/Instrument chain there are dependencies on the probe
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
323 * state's @CompilatonFinal fields.
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
324 */
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
325 void checkProbeUnchanged() {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
326 try {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
327 probeStateUnchangedAssumption.check();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
328 } catch (InvalidAssumptionException ex) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
329 // Failure creates an implicit deoptimization
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
330 // Get the assumption associated with the new probe state
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
331 this.probeStateUnchangedAssumption = probeStateUnchangedCyclic.getAssumption();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
332 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
333 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
334
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
335 private void invalidateProbeUnchanged() {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
336 probeStateUnchangedCyclic.invalidate();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
337 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
338
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
339 private void setTrap(SyntaxTagTrap newTagTrap) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
340 // No-op if same trap; traps are immutable
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
341 if (this.tagTrap != newTagTrap) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
342 if (newTagTrap == null) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
343 this.tagTrap = null;
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
344 if (isTrapActive) {
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
345 isTrapActive = false;
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
346 invalidateProbeUnchanged();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
347 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
348 } else { // new trap is non-null
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
349 this.tagTrap = newTagTrap;
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
350 this.isTrapActive = this.isTaggedAs(newTagTrap.getTag());
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
351 invalidateProbeUnchanged();
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
352 }
745ecef4c9cd Truffle/Instrumentation: clean up the use of Assumptions in the Probe (and attached Instruments)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 19488
diff changeset
353 }
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
354 }
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
355
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
356 private String getTagsDescription() {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
357 final StringBuilder sb = new StringBuilder();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
358 sb.append("[");
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
359 String prefix = "";
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
360 for (SyntaxTag tag : tags) {
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
361 sb.append(prefix);
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
362 prefix = ",";
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
363 sb.append(tag.toString());
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
364 }
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
365 sb.append("]");
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
366 return sb.toString();
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18338
diff changeset
367 }
15279
0c6d8a08e31b Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff changeset
368 }