Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/PolyglotEngine.java @ 22194:7afb5e5cc3ca
Fix use just one language instance per LanguageCache instead of one per mime-type.
author | Christian Humer <christian.humer@oracle.com> |
---|---|
date | Thu, 24 Sep 2015 14:48:26 +0200 |
parents | 2e7352f9ffa8 |
children | 364e3f024643 |
comparison
equal
deleted
inserted
replaced
22193:dd0b18eb8000 | 22194:7afb5e5cc3ca |
---|---|
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.vm; | 25 package com.oracle.truffle.api.vm; |
26 | 26 |
27 import com.oracle.truffle.api.CallTarget; | |
28 import com.oracle.truffle.api.TruffleLanguage; | |
29 import com.oracle.truffle.api.TruffleLanguage.Env; | |
30 import com.oracle.truffle.api.TruffleLanguage.Registration; | |
31 import com.oracle.truffle.api.debug.DebugSupportProvider; | |
32 import com.oracle.truffle.api.debug.Debugger; | |
33 import com.oracle.truffle.api.debug.ExecutionEvent; | |
34 import com.oracle.truffle.api.debug.SuspendedEvent; | |
35 import com.oracle.truffle.api.impl.Accessor; | |
36 import com.oracle.truffle.api.instrument.Probe; | |
37 import com.oracle.truffle.api.instrument.ToolSupportProvider; | |
38 import com.oracle.truffle.api.interop.TruffleObject; | |
39 import com.oracle.truffle.api.interop.java.JavaInterop; | |
40 import com.oracle.truffle.api.source.Source; | |
41 import java.io.Closeable; | 27 import java.io.Closeable; |
42 import java.io.File; | 28 import java.io.File; |
43 import java.io.IOException; | 29 import java.io.IOException; |
44 import java.io.InputStream; | 30 import java.io.InputStream; |
45 import java.io.InterruptedIOException; | 31 import java.io.InterruptedIOException; |
54 import java.nio.file.Files; | 40 import java.nio.file.Files; |
55 import java.util.ArrayList; | 41 import java.util.ArrayList; |
56 import java.util.Arrays; | 42 import java.util.Arrays; |
57 import java.util.Collections; | 43 import java.util.Collections; |
58 import java.util.HashMap; | 44 import java.util.HashMap; |
45 import java.util.HashSet; | |
59 import java.util.LinkedHashSet; | 46 import java.util.LinkedHashSet; |
60 import java.util.List; | 47 import java.util.List; |
61 import java.util.Map; | 48 import java.util.Map; |
62 import java.util.Set; | 49 import java.util.Set; |
63 import java.util.concurrent.CountDownLatch; | 50 import java.util.concurrent.CountDownLatch; |
64 import java.util.concurrent.Executor; | 51 import java.util.concurrent.Executor; |
65 import java.util.logging.Level; | 52 import java.util.logging.Level; |
66 import java.util.logging.Logger; | 53 import java.util.logging.Logger; |
54 | |
55 import com.oracle.truffle.api.CallTarget; | |
56 import com.oracle.truffle.api.TruffleLanguage; | |
57 import com.oracle.truffle.api.TruffleLanguage.Env; | |
58 import com.oracle.truffle.api.TruffleLanguage.Registration; | |
59 import com.oracle.truffle.api.debug.DebugSupportProvider; | |
60 import com.oracle.truffle.api.debug.Debugger; | |
61 import com.oracle.truffle.api.debug.ExecutionEvent; | |
62 import com.oracle.truffle.api.debug.SuspendedEvent; | |
63 import com.oracle.truffle.api.impl.Accessor; | |
64 import com.oracle.truffle.api.instrument.Probe; | |
65 import com.oracle.truffle.api.instrument.ToolSupportProvider; | |
66 import com.oracle.truffle.api.interop.TruffleObject; | |
67 import com.oracle.truffle.api.interop.java.JavaInterop; | |
68 import com.oracle.truffle.api.source.Source; | |
67 | 69 |
68 /** | 70 /** |
69 * Gate way into the world of {@link TruffleLanguage Truffle languages}. {@link #buildNew() | 71 * Gate way into the world of {@link TruffleLanguage Truffle languages}. {@link #buildNew() |
70 * Instantiate} your own portal into the isolated, multi language system with all the registered | 72 * Instantiate} your own portal into the isolated, multi language system with all the registered |
71 * languages ready for your use. A {@link PolyglotEngine} runs inside of a <em>JVM</em>, there can | 73 * languages ready for your use. A {@link PolyglotEngine} runs inside of a <em>JVM</em>, there can |
138 this.in = in; | 140 this.in = in; |
139 this.handlers = handlers; | 141 this.handlers = handlers; |
140 this.initThread = Thread.currentThread(); | 142 this.initThread = Thread.currentThread(); |
141 this.globals = new HashMap<>(globals); | 143 this.globals = new HashMap<>(globals); |
142 Map<String, Language> map = new HashMap<>(); | 144 Map<String, Language> map = new HashMap<>(); |
143 for (Map.Entry<String, LanguageCache> en : LanguageCache.languages().entrySet()) { | 145 /* We want to create a language instance but per LanguageCache and not per mime type. */ |
144 map.put(en.getKey(), createLanguage(en)); | 146 Set<LanguageCache> uniqueCaches = new HashSet<>(LanguageCache.languages().values()); |
147 for (LanguageCache languageCache : uniqueCaches) { | |
148 Language newLanguage = new Language(languageCache); | |
149 for (String mimeType : newLanguage.getMimeTypes()) { | |
150 map.put(mimeType, newLanguage); | |
151 } | |
145 } | 152 } |
146 this.langs = map; | 153 this.langs = map; |
147 } | 154 } |
148 | 155 |
149 /** | 156 /** |
675 /** | 682 /** |
676 * Obtains Java view of the object represented by this symbol. The method basically | 683 * Obtains Java view of the object represented by this symbol. The method basically |
677 * delegates to | 684 * delegates to |
678 * {@link JavaInterop#asJavaObject(java.lang.Class, com.oracle.truffle.api.interop.TruffleObject)} | 685 * {@link JavaInterop#asJavaObject(java.lang.Class, com.oracle.truffle.api.interop.TruffleObject)} |
679 * just handles primitive types as well. | 686 * just handles primitive types as well. |
680 * | 687 * |
681 * @param <T> the type of the view one wants to obtain | 688 * @param <T> the type of the view one wants to obtain |
682 * @param representation the class of the view interface (it has to be an interface) | 689 * @param representation the class of the view interface (it has to be an interface) |
683 * @return instance of the view wrapping the object of this symbol | 690 * @return instance of the view wrapping the object of this symbol |
684 * @throws IOException in case it is not possible to obtain the value of the object | 691 * @throws IOException in case it is not possible to obtain the value of the object |
685 * @throws ClassCastException if the value cannot be converted to desired view | 692 * @throws ClassCastException if the value cannot be converted to desired view |