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

John Rose john.r.rose at oracle.com
Thu Jun 4 01:24:08 UTC 2020


On Jun 3, 2020, at 5:16 PM, Paul Sandoz <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));



More information about the core-libs-dev mailing list