diff 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
line wrap: on
line diff
--- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java	Fri May 29 13:19:05 2015 -0700
+++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java	Fri May 29 22:27:38 2015 +0200
@@ -26,6 +26,8 @@
 
 import java.util.*;
 
+import sun.reflect.*;
+
 /**
  * A mechanism on top of the standard {@link ServiceLoader} that enables a runtime to efficiently
  * load services marked by {@link Service}. This may be important for services loaded early in the
@@ -50,15 +52,19 @@
      * Gets an {@link Iterable} of the implementations available for a given service.
      */
     @SuppressWarnings("unchecked")
+    @CallerSensitive
     public static <S> Iterable<S> load(Class<S> service) {
         if (Service.class.isAssignableFrom(service)) {
             try {
                 return (Iterable<S>) cache.get(service);
             } catch (UnsatisfiedLinkError e) {
-                // Fall back to standard SerivceLoader
+                // Fall back to standard ServiceLoader
             }
         }
-        return ServiceLoader.load(service, Services.class.getClassLoader());
+
+        // Need to use the ClassLoader of the caller
+        ClassLoader cl = Reflection.getCallerClass().getClassLoader();
+        return ServiceLoader.load(service, cl);
     }
 
     private static native <S> S[] getServiceImpls(Class<?> service);