Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/vm/LanguageCache.java @ 22117:fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Sat, 29 Aug 2015 01:34:41 +0200 |
parents | |
children |
rev | line source |
---|---|
22117
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 * questions. |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 */ |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.vm; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
26 |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.TruffleLanguage; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.vm.TruffleVM.Language; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
29 import java.util.HashMap; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 import java.util.Map; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
32 /** |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
33 * Ahead-of-time initialization. If the JVM is started with -Dcom.oracle.truffle.aot=true, it |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
34 * populates cache with languages found in application classloader. |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
35 */ |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
36 final class LanguageCache { |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
37 private static final boolean PRELOAD; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 private static final Map<String, TruffleLanguage<?>> CACHE; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
39 static { |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
40 Map<String, TruffleLanguage<?>> map = null; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
41 if (Boolean.getBoolean("com.oracle.truffle.aot")) { // NOI18N |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
42 map = new HashMap<>(); |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
43 for (Language description : TruffleVM.newVM().build().getLanguages().values()) { |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
44 TruffleLanguage<?> language = description.getImpl(); |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
45 map.put(language.getClass().getName(), language); |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
46 } |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
47 } |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
48 CACHE = map; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
49 PRELOAD = CACHE != null; |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
50 } |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
51 |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
52 static TruffleLanguage<?> find(String name, ClassLoader loader) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException { |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
53 if (PRELOAD) { |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
54 return CACHE.get(name); |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
55 } else { |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
56 Class<?> langClazz = Class.forName(name, true, loader); |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
57 return (TruffleLanguage<?>) langClazz.getField("INSTANCE").get(null); |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
58 } |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
59 } |
fab555eab36e
Returning back the LanguageCache concept just making sure it has static final boolean field that eliminates the reflection part when ahead of time compilation is on.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
60 } |