Why is "checkcast MethodHandle" necessary in methodHandleInvokeLinkerMethod?
Ioi Lam
ioi.lam at oracle.com
Mon Apr 9 21:06:43 UTC 2018
Hi John,
That was my suspicion and thanks for confirming it.
I wrote a simple benchmark to try to compare the speed of a 'real'
method invocation vs MH.invokeExact
http://cr.openjdk.java.net/~iklam/misc/method_handle_bench/BenchMH.java
Basically
private static void loopMH(int loops, MethodHandle mh) throws
Throwable {
for (int i=0; i<loops; i++) {
mh.invokeExact("yo!");
}
}
-vs-
private static void loopDirect(int loops) {
for (int i=0; i<loops; i++) {
callme("yo!");
}
}
$ java -cp . BenchMH 1000000000
...
MH: loops = 1000000000: elapsed = 10332 ms
direct: loops = 1000000000: elapsed = 7500 ms
So it seems like the JIT still can't handle such a simple case ... :-(
On 4/9/18 1:32 PM, John Rose wrote:
> On Apr 9, 2018, at 1:17 PM, Ioi Lam <ioi.lam at oracle.com
> <mailto:ioi.lam at oracle.com>> wrote:
>>
>> So why is this first argument not declared as a MethodHandle?
>>
>
> The short answer is to simplify the plumbing of lambda forms.
>
> Method handles are strongly typed but the underlying IR of
> lambda forms is weakly typed. This keeps the IR simple.
> To make up the difference, casts are inserted where necessary.
> Most (not all) uses of MHs are inlined and/or customized,
> in which case the JIT simply drops the casts.
>
> — John
>
>
> _______________________________________________ mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20180409/f95c2d86/attachment-0001.html>
More information about the mlvm-dev
mailing list