changeset 21762:1025d6dc645a

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 06 Jun 2015 15:13:09 +0200
parents 0dfd3ea90d33 (current diff) 55058b8000ea (diff)
children 1ab2c7bb6f0f
files
diffstat 6 files changed, 31 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java	Sat Jun 06 15:12:58 2015 +0200
+++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java	Sat Jun 06 15:13:09 2015 +0200
@@ -25,7 +25,6 @@
 import java.util.*;
 
 import com.oracle.jvmci.options.*;
-import com.oracle.jvmci.service.*;
 
 //JaCoCo Exclude
 
@@ -42,7 +41,8 @@
      */
     static void printFlags() {
         SortedMap<String, OptionDescriptor> options = new TreeMap<>();
-        for (Options opts : Services.load(Options.class)) {
+
+        for (Options opts : ServiceLoader.load(Options.class, HotSpotOptions.class.getClassLoader())) {
             for (OptionDescriptor desc : opts) {
                 if (isHotSpotOption(desc)) {
                     String name = desc.getName();
--- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java	Sat Jun 06 15:12:58 2015 +0200
+++ b/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java	Sat Jun 06 15:13:09 2015 +0200
@@ -24,8 +24,6 @@
 
 import java.util.*;
 
-import com.oracle.jvmci.service.*;
-
 /**
  * Helper class used to load option descriptors. Only to be used in the slow-path.
  */
@@ -36,7 +34,7 @@
      * Initializes {@link #options} from {@link Options} services.
      */
     static {
-        for (Options opts : Services.load(Options.class)) {
+        for (Options opts : ServiceLoader.load(Options.class, OptionsLoader.class.getClassLoader())) {
             for (OptionDescriptor desc : opts) {
                 String name = desc.getName();
                 OptionDescriptor existing = options.put(name, desc);
--- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java	Sat Jun 06 15:12:58 2015 +0200
+++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java	Sat Jun 06 15:13:09 2015 +0200
@@ -22,8 +22,18 @@
  */
 package com.oracle.jvmci.service;
 
+import java.util.*;
+
 /**
- * Denotes a service that may be efficiently loaded by {@link Services#load(Class)}.
+ * Denotes a JVMCI service that can be loaded by {@link Services#load(Class)} or
+ * {@link Services#loadSingle(Class, boolean)}. JVMCI services differ from
+ * {@linkplain ServiceLoader#load(Class) standard} services in that they may have implementations
+ * hidden behind a class loader not accessible to applications. For this reason,
+ * {@link Services#load(Class)} and {@link Services#loadSingle(Class, boolean)} perform
+ * {@link SecurityManager} checks.
+ *
+ * @see Services
+ * @see ServiceProvider
  */
 public interface Service {
 }
--- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java	Sat Jun 06 15:12:58 2015 +0200
+++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java	Sat Jun 06 15:13:09 2015 +0200
@@ -24,6 +24,11 @@
 
 import java.lang.annotation.*;
 
+/**
+ * Annotates a class that implements a {@linkplain Service JVMCI service}. This annotation is used
+ * by the JVMCI build system to deploy the necessary files used to {@linkplain Services#load(Class)
+ * load} JVMCI services at runtime.
+ */
 @Retention(RetentionPolicy.CLASS)
 @Target(ElementType.TYPE)
 public @interface ServiceProvider {
--- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java	Sat Jun 06 15:12:58 2015 +0200
+++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java	Sat Jun 06 15:13:09 2015 +0200
@@ -27,10 +27,7 @@
 import sun.reflect.*;
 
 /**
- * A mechanism on top of the standard {@link ServiceLoader} that enables JVMCI enabled runtime to
- * efficiently load services marked by {@link Service}. This is important to avoid the performance
- * overhead of the standard service loader mechanism for services loaded in the runtime
- * initialization process.
+ * An mechanism for loading {@linkplain Service JVMCI services}.
  */
 public class Services {
 
@@ -55,29 +52,23 @@
     };
 
     /**
-     * Gets an {@link Iterable} of the implementations available for a given service.
+     * Gets an {@link Iterable} of the implementations available for a given JVMCI service.
      *
      * @throws SecurityException if a security manager is present and it denies
      *             <tt>{@link RuntimePermission}("jvmciServices")</tt>
      */
     @SuppressWarnings("unchecked")
     @CallerSensitive
-    public static <S> Iterable<S> load(Class<S> service) {
+    public static <S extends Service> Iterable<S> load(Class<S> service) {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             sm.checkPermission(new RuntimePermission("jvmciServices"));
         }
-        if (Service.class.isAssignableFrom(service)) {
-            try {
-                return (Iterable<S>) cache.get(service);
-            } catch (UnsatisfiedLinkError e) {
-                // Fall back to standard ServiceLoader
-            }
+        try {
+            return (Iterable<S>) cache.get(service);
+        } catch (UnsatisfiedLinkError e) {
+            return Collections.emptyList();
         }
-
-        // Need to use the ClassLoader of the caller
-        ClassLoader cl = Reflection.getCallerClass().getClassLoader();
-        return ServiceLoader.load(service, cl);
     }
 
     /**
@@ -92,28 +83,18 @@
      */
     @SuppressWarnings("unchecked")
     @CallerSensitive
-    public static <S> S loadSingle(Class<S> service, boolean required) {
+    public static <S extends Service> S loadSingle(Class<S> service, boolean required) {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             sm.checkPermission(new RuntimePermission("jvmciServices"));
         }
         Iterable<S> impls;
-        if (Service.class.isAssignableFrom(service)) {
-            try {
-                impls = (Iterable<S>) cache.get(service);
-            } catch (UnsatisfiedLinkError e) {
-                // Fall back to standard ServiceLoader
-                impls = null;
-            }
-        } else {
-            impls = null;
+        try {
+            impls = (Iterable<S>) cache.get(service);
+        } catch (UnsatisfiedLinkError e) {
+            impls = Collections.emptyList();
         }
 
-        if (impls == null) {
-            // Need to use the ClassLoader of the caller
-            ClassLoader cl = Reflection.getCallerClass().getClassLoader();
-            impls = ServiceLoader.load(service, cl);
-        }
         S singleImpl = null;
         for (S impl : impls) {
             if (singleImpl != null) {
--- a/mx/suite.py	Sat Jun 06 15:12:58 2015 +0200
+++ b/mx/suite.py	Sat Jun 06 15:13:09 2015 +0200
@@ -252,9 +252,6 @@
     "com.oracle.jvmci.options" : {
       "subDir" : "graal",
       "sourceDirs" : ["src"],
-      "dependencies" : [
-        "com.oracle.jvmci.service",
-      ],
       "checkstyle" : "com.oracle.graal.graph",
       "javaCompliance" : "1.8",
       "workingSets" : "JVMCI",