JDK support for VM to read classes from modules in a module library
Rémi Forax
forax at univ-mlv.fr
Wed May 9 10:29:08 PDT 2012
On 05/09/2012 06:52 PM, Mandy Chung wrote:
> Hi Paul,
>
> On 5/9/2012 8:44 AM, Paul Sandoz wrote:
>> Hi Mandy,
>>
>> Regarding the change to com/sun/jmx/mbeanserver/MXBeanMapping.java:
>>
>> 172 return Class.forName(className, false,
>> MXBeanMapping.class.getClassLoader());
>>
>> Do you think it would make sense to add the following method to Class:
>>
>> public static Class<?> forName(String className, boolean
>> initialize) {
>> return forName0(className, initialize,
>> ClassLoader.getCallerClassLoader());
>> }
>>
>> there by removing the explicit reference to the class loader in
>> MXBeanMapping.java. It intuitively feels like a best practice to
>> reduce the cases of explicitly dealing with a class loader.
>
> That's a good observation and this new convenient method may be useful
> (and less to type). One thing I'm not sure about is how common
> application code calls Class.forName(String, boolean, ClassLoader)
> with the "initialize" parameter be false. i.e. the case when we only
> want a class to be loaded but not to call its static initializer. I
> think it'd be useful to find out how existing code uses Class.forName
> as additional data to determine if it's worth adding this new
> convenient method. BTW, I have been talking with Jon to find out the
> usage of "null" class loader from corpus. I can also gather
> Class.forName usage and send it to you.
In fact, this method is really useful, most of the tools that does
bytecode transformation at runtime
(most O/R mappers, dynamic language runtimes, profilers, code coverage
tools, etc)
are now required to compute the stack frame attribute which requires to
compute the lower upper bound
of a set of types. For that, being able to crawle the type hierachy
without loading the static initializer
is a must have.
>
>>
>>
>> The change to java/lang/management/PlatformComponent.java from:
>>
>> 366 Class.forName(mxbeanInterfaceName,
>> false, null);
>>
>> to:
>>
>> 367 Class.forName(mxbeanInterfaceName);
>>
>> changes the initialization [*] flag from false to true. Is that
>> intended?
>
> mxbeanInterfaceName is an interface which does not have <clinit>.
> This change doesn't cause any
> difference.
interfaces can have a <clinit> if you initialize a static final field
that store something which is not
a primitive type or a String, e.g. an ArrayList.
>
>>
>> Paul.
>>
>> [*] i must admit to never quite understanding what this flag means.
>> Java doc states that for initialize parameter "whether the class must
>> be initialized". Is that a constraint or an action? I presume the later.
>
> Yes, the later - that indicates whether the class static initializer
> will be invoked or not.
>
> Mandy
Rémi
More information about the jigsaw-dev
mailing list