RFR: 8273585: String.charAt performance degrades due to JDK-8268698
Roland Westrelin
roland at openjdk.java.net
Mon Oct 25 12:31:05 UTC 2021
On Mon, 25 Oct 2021 05:52:02 GMT, Yi Yang <yyang at openjdk.org> wrote:
> String.charAt shows significant performance regression due to [JDK-8268698](https://bugs.openjdk.java.net/browse/JDK-8268698), which replaces index bound checking with Preconditions.checkIndex intrinsic method.
>
> The result of "time linux-x86_64-server-release/images/jdk/bin/java Test":
>
>
> Before JDK-8268698
> real 0m8.369s
> user 0m8.386s
> sys 0m0.019s
>
> After JDK-8268698,
> real 0m19.722s
> user 0m19.748s
> sys 0m0.013s
>
>
> The reason is Preconditions.checkIndex generates a CastII for index node as index is now known to be >= 0 and < length.:
>
> https://github.com/openjdk/jdk/blob/5dab76b939e381312ce5c89b9aebca628238a387/src/hotspot/share/opto/library_call.cpp#L1077-L1083
>
> CastII can not be recognized as a parallel induction variable because AddNode's input must be the PhiNode:
>
> https://github.com/openjdk/jdk/blob/5dab76b939e381312ce5c89b9aebca628238a387/src/hotspot/share/opto/loopnode.cpp#L3177-L3184
>
> It seems this prevents further loop unrolling. I think we can relax this constraint, i.e CastII can be the input of AddNode if its input is PhiNode. After applying this patch, performance regression disappears:
>
>
> $time ./test.sh
>
> real 0m9.514s
> user 0m10.310s
> sys 0m0.155s
>
> This is likely the reason for [JDK-8272493](https://bugs.openjdk.java.net/browse/JDK-8272493). Please help review it. Thanks!
Changes requested by roland (Reviewer).
src/hotspot/share/opto/loopnode.cpp line 3184:
> 3182: !incr2->in(2)->is_Con())
> 3183: continue;
> 3184: if (incr2->in(1) != phi2) {
You could use incr2->in(1)->uncast() != phi2. You don't need to add an extra if then.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6096
More information about the hotspot-compiler-dev
mailing list