ServiceLoader in the JDK
Alan Bateman
Alan.Bateman at oracle.com
Wed May 23 11:29:36 PDT 2012
On 23/05/2012 17:31, Paul Sandoz wrote:
> Hi,
>
> Here is some proposed changes in the JDK related to service loader (not tested yet! just want some easily feedback):
>
> http://cr.openjdk.java.net/~psandoz/jigsaw/jdk-services/webrev/
>
> I have attempted where possible to tidy things up to avoid an explicit reference to a class loader for common patterns hence the addition of the methods ServiceLoader.loadFromClass, ServiceLoader.loadFromSystem and ServiceLoader.loadFromCaller (when in module mode most ServiceLoader.load* method do the equivalent of the latter). The names could be better.
I agree the names are problematic, I'm also not sure that we really need
them either.
loadFromClass(c) is specified to work like load(c,c.getClassLoader())
but it works differently when working with modules?
loadFromSystem is specified to use the system class loader so will be
confusing when running with modules. For the 10 or so cases in the JDK
then an alternative push the check back to the use sites.
I'm also not sure about loadFromCaller. Determining the caller is
expensive and at least for the usages in the JDK then
load(Class,ClassLoader) should be okay.
One other thing about ServiceLoader is that we have to put in a few
hacks (to use the caller loader) in order to keep it working with
existing code. Once all usages are cleaned then this of course can be
re-vistied.
Anyway, I scanned the rest of the JDK patch. One thing is that we'll
need to work out spec/javadoc changes for many of these cases.
I would suggest ignoring JMX for now as it will require a special update.
JDI is specified to use Connector and TransportService providers using
the defining loader of the Connector and TransportService types so I
don't think it requires any changes.
Phil may be able to say something about the rendering engine code but I
think this is just for switching between rendering engines and that they
are will all be loaded by the module loader for the desktop module.
Mandy will likely have an opinion on jconsole but my take is that it's
mostly replaced by VisualVM now and maybe we don't do anything and run
just it with -Xmode:legacy.
Having dump-config include the services configuration is a good idea.
-Alan.
More information about the jigsaw-dev
mailing list