RFR: 8261731: shallow copy the internal buffer of a scalar-replaced java.lang.String object
Claes Redestad
redestad at openjdk.java.net
Wed Mar 24 00:42:44 UTC 2021
On Wed, 24 Mar 2021 00:06:45 GMT, Vladimir Kozlov <kvn at openjdk.org> wrote:
>> @navyxliu I think you want to fix a lot of issues once. You need to split problems you see.
>>
>> I did few experiments and the one issue which could be fixed first is scalarizing of array created by `Arrays.copyOfRange()` used by `String::substring()`.
>>
>> I see that current JDK easy scalarize new array and arraycopy():
>> private static int test4(byte[] src) {
>> byte[] dst = new byte[6];
>> System.arraycopy(src, 1, dst, 0, 6);
>> return dst[2] + dst[5];
>> }
>> But it did not scalarize:
>> private static int test5(byte[] src) {
>> byte[] dst = Arrays.copyOfRange(src, 1, 7);
>> return dst[2] + dst[5];
>> }
>> Even so code in `Arrays.copyOfRange()` is the same as in `test4()`:
>> https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/Arrays.java#L3817
>>
>> Arrays does not escaped but it is not eliminated because Loads are not redirected into `dst` array as in `test4()` case.
>>
>> I think this should be fixed first.
>
> Hmm, actually it was easy solved with `-XX:DisableIntrinsic=_min` :(
>
> This intrinsic was implemented long ago. the code is used for `arraycopy` optimization. But for some reason it does not work here.
>
> I think this should be investigated first-first. It would be interesting to see performance effects if we disable this intrinsic at all.
You seem to have had a run-in with these intrinsics causing issues before: https://bugs.openjdk.java.net/browse/JDK-8039104 - is this a similar issue?
On a trivial micro adding together a few Math.min values the intrinsic seem to have no effect on my x64 system, down to generating the exact same assembly.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2570
More information about the hotspot-compiler-dev
mailing list