Skip to content
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

8321279: Implement hashCode() in Heap-X-Buffer.java.template #16992

Closed
wants to merge 15 commits into from

Conversation

stsypanov
Copy link
Contributor

@stsypanov stsypanov commented Dec 6, 2023

Currently Heap*Buffer.hashCode() is inherited from *Buffer and implemented as

public int hashCode() {
    int h = 1;
    int p = position();
    for (int i = limit() - 1; i >= p; i--)
        h = 31 * h + (int)get(i);
    return h;
}

This can be improved using ArraysSupport.vectorizedHashCode()


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-8321279: Implement hashCode() in Heap-X-Buffer.java.template (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16992

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 6, 2023

👋 Welcome back stsypanov! 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 openjdk bot added the rfr Pull request is ready for review label Dec 6, 2023
@openjdk
Copy link

openjdk bot commented Dec 6, 2023

@stsypanov The following label will be automatically applied to this pull request:

  • nio

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 nio nio-dev@openjdk.org label Dec 6, 2023
@mlbridge
Copy link

mlbridge bot commented Dec 6, 2023

@AlanBateman
Copy link
Contributor

Are you planning to add a microbenchmark?

@openjdk
Copy link

openjdk bot commented Dec 9, 2023

⚠️ @stsypanov This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@stsypanov
Copy link
Contributor Author

@AlanBateman added a benchmark for this. Currently I'm working on Windows and run the benchmark on Linux image on Oracle VM VirtualBox, I guess this is the reason why the improvement is not that impressive

master

Benchmark                 (size)  Mode  Cnt      Score      Error  Units
ByteBuffers.testHashCode      16  avgt   30      8.712 ?    0.180  ns/op
ByteBuffers.testHashCode    1024  avgt   30    641.727 ?   10.785  ns/op
ByteBuffers.testHashCode  131072  avgt   30  86610.737 ? 1569.968  ns/op

patch

Benchmark                 (size)  Mode  Cnt      Score     Error  Units
ByteBuffers.testHashCode      16  avgt   30      8.699 ?   0.048  ns/op
ByteBuffers.testHashCode    1024  avgt   30    633.038 ?   6.090  ns/op
ByteBuffers.testHashCode  131072  avgt   30  82270.905 ? 927.101  ns/op

@AlanBateman
Copy link
Contributor

@AlanBateman added a benchmark for this. Currently I'm working on Windows and run the benchmark on Linux image on Oracle VM VirtualBox, I guess this is the reason why the improvement is not that impressive

I think the issue is that the benchmark was testing a direct ByteBuffer but the change is for heap ByteBuffer. Maybe you can re-run and paste in results?

@stsypanov
Copy link
Contributor Author

I've run the tests again on VM, no significant difference

master

Benchmark                     (size)  Mode  Cnt      Score      Error  Units
ByteBuffers.testHeapHashCode      16  avgt   30      9.956 ?    0.537  ns/op
ByteBuffers.testHeapHashCode    1024  avgt   30    639.355 ?    4.158  ns/op
ByteBuffers.testHeapHashCode  131072  avgt   30  84327.624 ? 1231.085  ns/op

patch

Benchmark                     (size)  Mode  Cnt      Score      Error  Units
ByteBuffers.testHeapHashCode      16  avgt   30      7.791 ?    0.158  ns/op
ByteBuffers.testHeapHashCode    1024  avgt   30    669.107 ?   10.464  ns/op
ByteBuffers.testHeapHashCode  131072  avgt   30  85484.992 ? 2064.665  ns/op

I think in a week I'll be able to run this on Linux machine

@AlanBateman
Copy link
Contributor

AlanBateman commented Dec 12, 2023

Here's the results that I see

ByteBuffers.testHeapHashCode      16  avgt   30      21.364 ?  0.012  ns/op
ByteBuffers.testHeapHashCode    1024  avgt   30    1273.856 ?  1.102  ns/op
ByteBuffers.testHeapHashCode  131072  avgt   30  162732.079 ? 83.787  ns/op

with vectorizedHashCode:

ByteBuffers.testHeapHashCode      16  avgt   30     12.736 ? 0.025  ns/op
ByteBuffers.testHeapHashCode    1024  avgt   30     88.203 ? 0.049  ns/op
ByteBuffers.testHeapHashCode  131072  avgt   30  10639.662 ? 5.396  ns/op

@vlsi
Copy link

vlsi commented Dec 12, 2023

Should the change handle the other buffer types like HeapIntBuffer, HeapShortBuffer, HeapLongBuffer, HeapDoubleBuffer, HeapFloatBuffer as well?

It looks like vectorization is not supported for long, double, float yet:

case T_BOOLEAN -> signedHashCode(initialValue, (byte[]) array, fromIndex, length);
case T_CHAR -> array instanceof byte[]
? utf16hashCode(initialValue, (byte[]) array, fromIndex, length)
: hashCode(initialValue, (char[]) array, fromIndex, length);
case T_BYTE -> hashCode(initialValue, (byte[]) array, fromIndex, length);
case T_SHORT -> hashCode(initialValue, (short[]) array, fromIndex, length);
case T_INT -> hashCode(initialValue, (int[]) array, fromIndex, length);

However, HeapIntBuffer and HeapShortBuffer could probably be supported.

@bplb
Copy link
Member

bplb commented Dec 12, 2023

However, HeapIntBuffer and HeapShortBuffer could probably be supported.

The byte and char types probably account for a large percentage of use cases so perhaps it's not worth cluttering up the code with other #ifs for other cases. It's common for char to require special handling.

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

I think this looks okay. @bplb may want to review it too.

@openjdk
Copy link

openjdk bot commented Dec 12, 2023

@stsypanov 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:

8321279: Implement hashCode() in Heap-X-Buffer.java.template

Reviewed-by: alanb, bpb

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 13 new commits pushed to the master branch:

  • d5a96e3: 8321621: Update JCov version to 3.0.16
  • aadf368: 6230751: [Fmt-Ch] Recursive MessageFormats in ChoiceFormats ignore indicated subformats
  • a3447ec: 8321827: Remove unnecessary suppress warnings annotations from the printing processor
  • b25ed57: 8270269: Desktop.browse method fails if earlier CoInitialize call as COINIT_MULTITHREADED
  • df4ed7e: 8321739: Source launcher fails with "Not a directory" error
  • 5718039: 8321542: C2: Missing ChaCha20 stub for x86_32 leads to crashes
  • c516852: 8321889: JavaDoc method references with wrong (nested) type
  • 7d90396: 8321422: Test gc/g1/pinnedobjs/TestPinnedObjectTypes.java times out after completion
  • 6f48240: 8321729: Remove 'orb' field in RMIConnector
  • e1fd663: 8311306: Test com/sun/management/ThreadMXBean/ThreadCpuTimeArray.java failed: out of expected range
  • ... and 3 more: https://git.openjdk.org/jdk/compare/973bcdab81f754671de4c55656b8fb921bba4f61...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@AlanBateman, @bplb) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 12, 2023
Copy link
Member

@bplb bplb left a comment

Choose a reason for hiding this comment

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

I concur.

@stsypanov
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 12, 2023
@openjdk
Copy link

openjdk bot commented Dec 12, 2023

@stsypanov
Your change (at version d919253) is now ready to be sponsored by a Committer.

@AlanBateman
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 13, 2023

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

  • 3d9d353: 8321825: Remove runtime/CompressedOops/CompressedClassPointers.java from the ProblemList
  • 1b621f5: 8321474: TestAutoCreateSharedArchiveUpgrade.java should be updated with JDK 21
  • 5463c9c: 8321557: Move SOURCE line verification for OracleJDK out of OpenJDK
  • ac07355: 8320200: Use Elements predicates for record constructors to improve print output
  • 4fb5c12: 8321180: Condition for non-latin1 string size too large exception is off by one
  • d5a96e3: 8321621: Update JCov version to 3.0.16
  • aadf368: 6230751: [Fmt-Ch] Recursive MessageFormats in ChoiceFormats ignore indicated subformats
  • a3447ec: 8321827: Remove unnecessary suppress warnings annotations from the printing processor
  • b25ed57: 8270269: Desktop.browse method fails if earlier CoInitialize call as COINIT_MULTITHREADED
  • df4ed7e: 8321739: Source launcher fails with "Not a directory" error
  • ... and 8 more: https://git.openjdk.org/jdk/compare/973bcdab81f754671de4c55656b8fb921bba4f61...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 13, 2023
@openjdk openjdk bot closed this Dec 13, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Dec 13, 2023
@openjdk
Copy link

openjdk bot commented Dec 13, 2023

@AlanBateman @stsypanov Pushed as commit 8a0a6f8.

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

@stsypanov stsypanov deleted the 8321279 branch December 13, 2023 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated nio nio-dev@openjdk.org
5 participants