# HG changeset patch # User Doug Simon # Date 1433575417 -7200 # Node ID 55058b8000eab8091f23873b3932dded07b2c1a0 # Parent 75daca0c6a0f017d855f7e614d82da3f79372600 updated javadoc to document that JVMCI services are disjoint from the standard service loading mechanism and tightened generic type constraint such that Services and @ServiceProcessor can only be used with classes implementing Service diff -r 75daca0c6a0f -r 55058b8000ea graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java --- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java Fri Jun 05 23:54:02 2015 +0200 +++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java Sat Jun 06 09:23:37 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 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(); diff -r 75daca0c6a0f -r 55058b8000ea graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java --- a/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java Fri Jun 05 23:54:02 2015 +0200 +++ b/graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/OptionsLoader.java Sat Jun 06 09:23:37 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); diff -r 75daca0c6a0f -r 55058b8000ea graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java --- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java Fri Jun 05 23:54:02 2015 +0200 +++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Service.java Sat Jun 06 09:23:37 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 { } diff -r 75daca0c6a0f -r 55058b8000ea graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java --- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java Fri Jun 05 23:54:02 2015 +0200 +++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/ServiceProvider.java Sat Jun 06 09:23:37 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 { diff -r 75daca0c6a0f -r 55058b8000ea graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java --- a/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java Fri Jun 05 23:54:02 2015 +0200 +++ b/graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/Services.java Sat Jun 06 09:23:37 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 * {@link RuntimePermission}("jvmciServices") */ @SuppressWarnings("unchecked") @CallerSensitive - public static Iterable load(Class service) { + public static Iterable load(Class service) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new RuntimePermission("jvmciServices")); } - if (Service.class.isAssignableFrom(service)) { - try { - return (Iterable) cache.get(service); - } catch (UnsatisfiedLinkError e) { - // Fall back to standard ServiceLoader - } + try { + return (Iterable) 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 loadSingle(Class service, boolean required) { + public static S loadSingle(Class service, boolean required) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new RuntimePermission("jvmciServices")); } Iterable impls; - if (Service.class.isAssignableFrom(service)) { - try { - impls = (Iterable) cache.get(service); - } catch (UnsatisfiedLinkError e) { - // Fall back to standard ServiceLoader - impls = null; - } - } else { - impls = null; + try { + impls = (Iterable) 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) { diff -r 75daca0c6a0f -r 55058b8000ea mx/suite.py --- a/mx/suite.py Fri Jun 05 23:54:02 2015 +0200 +++ b/mx/suite.py Sat Jun 06 09:23:37 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",