Request Review: JDK-6479237 (cl) Add support for classloader names
David M. Lloyd
david.lloyd at redhat.com
Wed Oct 26 13:28:56 UTC 2016
On 10/25/2016 06:10 PM, Mandy Chung wrote:
> Webrev at:
> http://cr.openjdk.java.net/~mchung/jdk9/webrevs/6479237/webrev.00/
>
> Specdiff:
> http://cr.openjdk.java.net/~mchung/jdk9/webrevs/6479237/specdiff/overview-summary.html
>
> This is a long-standing RFE for adding support for class
> loader names. It's #ClassLoaderNames on JSR 376 issue
> list where the proposal [1] has been implemented in jake
> for some time. This patch brings this change to jdk9.
>
> A short summary:
> - New constructors are added in ClassLoader, SecureClassLoader
> and URLClassLoader to specify the class loader name.
>
> - New ClassLoader::getName and StackTraceElement::getClassLoaderName
> method
>
> - StackTraceElement::toString is updated to include the name
> of the class loader and module of that frame in this format:
> <loader>/<module>/<fully-qualified-name>(<src>:<line>)
>
> The detail is in StackTraceElement::buildLoaderModuleClassName
> that compress the output string for cases when the loader
> has no name or the module is unnamed module. Another thing
> to mention is that VM sets the Class object when filling in
> a stack trace of a Throwable object. Then the library will
> build a String from the Class object for serialization purpose.
I am not a reviewer. I have a question though: Does this mean that you
have to establish the name of your class loader in the constructor?
If so, here's what mainly bothers me about this approach:
- With a new constructor being required, you cannot easily write a class
loader which both functions under Java 8 and has a name under Java 9
without resorting to MR JARs
- The getName() method can be overridden but doing so has no effect on
the real name of the class loader
- ... but you can't make it final or you risk breaking class loaders
that already exist
Maybe instead, the "name" field (or other internal mechanism) could
somehow be lazily populated by calling getName(), which returns null by
default but can be overridden by subclasses? This way ClassLoaders can
function the same way in Java 8 and 9, and just get extra functionality
when running under Java 9.
--
- DML
More information about the jigsaw-dev
mailing list