forax at univ-mlv.fr
Thu Jan 12 15:24:39 UTC 2017
I've just taken a look to the code,
i've seen any seen any weird things,
it creates a MH, do a asType() that insert a cast on the parameter type (from Bean to the right kind of Bean),
and the mh is called with an invokeExact.
Apart the fact that the perf test do not use JMH so there is no proper sandboxing between the tests.
Stephen, in HandleMetaProperty.get, you should add a catch(Error) and repropagate it like you do with RuntimeException, because currently if you have an OOME, you will try to allocate in the catch block.
----- Mail original -----
> De: "Claes Redestad" <claes.redestad at oracle.com>
> À: jigsaw-dev at openjdk.java.net, "Stephen Colebourne" <scolebourne at joda.org>
> Envoyé: Jeudi 12 Janvier 2017 15:47:22
> Objet: Re: MethodHandle performance
> Hi Stephen,
> this is surprising; handles should typically be as fast or much
> faster than reflection (VarHandles can be faster than Unsafe in certain
> cases), but may carry a slightly more expensive setup cost - do you have
> a reproducer I could try?
> 8b122 - do you mean 8u122 EA?
> On 2017-01-12 15:23, Stephen Colebourne wrote:
>> I've recently tried  converting Joda-Beans use of setAccessible()
>> to use MethodHandle. Since it is a code generator, the actual coding
>> is relatively easy, and obtaining the MethodHandles.Lookup instance
>> with the "private" capability is simple. While the MethodHandles API
>> looks very complex, it isn't too bad to use, although it is
>> undoubtedly more complex than reflection.
>> (Note that the standard Joda-Beans technique is to code generate
>> normal Java code to avoid the need to use reflection, but it can
>> optionally generate reflection-based code in "light bean" mode. It is
>> that reflection approach that is being examined here).
>> The real problem however is performance. In my tests, I am seeing a
>> MethodHandle approach being 2 to 3 times slower than a reflection
>> approach for identical functionality, which is quite a significant
>> degradation. (using Java 8 b122)
>> Given the performance, I left to question whether the repeated Jigsaw
>> advice to use MethodHandle instead of setAccessible is viable - in the
>> kinds of places that use reflection, performance tends to be critical.
>> Is there, or has there been, work in Java 9 to improve the performance
>> of method handles?
>>  https://github.com/JodaOrg/joda-beans/commits/wip/methodhandles
More information about the jigsaw-dev