Review Request: JDK-8235521: Replacement API for Unsafe::ensureClassInitialized

Mandy Chung mandy.chung at oracle.com
Thu Jun 4 02:38:57 UTC 2020



On 6/3/20 6:24 PM, John Rose wrote:
> On Jun 3, 2020, at 5:16 PM, Paul Sandoz <paul.sandoz at oracle.com 
> <mailto:paul.sandoz at oracle.com>> wrote:
>>
>>  if (UNSAFE.shouldBeInitialized(cls)) {
>>      UNSAFE.ensureClassInitialized(cls);
>>  }
>>
>> Although it seems redundant to perform the check, suggesting it is 
>> not needed.
>
> It’s useful (IIRC) in this kind of code:
>
> MethodHandle mh = … something about cls ...;
>  if (!UNSAFE.shouldBeInitialized(cls))
>     return mh;
> // Oops, every eventual call to mh needs to do the check:
> return filterArguments(mh, 0, UNSAFE_ensureClassInitialized.bindTo(cls));
>

It is useful for method handle machinery.   I don't see the need to 
expose it as a supported API for java applications/framework.

Maybe useful for dynamic languages?

Mandy


More information about the core-libs-dev mailing list