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

Paul Sandoz paul.sandoz at oracle.com
Thu Jun 4 20:05:46 UTC 2020


> On Jun 4, 2020, at 12:31 PM, Mandy Chung <mandy.chung at oracle.com> wrote:
> 
> JVMS 5.5 is the spec for class initialization.  Step 3 describes the recursive request for initialization.
> 

Ok. (From quick offline chat we agreed its not worth explicitly highlighting this case.)


> I have @jvms 5.5 in the javadoc. I can make it explicit:
> 
>          * Ensures that {@code targetClass} has been initialized. The class
>          * to be initialized must be {@linkplain #accessClass accessible}
>          * to this {@code Lookup} object.  This method causes {@code targetClass}
>          * to be initialized if it has not been already initialized,
>          * as specified in JVMS {@jvms 5.5}.
> 

LGTM,
Paul.

> There are detailed rules about class initialization in JVMS 5.5.
> 
> Mandy
> 

> On 6/4/20 12:13 PM, Paul Sandoz wrote:
>> Hi Mandy,
>> 
>> What about this case:
>> 
>> class Test {
>>   static {
>>     MethodHandles.lookup().ensureClassInitialized(Test.class);
>>     // not yet initialized
>>   }
>> }
>> 
>> (I see you do that for m/p1/A.java and Test.clinitInvokeEnsureClassInitialized.)
>> 
>> Do we need mention this in the spec? e.g. this method does nothing if the class is already initialized or if the class is in the process of being initialized?
>> 
>> Paul.
>> 
>>> On Jun 3, 2020, at 4:16 PM, Mandy Chung <mandy.chung at oracle.com> <mailto:mandy.chung at oracle.com> wrote:
>>> 
>>> This proposes a new `Lookup::ensureClassInitialized` API as a replacement
>>> for `sun.misc.Unsafe::ensureClassInitialized`.The Lookup object must have
>>> the access to the given class being initialized.
>>> 
>>> CSR: https://bugs.openjdk.java.net/browse/JDK-8245871 <https://bugs.openjdk.java.net/browse/JDK-8245871>
>>> 
>>> webrev:
>>> http://cr.openjdk.java.net/~mchung/jdk15/webrevs/8235521/webrev.01/ <http://cr.openjdk.java.net/~mchung/jdk15/webrevs/8235521/webrev.01/>
>>> 
>>> This patch converts the JDK use of `jdk.internal.misc.Unsafe::ensureClassInitialized` to
>>> call this new API where appropriate. `Unsafe::ensureClassInitialized` remains for java.lang.invoke.* internal implementation use.
>>> 
>>> A framework can use `Lookup::privateLookupIn` to access a class in another module if the module authorizes it by opening the packages for it to access. Or a user can produce a less privileged lookup by Lookup::dropLookupMode and pass it to the framework.
>>> 
>>> `Class::ensureInitialized` was considered as an alternative. The downside for this option is that it would be caller sensitive in order to ensure the caller has the proper access to this class.  And it may not work for frameworks which have no access to user classes. It would have to fallback toClass::forName` limited solution.
>>> 
>>> Thanks
>>> Mandy
>>> 
> 



More information about the core-libs-dev mailing list