Mercurial > hg > truffle
comparison graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java @ 21607:71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 29 May 2015 22:27:38 +0200 |
parents | 93f282187d90 |
children | 2f92172fa320 |
comparison
equal
deleted
inserted
replaced
21606:625b2b12b418 | 21607:71b338926f2e |
---|---|
24 | 24 |
25 import static java.lang.String.*; | 25 import static java.lang.String.*; |
26 | 26 |
27 import java.util.*; | 27 import java.util.*; |
28 | 28 |
29 import sun.reflect.*; | |
30 | |
29 /** | 31 /** |
30 * A mechanism on top of the standard {@link ServiceLoader} that enables a runtime to efficiently | 32 * A mechanism on top of the standard {@link ServiceLoader} that enables a runtime to efficiently |
31 * load services marked by {@link Service}. This may be important for services loaded early in the | 33 * load services marked by {@link Service}. This may be important for services loaded early in the |
32 * runtime initialization process. | 34 * runtime initialization process. |
33 */ | 35 */ |
48 | 50 |
49 /** | 51 /** |
50 * Gets an {@link Iterable} of the implementations available for a given service. | 52 * Gets an {@link Iterable} of the implementations available for a given service. |
51 */ | 53 */ |
52 @SuppressWarnings("unchecked") | 54 @SuppressWarnings("unchecked") |
55 @CallerSensitive | |
53 public static <S> Iterable<S> load(Class<S> service) { | 56 public static <S> Iterable<S> load(Class<S> service) { |
54 if (Service.class.isAssignableFrom(service)) { | 57 if (Service.class.isAssignableFrom(service)) { |
55 try { | 58 try { |
56 return (Iterable<S>) cache.get(service); | 59 return (Iterable<S>) cache.get(service); |
57 } catch (UnsatisfiedLinkError e) { | 60 } catch (UnsatisfiedLinkError e) { |
58 // Fall back to standard SerivceLoader | 61 // Fall back to standard ServiceLoader |
59 } | 62 } |
60 } | 63 } |
61 return ServiceLoader.load(service, Services.class.getClassLoader()); | 64 |
65 // Need to use the ClassLoader of the caller | |
66 ClassLoader cl = Reflection.getCallerClass().getClassLoader(); | |
67 return ServiceLoader.load(service, cl); | |
62 } | 68 } |
63 | 69 |
64 private static native <S> S[] getServiceImpls(Class<?> service); | 70 private static native <S> S[] getServiceImpls(Class<?> service); |
65 } | 71 } |