RFR: 6983726: remove Proxy from MethodHandleProxies.asInterfaceInstance SAM conversion [v9]
ExE Boss
duke at openjdk.org
Fri Apr 7 12:56:51 UTC 2023
On Fri, 7 Apr 2023 11:41:52 GMT, Johannes Kuhn <jkuhn at 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
More information about the core-libs-dev
mailing list