RFR 8206955 MethodHandleProxies.asInterfaceInstance does not support default methods

Remi Forax forax at univ-mlv.fr
Wed Jul 11 15:31:09 UTC 2018

----- Mail original -----
> De: "Peter Levart" <peter.levart at gmail.com>
> À: "Paul Sandoz" <paul.sandoz at oracle.com>, "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Mercredi 11 Juillet 2018 17:15:09
> Objet: Re: RFR 8206955 MethodHandleProxies.asInterfaceInstance does not support default methods

> Hi Paul,
> The patch looks ok. I hope IMPL_LOOKUP has access to all methods (even
> if located in package-private interfaces and/or in concealed packages of
> modules)?
> Just a thought... Would it be possible to implement this API in terms of
> LambdaMetafactory ?
> Regards, Peter

Hi Peter,
not with the current LambdaMetaFactory, the LambdaMetaFactory only accept some kind of method handles (constant method calls) not all kind of method handles.

That said the current implementation of MethodHandleProxies is very raw and not very efficient, we should use the same idea as the lambda meta factory i.e spin an anonymous class and use the mechanism of constant patching offer by unsafe.defineAnonymousClass to inject the method handle into proxy so it will work with any method handle.

For each interface, you should cache the bytecode of the anonymous class you want to load and use defineAnonymousClass with the method handle each time asInterfaceInstance is called.


> On 07/11/2018 12:43 AM, Paul Sandoz wrote:
>> Hi,
>> Please review this fix to MethodHandleProxies.asInterfaceInstance to support
>> default methods:
>>    http://cr.openjdk.java.net/~psandoz/jdk/JDK-8206955-mh-func-iface-proxy-default-methods/webrev/
>>    <http://cr.openjdk.java.net/~psandoz/jdk/JDK-8206955-mh-func-iface-proxy-default-methods/webrev/>
>> It probably requires a CSR, which i shall do after this review.
>> Thanks,
> > Paul.

More information about the core-libs-dev mailing list