proxy an interface and call a default method
forax at univ-mlv.fr
forax at univ-mlv.fr
Thu Jun 2 16:34:57 UTC 2016
----- Mail original -----
> De: "Peter Levart" <peter.levart at gmail.com>
> À: forax at univ-mlv.fr
> Cc: "Da Vinci Machine Project" <mlvm-dev at openjdk.java.net>, "jochen
> Theodorou" <blackdrag at gmx.org>
> Envoyé: Jeudi 2 Juin 2016 15:23:44
> Objet: Re: proxy an interface and call a default method
> Hi Remi, Jochen,
> On 06/02/2016 11:15 AM, forax at univ-mlv.fr wrote:
> > > > The solution could be for Proxy API to provide a MH that was already >
> > > > bound to the Proxy instance. Such pre-bound MH could not be abused
> > > > then.
> >
>
> > independently of any security issue, it may be a good idea but doing a
> > partial evaluation on a MH is not cheap.
>
> I created a prototype for this:
> http://cr.openjdk.java.net/~plevart/jdk9-dev/Proxy.invokeSuperDefaults/webrev.01/
> Example usage is as follows:
> public class Test {
> interface I {
> default void m() {
> System.out.println("default I.m() called");
> }
> }
> public static void main(String[] args) {
> InvocationHandler h = (proxy, method, params) -> {
> System.out.println("InvocationHandler called for: " + method);
> MethodHandle superM = ((Proxy) proxy).findSuper(I.class, "m",
> MethodType.methodType(void.class));
> return superM.invokeWithArguments(params);
> };
> I i = (I) Proxy.newProxyInstance(
> I.class.getClassLoader(), new Class<?>[]{I.class}, h);
> i.m();
> }
> }
> It works, but in order for this to have adequate performance, caching would
> have to be added. But caching a pre-bound MH would require caching on
> per-proxy-instance basis, which would not be very efficient. So perhaps,
> instead of providing a Proxy::findSuper method that returns a pre-bound MH,
> there could simply be a method like the following in the Proxy class:
> public final Object invokeSuper(Class<?> interfaze, String methodName,
> MethodType methodType, Object ... args) { ... }
> What do you think?
yes, good idea,
i think it should be static (and takes a Proxy as parameter) to avoid unwanted overriding.
> Regards, Peter
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20160602/21eb5934/attachment.html>
More information about the mlvm-dev
mailing list