On Sun, 30 Apr 2023 06:14:28 GMT, Chen Liang <li...@openjdk.org> wrote:

> Try to intrinsify MethodHandles.arrayConstructor for java.lang, 
> java.lang.invoke, and java.util types, which InvokerBytecodeGenerator can 
> refer to directly in a class constant.
> 
> In fact, the performance difference of Array.newInstance and anewarray is 
> quite negligible per benchmark:
> 
> Benchmark                                                            Mode  
> Cnt     Score     Error  Units
> MethodHandlesArrayConstructorCall.baselineConstruct                  avgt    
> 5     3.467 ±   0.163  ns/op
> MethodHandlesArrayConstructorCall.constantFoldConstruct              avgt    
> 5     3.403 ±   0.070  ns/op
> MethodHandlesArrayConstructorCall.constantFoldNonInvocableConstruct  avgt    
> 5     3.445 ±   0.231  ns/op
> MethodHandlesArrayConstructorCall.instanceConstruct                  avgt    
> 5     4.034 ±   0.168  ns/op
> MethodHandlesArrayConstructorCall.instanceNonInvocableConstruct      avgt    
> 5     4.038 ±   0.104  ns/op
> MethodHandlesArrayConstructorColdStart.testCreateInvocable             ss   
> 10  1425.991 ± 308.216  us/op
> MethodHandlesArrayConstructorColdStart.testCreateNonInvocable          ss   
> 10  1401.480 ± 258.402  us/op
> MethodHandlesArrayConstructorColdStart.testCreateObject                ss   
> 10  1213.018 ± 166.522  us/op
> MethodHandlesArrayConstructorColdStart.testCreatePrimitive             ss   
> 10  1163.461 ± 178.549  us/op

`Array::newInstance` is already intrinsified. It behaves pretty much the same 
as `anewarray` if the array type is constant ([1], [2]). So, I'm not sure I see 
how intrinsifying this could improve performance.

What kind of performance improvement are you seeing? Could you add a comparison 
with a method handle that calls `Array::newInstance` bound to the array type? 
(that should have the same performance as the current implementation).

[1]: 
https://github.com/openjdk/jdk/blob/b3dbf28bc0614bee2f7137af95389134155c9511/src/hotspot/share/opto/library_call.cpp#L4051
[2]: 
https://github.com/openjdk/jdk/blob/b3dbf28bc0614bee2f7137af95389134155c9511/src/hotspot/share/opto/parse3.cpp#L282

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13735#issuecomment-1529144414

Reply via email to