JDK support for VM to read classes from modules in a module library

Paul Sandoz paul.sandoz at oracle.com
Thu May 10 01:49:43 PDT 2012


On May 9, 2012, at 6: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.

OK.


>  BTW, I have been talking with Jon to find out the usage of "null" class loader from corpus.  

I hope the usage of that is low.


> I can also gather Class.forName usage and send it to you.
> 

Please. (Note: NetBeans is quite fast on the JDK code base now for method use search.)

It is clear from looking at the changes to some areas you made (and my comprehension of "initialize") that this is an area often misunderstood (e.g. passing String.class.getClassLoader() to Class.forName).


>> 
>> 
>> 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.
> 

Ah!


>> 
>> 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.
> 

Could we update the JavaDoc :-)

@param initialize if true the class will be initialized (specifically the class static initializer will be invoked) [refer to errors on initialization], otherwise the class is not initialized [refer to when it will be initialized].

Thanks,
Paul.


More information about the jigsaw-dev mailing list