On Fri, 7 Apr 2023 11:41:52 GMT, Johannes Kuhn <jk...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java line 
>> 317:
>> 
>>> 315:                 cob.aload(1);
>>> 316:                 cob.invokevirtual(CD_MethodHandles_Lookup, 
>>> "lookupClass", MTD_Class);
>>> 317:                 cob.constantInstruction(proxyDesc);
>> 
>> This probably can’t use `LDC` of `CONSTANT_Class`, as that can’t refer to 
>> hidden classes:
>> Suggestion:
>> 
>>                 cob.aload(0);
>>                 cob.invokevirtual(CD_Object, "getClass", MTD_Class);
>> 
>> 
>> --------------------------------------------------------------------------------
>> 
>> Having a helper constant bootstrap of the following form would allow to 
>> obtain the current class using a dynamic constant:
>> 
>> public static final Class<?> lookupClass(
>>      final MethodHandles.Lookup lookup,
>>      final String name,
>>      @SuppressWarnings("rawtypes") // needed to allow `Class.class`
>>      final Class<? extends Class> type
>> ) {
>>      requireNonNull(lookup);
>>      requireNonNull(type);
>>      if (type != Class.class) {
>>              throw new IllegalArgumentException();
>>      }
>>      return lookup.lookupClass();
>> }
>
>> that can’t refer to hidden classes
> 
> No, that is exactly the **one and only thing** that can refer to the hidden 
> class:
> 
>> * On any attempt to resolve the entry in the run-time constant pool 
>> indicated by `this_class`, the symbolic reference is considered to be 
>> resolved to `C` and resolution always succeeds immediately.
> 
> [(Souce)](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClass%28byte%5B%5D,boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...%29)
> 
> As the passed class refers to `this_class`, that use is fine.

The **JVM** spec doesn’t mention that anywhere though.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13197#discussion_r1160682245

Reply via email to