RFR: 8264288: Performance issue with MethodHandle.asCollector [v2]

Jorn Vernee jvernee at openjdk.java.net
Fri Apr 2 13:26:26 UTC 2021

On Thu, 1 Apr 2021 19:19:10 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
>>   - Address review comments
>>   - Use cached version of store func getter
>>   - Use ARRAY_STORE intrinsic for array stores
>>   - Generate direct call to Array.newInstance instead of using an array constructor handle
>>   - Intrinsify call to Array.newInstance if the component type is constant
> That's an elegant solution.
> At first i thought it might unduly perturb lambda form generation and caching. but you slotted a different lambda form implementation underneath the varargs implementation.

I've address review comments, plus some other things:

- I realized that I was calling the uncached version of the store function factory. Fixed that.
- I also realized that there's already an `ARRAY_STORE` intrinsic, which I'm now using to avoid generating a call.
- I also realized that since we only have 1 array creation handle per lambda form, we can instead generate a direct call to `Array::newInstance` instead of going through the array constructor handle (which also avoids having to use a BoundMethodHandle).
- Finally, I added an instrinsic, under the old `NEW_ARRAY` name, that intrinsifies a call to `Array::newInstance` if the component type argument is constant (which it is in this case).

As a result, the lambda form is now fully intrinsified (no more calls in the generated bytecode) e.g.:

static java.lang.Object collector001_LLLL_L(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object);
       0: iconst_3
       1: anewarray     #12                 // class java/lang/String
       4: astore        4
       6: aload         4
       8: checkcast     #14                 // class "[Ljava/lang/String;"
      11: dup
      12: astore        4
      14: iconst_0
      15: aload_1
      16: checkcast     #12                 // class java/lang/String
      19: aastore
      20: aload         4
      22: iconst_1
      23: aload_2
      24: checkcast     #12                 // class java/lang/String
      27: aastore
      28: aload         4
      30: iconst_2
      31: aload_3
      32: checkcast     #12                 // class java/lang/String
      35: aastore
      36: aload         4
      38: areturn



PR: https://git.openjdk.java.net/jdk/pull/3306

More information about the core-libs-dev mailing list