Skip to content

Conversation

@Hamlin-Li
Copy link

@Hamlin-Li Hamlin-Li commented Feb 6, 2025

Hi,

Can you help to review the patch?

It tries to improve the string compare when AvoidUnalignedAccesses == false && encoding is LU or UL (i.e. 2 strings encodings are different with each other).
The jmh test shows when -CompactObjectHeaders (i.e. -COH) && -AvoidUnalignedAccesses, the patch bring much better performance, and in other cases, it does not bring obvious regression. And currently by default it's -COH.

Thanks

Performance

it's run on bananapi.

-COH-AvoidUnalignedAccesses

“-COH-Avoid” (delta) (size) (utf16) Mode Cnt Score - master Score - patch Error Units Improvement
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 24 N/A avgt 10 6438443.073 6383881.891 36912.539 ns/op 0.009
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 36 N/A avgt 10 9421176.34 9390907.1 21034.266 ns/op 0.003
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 72 N/A avgt 10 18592342.33 16871350.38 15550.827 ns/op 0.102
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 128 N/A avgt 10 30916157.05 28646961.11 9263.556 ns/op 0.079
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 256 N/A avgt 10 58945069.17 55505097.77 8803.847 ns/op 0.062
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 512 N/A avgt 10 115520355.5 110233842.8 35056.972 ns/op 0.048
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 24 N/A avgt 10 7541299.83 7481385.995 43240.713 ns/op 0.008
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 36 N/A avgt 10 10295051.77 10264978.04 38938.956 ns/op 0.003
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 72 N/A avgt 10 19652419.64 17953481.41 10987.17 ns/op 0.095
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 128 N/A avgt 10 32078969.29 29532674.32 26556.277 ns/op 0.086
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 256 N/A avgt 10 60265969.7 56586871.09 137156.033 ns/op 0.065
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 512 N/A avgt 10 116892685.5 111266086.7 106542.956 ns/op 0.051

+COH-AvoidUnalignedAccesses

"+COH-Avoid" (delta) (size) (utf16) Mode Cnt Score - master Score - patch Error Units Improvement
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 24 N/A avgt 10 6384145.1 6386249.278 1018.737 ns/op 0
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 36 N/A avgt 10 9484748.389 9437921.504 25184.962 ns/op 0.005
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 72 N/A avgt 10 18648808.89 17610658.36 3613.01 ns/op 0.059
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 128 N/A avgt 10 31130870.72 30542644.4 136527.281 ns/op 0.019
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 256 N/A avgt 10 58943258.88 59678929.13 9247.37 ns/op -0.012
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 512 N/A avgt 10 115515196.6 118941406.1 30104.94 ns/op -0.029
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 24 N/A avgt 10 7640264.164 7691120.134 8941.255 ns/op -0.007
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 36 N/A avgt 10 10568117.17 10540680.16 11225.744 ns/op 0.003
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 72 N/A avgt 10 19727550.52 18982109.53 8609.764 ns/op 0.039
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 128 N/A avgt 10 32125836.11 31006763.12 13915.357 ns/op 0.036
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 256 N/A avgt 10 60202330.54 59561746.17 15817.383 ns/op 0.011
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 512 N/A avgt 10 116636087.8 117264697.5 19632.92 ns/op -0.005

-COH+AvoidUnalignedAccesses

“-COH+Avoid” (delta) (size) (utf16) Mode Cnt Score - master Score - patch Error Units Improvement
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 24 N/A avgt 10 7885819.391 7886391.597 1238.502 ns/op 0
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 36 N/A avgt 10 10889126.89 10891175.03 1399.179 ns/op 0
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 72 N/A avgt 10 16897052.9 16774972.05 2609.977 ns/op 0.007
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 128 N/A avgt 10 28922269.1 28478100.28 66442.357 ns/op 0.016
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 256 N/A avgt 10 56180868.95 55517886.54 48061.692 ns/op 0.012
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 512 N/A avgt 10 110907025.6 110201411.8 65541.488 ns/op 0.006
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 24 N/A avgt 10 9160226.336 9053922.422 30162.696 ns/op 0.012
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 36 N/A avgt 10 11858619.51 11875124.68 30883.529 ns/op -0.001
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 72 N/A avgt 10 18145983.4 17975971.55 42989.862 ns/op 0.009
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 128 N/A avgt 10 30239261.15 29550149 93379.637 ns/op 0.023
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 256 N/A avgt 10 57340601.37 56598661.49 63235.889 ns/op 0.013
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 512 N/A avgt 10 111847228.7 111826244.4 30457.378 ns/op 0

+COH+AvoidUnalignedAccesses

“+COH+Avoid” (delta) (size) (utf16) Mode Cnt Score - master Score - patch Error Units Improvement
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 24 N/A avgt 10 8824614.771 8879669.558 1136.78 ns/op -0.006
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 36 N/A avgt 10 12453700.16 12452977.94 2412.16 ns/op 0
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 72 N/A avgt 10 24742973.85 24723425.63 46396.337 ns/op 0.001
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 128 N/A avgt 10 39673249.81 39681763.05 10340.791 ns/op 0
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 256 N/A avgt 10 74004446.14 73731397.09 29337.751 ns/op 0.004
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToLU 2 512 N/A avgt 10 142806141.5 142275494.2 52159.737 ns/op 0.004
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 24 N/A avgt 10 9935969.372 10045152.69 70155.123 ns/op -0.011
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 36 N/A avgt 10 13255244.36 13280685.46 68940.937 ns/op -0.002
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 72 N/A avgt 10 25848901.97 25887363.77 16178.629 ns/op -0.001
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 128 N/A avgt 10 40859613.95 40908567.84 54621.931 ns/op -0.001
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 256 N/A avgt 10 74853691.65 74878469.62 31639.587 ns/op 0
com.arm.benchmarks.intrinsics.StringCompareToDifferentLength.compareToUL 2 512 N/A avgt 10 143431358.1 143495718.8 60271.214 ns/op 0

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8349556: RISC-V: improve the performance when -COH and -AvoidUnalignedAccesses for UL and LU string comparison (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23495/head:pull/23495
$ git checkout pull/23495

Update a local copy of the PR:
$ git checkout pull/23495
$ git pull https://git.openjdk.org/jdk.git pull/23495/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23495

View PR using the GUI difftool:
$ git pr show -t 23495

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23495.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 6, 2025

👋 Welcome back mli! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Feb 6, 2025

@Hamlin-Li This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8349556: RISC-V: improve the performance when -COH and -AvoidUnalignedAccesses for UL and LU string comparison

Reviewed-by: fyang, vkempik

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 32 new commits pushed to the master branch:

  • 4a83ca1: 8349666: RISC-V: enable superwords tests for vector reductions
  • 8f6ccde: 8349554: [UBSAN] os::attempt_reserve_memory_between reported applying non-zero offset to non-null pointer produced null pointer
  • 7d52f1e: 8349525: RBTree: provide leftmost, rightmost, and a simple way to print trees
  • e9278de: 8348411: C2: Remove the control input of LoadKlassNode and LoadNKlassNode
  • 5395ffa: 8327378: XMLStreamReader throws EOFException instead of XMLStreamException
  • 1ed9ef1: 8349559: Compiler interface doesn't need to store protection domain
  • f0ea38b: 8349509: [macos] Clean up macOS dead code in jpackage
  • 7f6c687: 8349374: [JVMCI] concurrent use of HotSpotSpeculationLog can crash
  • bd9b24c: 8349512: Duplicate PermittedSubclasses entries with doclint enabled
  • b40f8ee: 8337251: C1: Improve Class.isInstance intrinsic
  • ... and 22 more: https://git.openjdk.org/jdk/compare/acb46ddb8901a4e96238de217d3e7931f381b699...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 6, 2025
@openjdk
Copy link

openjdk bot commented Feb 6, 2025

@Hamlin-Li The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Feb 6, 2025
@mlbridge
Copy link

mlbridge bot commented Feb 6, 2025

Webrevs

tmpL = isLU ? tmp1 : tmp2; // where to keep L for comparison

if (AvoidUnalignedAccesses && (base_offset1 % 8) == 0) {
if (AvoidUnalignedAccesses && (base_offset1 % 8) != 0) {
Copy link
Member

@RealFYang RealFYang Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that a similar check is in C2_MacroAssembler::string_compare for the UU/LL cases [1].
Seems more consistent if we move it into the counterpart generate_compare_long_string_same_encoding.

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp#L1443

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we should refactor the code a bit to make it more readable.
As it seems just a refactor, so I can do it in another pr, how do you think about it?
At the same time I can also clean the invocation of compare_string_16_bytes_same from generate_compare_long_string_same_encoding, I don't like the implicit registers passing between them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Seems the LL/UU cases are kind of different as they already emit direct 8-byte loads before the stub. So not sure if it's doable to move the check.


if (AvoidUnalignedAccesses && (base_offset1 % 8) == 0) {
if (AvoidUnalignedAccesses && (base_offset1 % 8) != 0) {
// Load another 4 bytes from strL to make sure main loop is 8-byte aligned
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You might want to update this code comment removing the word another.
// Load another 4 bytes from strL to make sure main loop is 8-byte aligned
=>
// Load 4 bytes from strL to make sure main loop is 8-byte aligned

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 7, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 7, 2025
Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 7, 2025
@Hamlin-Li
Copy link
Author

Thanks for the update!

Thank you!

@VladimirKempik
Copy link

hold on a bit, let me take a look at it after the weekend

@VladimirKempik
Copy link

I can't see how this end up improving perf, You have moved loading job for first few bytes from one place to another.
Technically it's correct and if jmh shows improvement - let it be

@Hamlin-Li
Copy link
Author

I can't see how this end up improving perf, You have moved loading job for first few bytes from one place to another. Technically it's correct and if jmh shows improvement - let it be

The reason is that with -COH && -Avoid, some alignment instructions that were previously required are omitted.

@Hamlin-Li
Copy link
Author

Thank you!

@Hamlin-Li
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 10, 2025

Going to push as commit d104deb.
Since your change was applied there have been 32 commits pushed to the master branch:

  • 4a83ca1: 8349666: RISC-V: enable superwords tests for vector reductions
  • 8f6ccde: 8349554: [UBSAN] os::attempt_reserve_memory_between reported applying non-zero offset to non-null pointer produced null pointer
  • 7d52f1e: 8349525: RBTree: provide leftmost, rightmost, and a simple way to print trees
  • e9278de: 8348411: C2: Remove the control input of LoadKlassNode and LoadNKlassNode
  • 5395ffa: 8327378: XMLStreamReader throws EOFException instead of XMLStreamException
  • 1ed9ef1: 8349559: Compiler interface doesn't need to store protection domain
  • f0ea38b: 8349509: [macos] Clean up macOS dead code in jpackage
  • 7f6c687: 8349374: [JVMCI] concurrent use of HotSpotSpeculationLog can crash
  • bd9b24c: 8349512: Duplicate PermittedSubclasses entries with doclint enabled
  • b40f8ee: 8337251: C1: Improve Class.isInstance intrinsic
  • ... and 22 more: https://git.openjdk.org/jdk/compare/acb46ddb8901a4e96238de217d3e7931f381b699...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 10, 2025
@openjdk openjdk bot closed this Feb 10, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 10, 2025
@openjdk
Copy link

openjdk bot commented Feb 10, 2025

@Hamlin-Li Pushed as commit d104deb.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@Hamlin-Li Hamlin-Li deleted the adjust-UL-LU-string-compare-alignment branch February 11, 2025 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants