Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ExecutionContext.java @ 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.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sun, 23 Nov 2014 16:07:23 -0800 |
parents | 656331a61829 |
children | 894f82515e38 |
comparison
equal
deleted
inserted
replaced
18484:e97e1f07a3d6 | 18485:e3c95cbbb50c |
---|---|
22 * or visit www.oracle.com if you need additional information or have any | 22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.api; | 25 package com.oracle.truffle.api; |
26 | 26 |
27 import java.util.*; | |
28 | |
29 import com.oracle.truffle.api.impl.*; | 27 import com.oracle.truffle.api.impl.*; |
30 import com.oracle.truffle.api.instrument.*; | 28 import com.oracle.truffle.api.instrument.*; |
31 import com.oracle.truffle.api.instrument.impl.*; | 29 import com.oracle.truffle.api.instrument.impl.*; |
32 import com.oracle.truffle.api.source.*; | |
33 | 30 |
34 /** | 31 /** |
35 * Access to information and basic services in the runtime context for a Truffle-implemented guest | 32 * Access to information and basic services in the runtime context for a Truffle-implemented guest |
36 * language. | 33 * language. |
37 * <p> | 34 * <p> |
38 * <strong>Disclaimer:</strong> this class is under development and will change. | 35 * <strong>Disclaimer:</strong> this class is under development and will change. |
39 */ | 36 */ |
40 public abstract class ExecutionContext { | 37 public abstract class ExecutionContext { |
41 | 38 |
42 private final ProbeManager probeManager = new ProbeManager(); | |
43 private final List<SourceListener> sourceListeners = new ArrayList<>(); | |
44 private Visualizer visualizer = new DefaultVisualizer(); | 39 private Visualizer visualizer = new DefaultVisualizer(); |
45 | 40 |
46 protected ExecutionContext() { | 41 protected ExecutionContext() { |
47 } | |
48 | |
49 /** | |
50 * Sets up the {@link SourceCallback} for this execution context. | |
51 */ | |
52 public void initialize() { | |
53 setSourceCallback(new SourceCallback() { | |
54 | |
55 public void startLoading(Source source) { | |
56 for (SourceListener listener : sourceListeners) { | |
57 listener.loadStarting(source); | |
58 } | |
59 } | |
60 | |
61 public void endLoading(Source source) { | |
62 for (SourceListener listener : sourceListeners) { | |
63 listener.loadEnding(source); | |
64 } | |
65 } | |
66 }); | |
67 } | |
68 | |
69 /** | |
70 * Registers a tool interested in being notified about the loading of {@link Source}s. | |
71 */ | |
72 public final void addSourceListener(SourceListener listener) { | |
73 assert listener != null; | |
74 sourceListeners.add(listener); | |
75 } | |
76 | |
77 /** | |
78 * Unregisters a tool interested in being notified about the loading of {@link Source}s. | |
79 */ | |
80 public final void removeSourceListener(SourceListener removeListener) { | |
81 final List<SourceListener> listeners = new ArrayList<>(sourceListeners); | |
82 for (SourceListener listener : listeners) { | |
83 if (listener == removeListener) { | |
84 sourceListeners.remove(listener); | |
85 } | |
86 } | |
87 } | |
88 | |
89 /** | |
90 * Registers a tool interested in being notified about the insertion of a newly created | |
91 * {@link Probe} into a Truffle AST. | |
92 */ | |
93 public final void addProbeListener(ProbeListener listener) { | |
94 probeManager.addProbeListener(listener); | |
95 } | |
96 | |
97 /** | |
98 * Unregisters a tool interested in being notified about the insertion of a newly created | |
99 * {@link Probe} into a Truffle AST. | |
100 */ | |
101 public final void removeProbeListener(ProbeListener listener) { | |
102 probeManager.removeProbeListener(listener); | |
103 } | |
104 | |
105 /** | |
106 * Return a newly created, untagged, {@link Probe} associated with a particular source section, | |
107 * with no requirement that the association be unique. | |
108 * | |
109 * @return a probe associated with an extent of guest language source code. | |
110 */ | |
111 public final Probe createProbe(SourceSection source) { | |
112 return probeManager.createProbe(source); | |
113 } | |
114 | |
115 /** | |
116 * Returns all existing probes with specific tag, or all probes if {@code tag = null}; empty | |
117 * collection if no probes found. | |
118 */ | |
119 public final Collection<Probe> findProbesTaggedAs(SyntaxTag tag) { | |
120 return probeManager.findProbesTaggedAs(tag); | |
121 } | |
122 | |
123 /** | |
124 * Sets a trap that will make a callback at any AST location where a existing probe holds a | |
125 * specified tag; only one trap may be set at a time. | |
126 * | |
127 * @throws IllegalStateException if a trap is already set | |
128 */ | |
129 public final void setTagTrap(SyntaxTagTrap trap) throws IllegalStateException { | |
130 // TODO (mlvdv) consider allowing multiple traps (without inhibiting Truffle inlining) | |
131 probeManager.setTagTrap(trap); | |
132 } | |
133 | |
134 /** | |
135 * Clears a trap that will halt execution; only one trap may be set at a time. | |
136 * | |
137 * @throws IllegalStateException if no trap is set. | |
138 */ | |
139 public final void clearTagTrap() { | |
140 probeManager.clearTagTrap(); | |
141 } | 42 } |
142 | 43 |
143 /** | 44 /** |
144 * Access to information visualization services for the specific language. | 45 * Access to information visualization services for the specific language. |
145 */ | 46 */ |
160 * might be used for an interactive prompt. | 61 * might be used for an interactive prompt. |
161 */ | 62 */ |
162 public abstract String getLanguageShortName(); | 63 public abstract String getLanguageShortName(); |
163 | 64 |
164 /** | 65 /** |
165 * Establishes source event reporting. | |
166 */ | |
167 protected abstract void setSourceCallback(SourceCallback sourceCallback); | |
168 | |
169 /** | |
170 * Get compiler options specific to this <code>ExecutionContext</code>. | 66 * Get compiler options specific to this <code>ExecutionContext</code>. |
171 */ | 67 */ |
172 public CompilerOptions getCompilerOptions() { | 68 public CompilerOptions getCompilerOptions() { |
173 return DefaultCompilerOptions.INSTANCE; | 69 return DefaultCompilerOptions.INSTANCE; |
174 } | 70 } |