> On Jun 3, 2020, at 7:31 PM, Mandy Chung <mandy.ch...@oracle.com> wrote:
> 
> 
> 
> On 6/3/20 5:16 PM, Paul Sandoz wrote:
>> Hi Mandy,
>> 
>> Did you consider an alternative name, such as:
>> 
>> /**
>>  * Initializes {@code targetClass}, if not already initialized.
>>  * ...
>> */
>> public Class<?> initializeClass(Class<?> targetClass) ...
>> 
>> ?
> 
> I considered this.   The targetClass may have been initialized.  
> `initializeClass` seems to be read that it should check if it's initialized 
> before calling??    I also considered `ensureInitialized` which can be an 
> option.   I'm open to suggestion.
> 

FWIW I keep tripping over the prefix “ensures”.  As I understand the 
implementation initializes a class, if not already so (and it has to check as 
you point out below). Focusing on the main action seems appropriate in this 
regard. I expect John has more context on the naming.


>> What about the companion Unsafe.shouldBeInitialized? I have seen (and 
>> written) code like this:
>> 
>>   if (UNSAFE.shouldBeInitialized(cls)) {
>>       UNSAFE.ensureClassInitialized(cls);
>>   }
> 
> A class may be initialized in many ways as specified in JVMS 5.5 (e.g. 
> another thread accesses a static member of this class).   The class may get 
> initialized right after `shouldBeInitialized` returns true.   
> `ensureClassInitialized` handles the case when the class has been initialized 
> and I don't see the need to expose it.
> 

Ok.

>> Although it seems redundant to perform the check, suggesting it is not 
>> needed.
>> 
>> I believe there is also some gnarly case during a clinit of C where 
>> ensureClassInitialized(C) is called and a subsequent call to 
>> shouldBeInitialized(C) returns true. Is that correct? If so it makes me 
>> reluctant to expose it and try and explain the edge cases.
> 
> Yes.
>> Maybe if we don’t think Unsafe.shouldBeInitialized needs a supported 
>> equivalent we can still deprecate it?
> 
> Good idea.   I will update the patch and CSR.
> 

Ok.

Paul.

Reply via email to