Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Geoffrey De Smet
Hi guys, I ran the following JMH benchmark on JDK 9 and JDK 8. Source code and detailed results below. Benchmark on JDK 9    Score staticMethodHandle  2.770 lambdaMetafactory  3.052    // 10% slower nonStaticMethodHandle   5.250    // 90% slower Why is LambdaMetafactory 10%

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Vladimir Ivanov
Geoffrey, In both staticMethodHandle & lambdaMetafactory Dog::getName is inlined, but using different mechanisms. In staticMethodHandle target method is statically known [1], but in case of lambdaMetafactory [2] compiler has to rely on profiling info to devirtualize Function::apply(). The la

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Jochen Theodorou
Am 19.02.2018 um 13:00 schrieb Vladimir Ivanov: Geoffrey, In both staticMethodHandle & lambdaMetafactory Dog::getName is inlined, but using different mechanisms. In staticMethodHandle target method is statically known [1], but in case of lambdaMetafactory [2] compiler has to rely on profil

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Vladimir Ivanov
In both staticMethodHandle & lambdaMetafactory Dog::getName is inlined, but using different mechanisms. In staticMethodHandle target method is statically known [1], but in case of lambdaMetafactory [2] compiler has to rely on profiling info to devirtualize Function::apply(). The latter require

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Geoffrey De Smet
Thank you for the insight, Vladimir. In staticMethodHandle target method is statically known [1], but in case of lambdaMetafactory [2] compiler has to rely on profiling info to devirtualize Function::apply(). The latter requires exact type check on the receiver at runtime and that explains the

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Vladimir Ivanov
In staticMethodHandle target method is statically known [1], but in case of lambdaMetafactory [2] compiler has to rely on profiling info to devirtualize Function::apply(). The latter requires exact type check on the receiver at runtime and that explains the difference you are seeing. Ah, so i

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Jochen Theodorou
On 19.02.2018 14:31, Vladimir Ivanov wrote: [...] CallSites are the best you can get (JITs treat CallSite.target as constant and aggressively inlines through them), but you have to bind CallSite instance either to invokedynamic call site or put it into static final field. And that really exte

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Vladimir Ivanov
On 2/19/18 5:13 PM, Jochen Theodorou wrote: On 19.02.2018 14:31, Vladimir Ivanov wrote: [...] CallSites are the best you can get (JITs treat CallSite.target as constant and aggressively inlines through them), but you have to bind CallSite instance either to invokedynamic call site or put it i

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Remi Forax
- Mail original - > De: "Vladimir Ivanov" > À: "Jochen Theodorou" , "Da Vinci Machine Project" > > Envoyé: Lundi 19 Février 2018 15:47:45 > Objet: Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but > 80% faster than a non-static MethodHandle? > On 2/19/18 5:13 PM,

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Wenlei Xie
> However, for java framework developers, > it would be really useful to have inlining for non-static method handles too (see Charles's thread), Is the problem that non-static MethodHandle doesn't get customized, or it's because in the benchmark, each time it will use a new MethodHandle from refle

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Wenlei Xie
Never mind. I miss some points in the previous discussion. Static method handle can get further benefit from JIT: > JIT-compiler extracts method handle instance from static final field (as if it were a constant from class constant pool) and inlines through MH.invokeExact() down to the target metho

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Vladimir Ivanov
On 2/19/18 11:43 PM, Wenlei Xie wrote: Never mind. I miss some points in the previous discussion. Static method handle can get further benefit from JIT: > JIT-compiler extracts method handle instance from static final field (as if it were a constant from class constant pool) and inlines thr

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Wenlei Xie
Thank you Vladimir for the explanation! > In both staticMethodHandle & lambdaMetafactory Dog::getName is inlined, but using different mechanisms. > In staticMethodHandle target method is statically known [1], but in case of lambdaMetafactory [2] compiler has to rely on profiling info to devirtual

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Vladimir Ivanov
Sorry if it's a dumb question, but why nonStaticMethodHandle cannot get inlined here? -- In the benchmark it's always the same line with the same final MethodHandle variable, can JIT based on some profiling info to inline it (similar to the function object generated by LambdaMetafactory). --

Re: Why is LambdaMetafactory 10% slower than a static MethodHandle but 80% faster than a non-static MethodHandle?

2018-02-19 Thread Jochen Theodorou
On 20.02.2018 00:14, Vladimir Ivanov wrote: Sorry if it's a dumb question, but why nonStaticMethodHandle cannot get inlined here? -- In the benchmark it's always the same line with the same final MethodHandle variable, can JIT based on some profiling info to inline it (similar to the function