Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java @ 22219:1c0f490984d5
Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 15:36:22 -0700 |
parents | dc83cc1f94f2 d3bdaa91bc82 |
children | 20380d1d41f2 |
comparison
equal
deleted
inserted
replaced
22160:0599e2df6a9f | 22219:1c0f490984d5 |
---|---|
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.impl; | 25 package com.oracle.truffle.api.impl; |
26 | 26 |
27 import java.io.Closeable; | |
28 import java.io.IOException; | |
29 import java.io.Reader; | |
30 import java.io.Writer; | |
31 import java.lang.ref.Reference; | |
32 import java.lang.ref.WeakReference; | |
33 | |
27 import com.oracle.truffle.api.Assumption; | 34 import com.oracle.truffle.api.Assumption; |
28 import com.oracle.truffle.api.CallTarget; | 35 import com.oracle.truffle.api.CallTarget; |
29 import com.oracle.truffle.api.Truffle; | 36 import com.oracle.truffle.api.Truffle; |
30 import com.oracle.truffle.api.TruffleLanguage; | 37 import com.oracle.truffle.api.TruffleLanguage; |
31 import com.oracle.truffle.api.TruffleLanguage.Env; | 38 import com.oracle.truffle.api.TruffleLanguage.Env; |
32 import com.oracle.truffle.api.debug.DebugSupportProvider; | 39 import com.oracle.truffle.api.debug.DebugSupportProvider; |
33 import com.oracle.truffle.api.debug.Debugger; | 40 import com.oracle.truffle.api.debug.Debugger; |
41 import com.oracle.truffle.api.frame.MaterializedFrame; | |
42 import com.oracle.truffle.api.instrument.ASTProber; | |
43 import com.oracle.truffle.api.instrument.AdvancedInstrumentResultListener; | |
44 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; | |
45 import com.oracle.truffle.api.instrument.Instrumenter; | |
34 import com.oracle.truffle.api.instrument.Probe; | 46 import com.oracle.truffle.api.instrument.Probe; |
35 import com.oracle.truffle.api.instrument.ToolSupportProvider; | 47 import com.oracle.truffle.api.instrument.ToolSupportProvider; |
48 import com.oracle.truffle.api.instrument.Visualizer; | |
36 import com.oracle.truffle.api.nodes.Node; | 49 import com.oracle.truffle.api.nodes.Node; |
37 import com.oracle.truffle.api.nodes.RootNode; | 50 import com.oracle.truffle.api.nodes.RootNode; |
38 import com.oracle.truffle.api.source.Source; | 51 import com.oracle.truffle.api.source.Source; |
39 import java.io.Closeable; | |
40 import java.io.IOException; | |
41 import java.io.Reader; | |
42 import java.io.Writer; | |
43 import java.lang.ref.Reference; | |
44 import java.lang.ref.WeakReference; | |
45 | 52 |
46 /** | 53 /** |
47 * Communication between TruffleVM and TruffleLanguage API/SPI. | 54 * Communication between TruffleVM, TruffleLanguage API/SPI, and other services. |
48 */ | 55 */ |
49 @SuppressWarnings("rawtypes") | 56 @SuppressWarnings("rawtypes") |
50 public abstract class Accessor { | 57 public abstract class Accessor { |
51 private static Accessor API; | 58 private static Accessor API; |
52 private static Accessor SPI; | 59 private static Accessor SPI; |
53 private static Accessor NODES; | 60 private static Accessor NODES; |
61 private static Accessor INTEROP; | |
54 private static Accessor INSTRUMENT; | 62 private static Accessor INSTRUMENT; |
63 private static Accessor TOOL; | |
55 private static Accessor DEBUG; | 64 private static Accessor DEBUG; |
56 private static final ThreadLocal<Object> CURRENT_VM = new ThreadLocal<>(); | 65 private static final ThreadLocal<Object> CURRENT_VM = new ThreadLocal<>(); |
57 | 66 |
58 static { | 67 static { |
59 TruffleLanguage<?> lng = new TruffleLanguage<Object>() { | 68 TruffleLanguage<?> lng = new TruffleLanguage<Object>() { |
70 @Override | 79 @Override |
71 protected boolean isObjectOfLanguage(Object object) { | 80 protected boolean isObjectOfLanguage(Object object) { |
72 return false; | 81 return false; |
73 } | 82 } |
74 | 83 |
84 @SuppressWarnings("deprecation") | |
75 @Override | 85 @Override |
76 protected ToolSupportProvider getToolSupport() { | 86 protected ToolSupportProvider getToolSupport() { |
77 return null; | 87 throw new UnsupportedOperationException(); |
78 } | 88 } |
79 | 89 |
90 @SuppressWarnings("deprecation") | |
80 @Override | 91 @Override |
81 protected DebugSupportProvider getDebugSupport() { | 92 protected DebugSupportProvider getDebugSupport() { |
82 return null; | 93 return null; |
83 } | 94 } |
84 | 95 |
87 throw new IOException(); | 98 throw new IOException(); |
88 } | 99 } |
89 | 100 |
90 @Override | 101 @Override |
91 protected Object createContext(TruffleLanguage.Env env) { | 102 protected Object createContext(TruffleLanguage.Env env) { |
103 return null; | |
104 } | |
105 | |
106 @Override | |
107 protected ASTProber getDefaultASTProber() { | |
108 return null; | |
109 } | |
110 | |
111 @Override | |
112 protected Visualizer getVisualizer() { | |
113 return null; | |
114 } | |
115 | |
116 @SuppressWarnings("deprecation") | |
117 @Override | |
118 protected void enableASTProbing(ASTProber astProber) { | |
119 throw new UnsupportedOperationException(); | |
120 } | |
121 | |
122 @Override | |
123 protected Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException { | |
124 return null; | |
125 } | |
126 | |
127 @Override | |
128 protected AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws IOException { | |
92 return null; | 129 return null; |
93 } | 130 } |
94 }; | 131 }; |
95 lng.hashCode(); | 132 lng.hashCode(); |
96 new Node(null) { | 133 new Node(null) { |
97 }.getRootNode(); | 134 }.getRootNode(); |
98 | 135 |
99 try { | 136 try { |
137 Class.forName(Instrumenter.class.getName(), true, Instrumenter.class.getClassLoader()); | |
100 Class.forName(Debugger.class.getName(), true, Debugger.class.getClassLoader()); | 138 Class.forName(Debugger.class.getName(), true, Debugger.class.getClassLoader()); |
101 } catch (ClassNotFoundException ex) { | 139 } catch (ClassNotFoundException ex) { |
102 throw new IllegalStateException(ex); | 140 throw new IllegalStateException(ex); |
103 } | 141 } |
104 } | 142 } |
112 } else if (this.getClass().getSimpleName().endsWith("Nodes")) { | 150 } else if (this.getClass().getSimpleName().endsWith("Nodes")) { |
113 if (NODES != null) { | 151 if (NODES != null) { |
114 throw new IllegalStateException(); | 152 throw new IllegalStateException(); |
115 } | 153 } |
116 NODES = this; | 154 NODES = this; |
155 } else if (this.getClass().getSimpleName().endsWith("Interop")) { | |
156 if (INTEROP != null) { | |
157 throw new IllegalStateException(); | |
158 } | |
159 INTEROP = this; | |
117 } else if (this.getClass().getSimpleName().endsWith("Instrument")) { | 160 } else if (this.getClass().getSimpleName().endsWith("Instrument")) { |
118 if (INSTRUMENT != null) { | 161 if (INSTRUMENT != null) { |
119 throw new IllegalStateException(); | 162 throw new IllegalStateException(); |
120 } | 163 } |
121 INSTRUMENT = this; | 164 INSTRUMENT = this; |
122 } else if (this.getClass().getSimpleName().endsWith("Debug")) { | 165 } else if (this.getClass().getSimpleName().endsWith("Debug")) { |
123 if (DEBUG != null) { | 166 if (DEBUG != null) { |
124 throw new IllegalStateException(); | 167 throw new IllegalStateException(); |
125 } | 168 } |
126 DEBUG = this; | 169 DEBUG = this; |
170 } else if (this.getClass().getSimpleName().endsWith("Tool")) { | |
171 if (TOOL != null) { | |
172 throw new IllegalStateException(); | |
173 } | |
174 TOOL = this; | |
127 } else { | 175 } else { |
128 if (SPI != null) { | 176 if (SPI != null) { |
129 throw new IllegalStateException(); | 177 throw new IllegalStateException(); |
130 } | 178 } |
131 SPI = this; | 179 SPI = this; |
150 | 198 |
151 protected Object languageGlobal(TruffleLanguage.Env env) { | 199 protected Object languageGlobal(TruffleLanguage.Env env) { |
152 return API.languageGlobal(env); | 200 return API.languageGlobal(env); |
153 } | 201 } |
154 | 202 |
155 protected ToolSupportProvider getToolSupport(TruffleLanguage<?> l) { | 203 @Deprecated |
156 return API.getToolSupport(l); | 204 protected ToolSupportProvider getToolSupport(@SuppressWarnings("unused") TruffleLanguage<?> l) { |
157 } | 205 throw new UnsupportedOperationException(); |
158 | 206 } |
159 protected DebugSupportProvider getDebugSupport(TruffleLanguage<?> l) { | 207 |
160 return API.getDebugSupport(l); | 208 @Deprecated |
209 protected DebugSupportProvider getDebugSupport(@SuppressWarnings("unused") TruffleLanguage<?> l) { | |
210 throw new UnsupportedOperationException(); | |
211 } | |
212 | |
213 protected ASTProber getDefaultASTProber(TruffleLanguage language) { | |
214 return API.getDefaultASTProber(language); | |
215 } | |
216 | |
217 protected AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(Object vm, Class<? extends TruffleLanguage> languageClass, String expr, AdvancedInstrumentResultListener resultListener) | |
218 throws IOException { | |
219 return API.createAdvancedInstrumentRootFactory(vm, languageClass, expr, resultListener); | |
161 } | 220 } |
162 | 221 |
163 protected Class<? extends TruffleLanguage> findLanguage(RootNode n) { | 222 protected Class<? extends TruffleLanguage> findLanguage(RootNode n) { |
164 return NODES.findLanguage(n); | 223 return NODES.findLanguage(n); |
165 } | 224 } |
180 } | 239 } |
181 } else { | 240 } else { |
182 vm = known; | 241 vm = known; |
183 } | 242 } |
184 return SPI.findLanguage(vm, languageClass); | 243 return SPI.findLanguage(vm, languageClass); |
244 } | |
245 | |
246 protected TruffleLanguage findLanguageImpl(Object known, Class<? extends TruffleLanguage> languageClass) { | |
247 Object vm; | |
248 if (known == null) { | |
249 vm = CURRENT_VM.get(); | |
250 if (vm == null) { | |
251 throw new IllegalStateException(); | |
252 } | |
253 } else { | |
254 vm = known; | |
255 } | |
256 return SPI.findLanguageImpl(vm, languageClass); | |
257 } | |
258 | |
259 protected Instrumenter getInstrumenter(Object known) { | |
260 Object vm; | |
261 if (known == null) { | |
262 vm = CURRENT_VM.get(); | |
263 if (vm == null) { | |
264 throw new IllegalStateException(); | |
265 } | |
266 } else { | |
267 vm = known; | |
268 } | |
269 return SPI.getInstrumenter(vm); | |
270 } | |
271 | |
272 protected Instrumenter createInstrumenter() { | |
273 return INSTRUMENT.createInstrumenter(); | |
185 } | 274 } |
186 | 275 |
187 private static Reference<Object> previousVM = new WeakReference<>(null); | 276 private static Reference<Object> previousVM = new WeakReference<>(null); |
188 private static Assumption oneVM = Truffle.getRuntime().createAssumption(); | 277 private static Assumption oneVM = Truffle.getRuntime().createAssumption(); |
189 | 278 |
235 } | 324 } |
236 | 325 |
237 protected TruffleLanguage<?> findLanguage(Env env) { | 326 protected TruffleLanguage<?> findLanguage(Env env) { |
238 return API.findLanguage(env); | 327 return API.findLanguage(env); |
239 } | 328 } |
329 | |
330 protected void applyInstrumentation(Node node) { | |
331 INSTRUMENT.applyInstrumentation(node); | |
332 } | |
240 } | 333 } |