-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accelerate String.indexOf(char) in JDK17+ #18819
Accelerate String.indexOf(char) in JDK17+ #18819
Conversation
Have you measured performance of doing this acceleration ? If so, could you share in brief (maybe a sentence or two for each platform that you worked on) ? |
I have measured performance using a simple String.indexOf() JMH benchmark and pingperf on x86 and aarch64. I used an x86 fyre machine for measuring x86 performance, and a Ubuntu VM on M1 Mac for measuring aarch64 performance.
JMH performancex86Comparing scores with default option and
AArch64
PingPerf performancex86
AArch64
|
Jenkins test sanity.functional all jdk17 |
Build of functional tests failed with the following error:
It looks the same as Issue #18822. |
Are the different overloads (signatures) of |
All overloads with a character argument are optimized, but overloads with a String argument are not. In JDK11+, String overloads of Also, I think it would be appropriate to work on other methods like EDIT: Findings about |
Jenkins test sanity.functional alinux64,zlinux jdk17 Issue #18822 was fixed. Running tests again. |
Thanks, I am fine with delivering related changes via separate PRs. |
I agree with the approach and change looks good to me, though would like @dchopra001 to comment as well and if possible help with verifying the performance on Z as well. |
on Power, OpenJ9 had pretty optimal implementations of indexOf() already for both UTF16 and Latin1, specific at least for pre-POWER10 and POWER10 hardwares. Possible follow-up (to this item) is to see how to teach the various overloads going to indexOf(ch) implementations. @ymanton |
The test failures (There are no deserialized methods at the client.) look the same as #18691. |
Intrinsic methods for indexOf(char) in JITHelpers class is not used in JDK17+ because OpenJDK's java/lang/String class is used. OpenJDK class library has intrinsic methods in java/lang/StringLatin1 and java/lang/StringUTF16 classes. The logic of those intrinsic methods are identical to those of JITHelpers class except that they are defined as static methods. This commit adds intrinsic methods of StringLatin1 and StringUTF16 to the recognized method table and update x/p/z/aarch64 codegen to generate the specialized instruction sequence which already exists for JITHelpers methods. Signed-off-by: Akira Saitoh <[email protected]>
29c6109
to
107ff02
Compare
Rebased the commit. |
Jenkins test sanity.functional all jdk17 |
Test job on x86-64 windows is failing also in PR #18847 with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! From a z/codegen perspective the change LGTM.
I downloaded the LoZ PR build here. Doing a quick run using the benchmark posted in #18819 (comment) to make sure Z is seeing performance improvements consistent with x86 and Aarch. |
Jenkins test sanity.functional win jdk17 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AArch64 changes look good to me.
Final call for additional comments. I am going to merge this PR on Monday if there is no objection. |
Intrinsic methods for indexOf(char) in JITHelpers class is not used in JDK17+ because OpenJDK's
java/lang/String
class is used.OpenJDK class library has intrinsic methods in
java/lang/StringLatin1
andjava/lang/StringUTF16
classes. The logic of those intrinsic methods are identical to those of JITHelpers class except that they are defined as static methods. This commit adds intrinsic methods of StringLatin1 and StringUTF16 to the recognized method table and update x/p/z/aarch64 codegen to generate the specialized instruction sequence which already exists for JITHelpers methods.Related issue: #6404
Callgraph of String.indexOf(char) in JDK8 and JDK11
All intrinsic methods exist in JITHelpers class. All platforms offer specialized implementation for
JITHelpers.intrinsicIndexOfLatin1(Object array, byte ch, int offset, int length)
andJITHelpers.intrinsicIndexOfUTF16(Object array, char ch, int offset, int length)
.Callgraph of String.indexOf(char) in JDK17
Note that red nodes are methods with
@IntrinsicCandidate
annotation.Intrinsic methods of
StringLatin1
andStringUTF16
classes are used in this version. We do not recognize intrinsic methods of these classes on any platform.There are 2 methods that are annotated as
@IntrinsicCandidate
StringLatin1.indexOfChar(byte[] value, int ch, int fromIndex, int max)
StringUTF16.indexOfChar(byte[] value, int ch, int fromIndex, int max)
StringUTF16.indexOfChar(byte[] value, int ch, int fromIndex, int max)
callscheckBoundsBeginEnd
and the actual search logic resides inStringUTF16.indexOfCharUnsafe(byte[] value, int ch, int fromIndex, int max)
. Thus, this change recognizesStringUTF16.indexOfCharUnsafe
method rather thanStringUTF16.indexOfChar
.The logic of
StringLatin1.indexOfChar(byte[] value, int ch, int fromIndex, int max)
andStringUTF16.indexOfCharUnsafe(byte[] value, int ch, int fromIndex, int max)
are same as those of JITHelper intrinsic methods. This PR simply maps JITHelper intrinsics to those StringLatin1 and StringUTF16 methods.Callgraph of String.indexOf(char) in JDK21
Almost same as Java17 except for the newly added API
String.indexOf(int ch, int beginIndex, int endIndex)
. No changes for intrinsic methods.