Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java @ 24225:a2dbb6fcc923
Added tag jvmci-0.33 for changeset 3aed4cb813f4
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 18 Aug 2017 22:47:33 +0200 |
parents | 3f81f36d2c99 |
children |
rev | line source |
---|---|
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
22761
f2206f5bb62e
removed @ServiceProvider mechanism (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
23 package jdk.vm.ci.services; |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
24122
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
25 import java.lang.reflect.Field; |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22430
diff
changeset
|
26 import java.util.Collections; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22430
diff
changeset
|
27 import java.util.Formatter; |
24126
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
28 import java.util.HashMap; |
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
29 import java.util.Map; |
24122
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
30 import java.util.Properties; |
23408
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
23380
diff
changeset
|
31 import java.util.ServiceLoader; |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 |
24122
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
33 import sun.misc.VM; |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22430
diff
changeset
|
34 import sun.reflect.Reflection; |
21607
71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21604
diff
changeset
|
35 |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 /** |
21937
3a292e8b9e51
replaced Service marker interface with non-standard META-INF directory names to differentiate JVMCI providers from standard service providers
Doug Simon <doug.simon@oracle.com>
parents:
21895
diff
changeset
|
37 * An mechanism for accessing service providers via JVMCI. These providers are loaded via a JVMCI |
3a292e8b9e51
replaced Service marker interface with non-standard META-INF directory names to differentiate JVMCI providers from standard service providers
Doug Simon <doug.simon@oracle.com>
parents:
21895
diff
changeset
|
38 * class loader that is hidden from application code. Hence the {@link SecurityManager} checks in |
3a292e8b9e51
replaced Service marker interface with non-standard META-INF directory names to differentiate JVMCI providers from standard service providers
Doug Simon <doug.simon@oracle.com>
parents:
21895
diff
changeset
|
39 * {@link #load(Class)} and {@link #loadSingle(Class, boolean)}. |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 */ |
21941
ef76ce87cc13
Services cannot be sub-classes or instantiated
Doug Simon <doug.simon@oracle.com>
parents:
21937
diff
changeset
|
41 public final class Services { |
ef76ce87cc13
Services cannot be sub-classes or instantiated
Doug Simon <doug.simon@oracle.com>
parents:
21937
diff
changeset
|
42 |
ef76ce87cc13
Services cannot be sub-classes or instantiated
Doug Simon <doug.simon@oracle.com>
parents:
21937
diff
changeset
|
43 private Services() { |
ef76ce87cc13
Services cannot be sub-classes or instantiated
Doug Simon <doug.simon@oracle.com>
parents:
21937
diff
changeset
|
44 } |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 |
24122
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
46 /** |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
47 * Gets the system properties saved when {@link System} is initialized. The caller must not |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
48 * modify the returned value. |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
49 */ |
24126
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
50 public static Map<String, String> getSavedProperties() { |
24122
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
51 SecurityManager sm = System.getSecurityManager(); |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
52 if (sm != null) { |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
53 sm.checkPermission(new JVMCIPermission()); |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
54 } |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
55 try { |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
56 Field savedPropsField = VM.class.getDeclaredField("savedProps"); |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
57 savedPropsField.setAccessible(true); |
24126
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
58 Properties props = (Properties) savedPropsField.get(null); |
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
59 Map<String, String> res = new HashMap<>(props.size()); |
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
60 for (Map.Entry<Object, Object> e : props.entrySet()) { |
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
61 res.put((String) e.getKey(), (String) e.getValue()); |
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
62 } |
c80b6f33b3d9
changed return type of Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24122
diff
changeset
|
63 return res; |
24122
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
64 } catch (Exception e) { |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
65 throw new InternalError(e); |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
66 } |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
67 } |
c6b5d927e67f
added Services.getSavedProperties (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24110
diff
changeset
|
68 |
24130
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
69 /** |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
70 * Causes the JVMCI subsystem to be initialized if it isn't already initialized. |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
71 */ |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
72 public static void initializeJVMCI() { |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
73 try { |
24133
3f81f36d2c99
need to use the JVMCI class loader when initializing JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
24130
diff
changeset
|
74 Class.forName("jdk.vm.ci.runtime.JVMCI", true, Services.getJVMCIClassLoader()); |
24130
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
75 } catch (ClassNotFoundException e) { |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
76 throw new InternalError(e); |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
77 } |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
78 } |
0386b21ed2b3
added Services.initializeJVMCI (JDK-8177845)
Doug Simon <doug.simon@oracle.com>
parents:
24126
diff
changeset
|
79 |
23692
93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
Doug Simon <doug.simon@oracle.com>
parents:
23408
diff
changeset
|
80 private static boolean jvmciEnabled = true; |
21675
2e8c01def9a5
moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21662
diff
changeset
|
81 |
24110
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
82 private static <S> Iterable<S> load0(Class<S> service) { |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
83 if (jvmciEnabled) { |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
84 ClassLoader cl = null; |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
85 try { |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
86 cl = getJVMCIClassLoader(); |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
87 return ServiceLoader.load(service, cl); |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
88 } catch (UnsatisfiedLinkError e) { |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
89 jvmciEnabled = false; |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
90 } catch (InternalError e) { |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
91 if (e.getMessage().equals("JVMCI is not enabled")) { |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
92 jvmciEnabled = false; |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
93 } else { |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
94 throw e; |
21675
2e8c01def9a5
moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21662
diff
changeset
|
95 } |
2e8c01def9a5
moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21662
diff
changeset
|
96 } |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 } |
24110
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
98 return Collections.emptyList(); |
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
99 } |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 /** |
23369
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
102 * Performs any required security checks and dynamic reconfiguration to allow the module of a |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
103 * given class to access the classes in the JVMCI module. |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
104 * |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
105 * Note: This API exists to provide backwards compatibility for JVMCI clients compiled against a |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
106 * JDK release earlier than 9. |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
107 * |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
108 * @param requestor a class requesting access to the JVMCI module for its module |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
109 * @throws SecurityException if a security manager is present and it denies |
23380
cd8fd4cced6c
added JVMCIPermission (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23369
diff
changeset
|
110 * {@link JVMCIPermission} |
23369
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
111 */ |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
112 public static void exportJVMCITo(Class<?> requestor) { |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
113 // There are no modules in JVMCI-8. |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
114 } |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
115 |
5aa3b3a72e35
jdk.vm.ci needs to securely export services (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23359
diff
changeset
|
116 /** |
21895
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
117 * Gets an {@link Iterable} of the JVMCI providers available for a given service. |
21636
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
118 * |
23297
4b58c92e939b
remove redundant modifiers
Manuel Rigger <rigger.manuel@gmail.com>
parents:
22761
diff
changeset
|
119 * @throws SecurityException if a security manager is present and it denies <tt> |
23359
9779df770504
align the permission checked by Services with jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23297
diff
changeset
|
120 * {@link RuntimePermission}("jvmci")</tt> |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 */ |
21887
543f150e7fa0
com.oracle.jvmci.service.Service is now a marker for service implementations available via JVMCI; removed Truffle -> JVMCI dependency
Doug Simon <doug.simon@oracle.com>
parents:
21799
diff
changeset
|
122 public static <S> Iterable<S> load(Class<S> service) { |
21636
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
123 SecurityManager sm = System.getSecurityManager(); |
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
124 if (sm != null) { |
23380
cd8fd4cced6c
added JVMCIPermission (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23369
diff
changeset
|
125 sm.checkPermission(new JVMCIPermission()); |
21636
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
126 } |
24110
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
127 return load0(service); |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
128 } |
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
129 |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
130 /** |
21895
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
131 * Gets the JVMCI provider for a given service for which at most one provider must be available. |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
132 * |
21895
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
133 * @param service the service whose provider is being requested |
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
134 * @param required specifies if an {@link InternalError} should be thrown if no provider of |
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
135 * {@code service} is available |
23297
4b58c92e939b
remove redundant modifiers
Manuel Rigger <rigger.manuel@gmail.com>
parents:
22761
diff
changeset
|
136 * @throws SecurityException if a security manager is present and it denies <tt> |
23359
9779df770504
align the permission checked by Services with jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23297
diff
changeset
|
137 * {@link RuntimePermission}("jvmci")</tt> |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
138 */ |
21887
543f150e7fa0
com.oracle.jvmci.service.Service is now a marker for service implementations available via JVMCI; removed Truffle -> JVMCI dependency
Doug Simon <doug.simon@oracle.com>
parents:
21799
diff
changeset
|
139 public static <S> S loadSingle(Class<S> service, boolean required) { |
21636
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
140 SecurityManager sm = System.getSecurityManager(); |
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
141 if (sm != null) { |
23380
cd8fd4cced6c
added JVMCIPermission (JDK-8155023)
Doug Simon <doug.simon@oracle.com>
parents:
23369
diff
changeset
|
142 sm.checkPermission(new JVMCIPermission()); |
21636
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
143 } |
24110
a8378ff1936d
remove use of cache in jdk.vm.ci.services.Services (GR-3293)
Doug Simon <doug.simon@oracle.com>
parents:
23692
diff
changeset
|
144 Iterable<S> providers = load0(service); |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
145 |
21895
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
146 S singleProvider = null; |
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
147 for (S provider : providers) { |
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
148 if (singleProvider != null) { |
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
149 throw new InternalError(String.format("Multiple %s providers found: %s, %s", service.getName(), singleProvider.getClass().getName(), provider.getClass().getName())); |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
150 } |
21895
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
151 singleProvider = provider; |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
152 } |
21895
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
153 if (singleProvider == null && required) { |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
154 String javaHome = System.getProperty("java.home"); |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
155 String vmName = System.getProperty("java.vm.name"); |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
156 Formatter errorMessage = new Formatter(); |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
157 errorMessage.format("The VM does not expose required service %s.%n", service.getName()); |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
158 errorMessage.format("Currently used Java home directory is %s.%n", javaHome); |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
159 errorMessage.format("Currently used VM configuration is: %s", vmName); |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
160 throw new UnsupportedOperationException(errorMessage.toString()); |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
161 } |
21895
763db13bd6f4
reworded Service documentation to be interms of "providers" instead of "implementations" to better match documentation for the standard ServiceLoader mechanism
Doug Simon <doug.simon@oracle.com>
parents:
21887
diff
changeset
|
162 return singleProvider; |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
163 } |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21607
diff
changeset
|
164 |
21636
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
165 static { |
23408
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
23380
diff
changeset
|
166 Reflection.registerMethodsToFilter(Services.class, "getJVMCIClassLoader"); |
21636
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
167 } |
6d9c8d0d0f7c
added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
21633
diff
changeset
|
168 |
23692
93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
Doug Simon <doug.simon@oracle.com>
parents:
23408
diff
changeset
|
169 /** |
93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
Doug Simon <doug.simon@oracle.com>
parents:
23408
diff
changeset
|
170 * Gets the JVMCI class loader. |
93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
Doug Simon <doug.simon@oracle.com>
parents:
23408
diff
changeset
|
171 * |
93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
Doug Simon <doug.simon@oracle.com>
parents:
23408
diff
changeset
|
172 * @throws InternalError with the {@linkplain Throwable#getMessage() message} |
93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
Doug Simon <doug.simon@oracle.com>
parents:
23408
diff
changeset
|
173 * {@code "JVMCI is not enabled"} iff JVMCI is not enabled |
93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
Doug Simon <doug.simon@oracle.com>
parents:
23408
diff
changeset
|
174 */ |
23408
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
23380
diff
changeset
|
175 private static native ClassLoader getJVMCIClassLoader(); |
15916
6aa352b260f4
removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
176 } |