annotate graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java @ 21702:70649030d511

mx archive: exclude dotfiles
author Andreas Woess <andreas.woess@oracle.com>
date Wed, 03 Jun 2015 17:38:26 +0200
parents 2e8c01def9a5
children 55058b8000ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 */
21604
93f282187d90 moved JVMCI service API into separate com.oracle.jvmci.service module (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21558
diff changeset
23 package com.oracle.jvmci.service;
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import java.util.*;
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26
21607
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
27 import sun.reflect.*;
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
28
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 /**
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
30 * A mechanism on top of the standard {@link ServiceLoader} that enables JVMCI enabled runtime to
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
31 * efficiently load services marked by {@link Service}. This is important to avoid the performance
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
32 * overhead of the standard service loader mechanism for services loaded in the runtime
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
33 * initialization process.
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 */
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 public class Services {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36
21675
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
37 /**
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
38 * Determines whether to suppress the {@link NoClassDefFoundError} raised if a service
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
39 * implementation class specified in a {@code <jre>/jvmci/services/*} file is missing.
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
40 */
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
41 private static final boolean SuppressNoClassDefFoundError = Boolean.getBoolean("jvmci.service.suppressNoClassDefFoundError");
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
42
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 private static final ClassValue<List<Service>> cache = new ClassValue<List<Service>>() {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 @Override
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 protected List<Service> computeValue(Class<?> type) {
21675
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
46 try {
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
47 return Arrays.asList(getServiceImpls(type));
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
48 } catch (NoClassDefFoundError e) {
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
49 if (SuppressNoClassDefFoundError) {
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
50 return Collections.emptyList();
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
51 }
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
52 throw e;
2e8c01def9a5 moved [AMD64|SPARC]HotSpotJVMCIBackendFactory into JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21662
diff changeset
53 }
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 };
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 /**
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 * Gets an {@link Iterable} of the implementations 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
59 *
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
60 * @throws SecurityException if a security manager is present and it denies
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
61 * <tt>{@link RuntimePermission}("jvmciServices")</tt>
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 */
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 @SuppressWarnings("unchecked")
21607
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
64 @CallerSensitive
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 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
66 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
67 if (sm != null) {
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
68 sm.checkPermission(new RuntimePermission("jvmciServices"));
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
69 }
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 if (Service.class.isAssignableFrom(service)) {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 try {
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 return (Iterable<S>) cache.get(service);
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 } catch (UnsatisfiedLinkError e) {
21607
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
74 // Fall back to standard ServiceLoader
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 }
21607
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
77
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
78 // Need to use the ClassLoader of the caller
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
79 ClassLoader cl = Reflection.getCallerClass().getClassLoader();
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21604
diff changeset
80 return ServiceLoader.load(service, cl);
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 }
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82
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
83 /**
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
84 * Gets the implementation for a given service for which at most one implementation must be
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
85 * available.
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
86 *
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
87 * @param service the service whose implementation is being requested
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
88 * @param required specifies if an {@link InternalError} should be thrown if no implementation
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
89 * of {@code service} is available
21636
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
90 * @throws SecurityException if a security manager is present and it denies
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
91 * <tt>{@link RuntimePermission}("jvmciServices")</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
92 */
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
93 @SuppressWarnings("unchecked")
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
94 @CallerSensitive
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
95 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
96 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
97 if (sm != null) {
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
98 sm.checkPermission(new RuntimePermission("jvmciServices"));
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
99 }
21662
b45e0f791465 avoid double assignment
Doug Simon <doug.simon@oracle.com>
parents: 21636
diff changeset
100 Iterable<S> impls;
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
101 if (Service.class.isAssignableFrom(service)) {
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
102 try {
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
103 impls = (Iterable<S>) cache.get(service);
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
104 } catch (UnsatisfiedLinkError e) {
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
105 // Fall back to standard ServiceLoader
21662
b45e0f791465 avoid double assignment
Doug Simon <doug.simon@oracle.com>
parents: 21636
diff changeset
106 impls = null;
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
107 }
21662
b45e0f791465 avoid double assignment
Doug Simon <doug.simon@oracle.com>
parents: 21636
diff changeset
108 } else {
b45e0f791465 avoid double assignment
Doug Simon <doug.simon@oracle.com>
parents: 21636
diff changeset
109 impls = null;
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
110 }
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
111
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
112 if (impls == null) {
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
113 // Need to use the ClassLoader of the caller
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
114 ClassLoader cl = Reflection.getCallerClass().getClassLoader();
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
115 impls = ServiceLoader.load(service, cl);
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
116 }
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
117 S singleImpl = null;
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
118 for (S impl : impls) {
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
119 if (singleImpl != null) {
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
120 throw new InternalError(String.format("Multiple %s implementations found: %s, %s", service.getName(), singleImpl.getClass().getName(), impl.getClass().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
121 }
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
122 singleImpl = impl;
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
123 }
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
124 if (singleImpl == null && required) {
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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 }
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
133 return singleImpl;
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
134 }
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
135
21636
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
136 static {
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
137 Reflection.registerMethodsToFilter(Services.class, "getServiceImpls");
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
138 Reflection.registerFieldsToFilter(Services.class, "cache");
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
139 }
6d9c8d0d0f7c added SecurityManager checks and field/method reflection hiding (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents: 21633
diff changeset
140
15916
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
141 private static native <S> S[] getServiceImpls(Class<?> service);
6aa352b260f4 removed use of ServiceLoader in runtime initialization
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
142 }