On Wed, 28 Oct 2020 20:13:19 GMT, Rémi Forax
<[email protected]> wrote:
>> Hi Remi,
>>
>> I appreciate your proposal to modernize Proxy API. There are several
>> requests for this enhancement to support default methods in Proxy.
>> Defining a new `java.lang.invoke.Proxy` is a much bigger project that I
>> can't tell when the existing users of `java.lang.reflect.Proxy` will be able
>> to get this default method invocation support.
>>
>> I do agree that this API design has many challenges caused by what you
>> listed above. Well, I believe we are very close to have a consensus:
>> 1. New `newProxyInstance` factory method takes a handler factory doing the
>> access check
>> 2. Update `getInvocationHandler` to throw
>> `InaccessibleInvocationHandlerException` if access denied to get an
>> invocation handler associated with the proxy instance
>>
>> If this needs more time, I think I will consider to shelf this RFE and come
>> back to it later (and consider your proposal as well).
>
> The trick is that if we know that a class like java.lang.invoke.Proxy may
> exist,
> it means that instead of distorting the j.l.r.Proxy API to increase of few
> percents the performance when calling a default method, you can come with a
> simpler design in term of API that just add an API point to call a default
> method.
>
> Better performance becoming on the the goals of java.lang.invoke.Proxy.
Hi Mandy,
I re-ran the benchmark on your latest version (the static API) and I get
similar results as you:
Benchmark Mode Cnt Score Error Units
ProxyBench.implClass avgt 5 3.745 ± 0.033 ns/op
ProxyBench.implProxy avgt 5 29.826 ± 0.183 ns/op
ProxyBench.ppImplClass avgt 5 3.683 ± 0.009 ns/op
ProxyBench.ppImplProxy avgt 5 29.124 ± 0.535 ns/op
I also tried a variant where the access check in the invokeDefault static
method in not pre-screened with checking of the interface modifiers and package
export status but relies on Method.checkAccess cache:
// access check
Class<?> caller = Reflection.getCallerClass();
int modifiers = method.getModifiers();
method.checkAccess(caller, intf, proxyClass, modifiers);
... and the results are not worse, even marginally better:
Benchmark Mode Cnt Score Error Units
ProxyBench.implClass avgt 5 3.724 ± 0.012 ns/op
ProxyBench.implProxy avgt 5 29.138 ± 0.271 ns/op
ProxyBench.ppImplClass avgt 5 3.744 ± 0.009 ns/op
ProxyBench.ppImplProxy avgt 5 28.961 ± 0.182 ns/op
I think this looks reasonably good.
-------------
PR: https://git.openjdk.java.net/jdk/pull/313