RFR 6642881: Improve performance of Class.getClassLoader()

Mandy Chung mandy.chung at oracle.com
Wed Jun 18 19:42:11 UTC 2014


On 6/18/2014 12:38 PM, Coleen Phillimore wrote:
>
> On 6/18/14, 3:27 PM, Mandy Chung wrote:
>>
>> On 6/18/2014 11:35 AM, Coleen Phillimore wrote:
>>>
>>>     /*
>>>      * Private constructor. Only the Java Virtual Machine creates Class
>>>      * objects.  This constructor is not used but prevents a warning 
>>> that
>>>      * classLoader is not initialized.  The initialization value of 
>>> non-null
>>>      * prevents future JIT optimizations from assuming this final 
>>> field is null.
>>>      */
>>>
>>
>> As David points out, the private constructor is to avoid the default 
>> constructor being generated.  Your change to initialize the final 
>> classloader field is a second reason.  The second statement reads to 
>> me like the reason for this private constructor is for the warning 
>> reason.  Perhaps "but prevents... " gets me confused and maybe that 
>> part is not really needed? Your change looks good anyway.
>
> How about this?  I separated out the two concerns.
>
>     /*
>      * Private constructor. Only the Java Virtual Machine creates 
> Class objects.
>      * This constructor is not used and prevents the default 
> constructor being
>      * generated.
>      */
>     private Class(ClassLoader loader) {
>         // Initialize final field for classLoader.  The initialization 
> value of non-null
>         // prevents future JIT optimizations from assuming this final 
> field is null.
>         classLoader = loader;
>     }
>

Looks okay with me.
Mandy


More information about the jdk9-dev mailing list