jdk
jdk copied to clipboard
8290041: ModuleDescriptor.hashCode is inconsistent
Can I please get a review of this change which proposes to fix https://bugs.openjdk.org/browse/JDK-8290041?
As noted by the reporter, the current implementation is buggy since the calculation can result in a different value of the hashcode depending on the order of iteration of the Modifiers. The commit in this PR changes that computation to produce consistent result irrespective of the order in which the Modifiers (enum) is iterated upon.
A new test has been added which reproduces the issue and verifies the fix.
Progress
- [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue
Issue
- JDK-8290041: ModuleDescriptor.hashCode is inconsistent
Reviewing
Using git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9790/head:pull/9790
$ git checkout pull/9790
Update a local copy of the PR:
$ git checkout pull/9790
$ git pull https://git.openjdk.org/jdk pull/9790/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9790
View PR using the GUI difftool:
$ git pr show -t 9790
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9790.diff
:wave: Welcome back jpai! 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.
@jaikiran The following label will be automatically applied to this pull request:
core-libs
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.
Hi,
Sorry for joining late. I noticed that modsHashCode is a private method and it takes Iterable<? extends Enum<?>> as a parameter. But everywhere it is called, a Set<? extends Enum<?>> is passed to it. So why not just calling the set.hashCode() and be done with it? It may be even more optimal in some cases.
Sorry for joining late. I noticed that modsHashCode is a private method and it takes Iterable> as a parameter. But everywhere it is called, a Set> is passed to it. So why not just calling the set.hashCode() and be done with it? It may be even more optimal in some cases.
There's a lot going on here as the hash code is generated at link time and we also want it to be reproducible across builds. We also had a CDS bug with the the way that Enum objects were archived - Ioi has fixed that in JDK 19 so we have one less thing to be concerned about now.
Sorry for joining late. I noticed that modsHashCode is a private method and it takes Iterable as a parameter. But everywhere it is called, a Set is passed to it. So why not just calling the set.hashCode() and be done with it? It may be even more optimal in some cases.
There's a lot going on here as the hash code is generated at link time and we also want it to be reproducible across builds. We also had a CDS bug with the the way that Enum objects were archived - Ioi has fixed that in JDK 19 so we have one less thing to be concerned about now.
Ah, I see. Enum.hashCode() is identity hash code. I have been beaten by that in the past and apparently this is a sore point for many. I wonder if it could be changed. Is unstable hashCode (accross JVM instances) a feature here or just unfortunate implementation detail?
Mailing list message from Joe Darcy on core-libs-dev:
On 8/9/2022 11:56 PM, Peter Levart wrote:
On Sun, 7 Aug 2022 08:14:58 GMT, Alan Bateman <alanb at openjdk.org> wrote:
Sorry for joining late. I noticed that modsHashCode is a private method and it takes Iterable as a parameter. But everywhere it is called, a Set is passed to it. So why not just calling the set.hashCode() and be done with it? It may be even more optimal in some cases. There's a lot going on here as the hash code is generated at link time and we also want it to be reproducible across builds. We also had a CDS bug with the the way that Enum objects were archived - Ioi has fixed that in JDK 19 so we have one less thing to be concerned about now. Ah, I see. Enum.hashCode() is identity hash code. I have been beaten by that in the past and apparently this is a sore point for many. I wonder if it could be changed. Is unstable hashCode (accross JVM instances) a feature here or just unfortunate implementation detail?
We've gotten a few issues filed about Enum.hashCode() over the years, one more recent one is
??? JDK-8050217: Enum.hashCode() should return ordinal value for the enum, for better consistency
Current thinking per that issue is the present behavior is more of a feature than a bug.
-Joe
Hello Alan, Peter, you are right - the hashcode computation and do away with the * 43 part. I've updated this PR to do that change. I've also updated the tests to add coverage for the exports and requires modifiers as suggested by Alan.
I've now updated the PR to rename mdb to builder and add relevant imports to reduce line lengths where those enums were referenced.
@jaikiran 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:
8290041: ModuleDescriptor.hashCode is inconsistent
Reviewed-by: alanb
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 90 new commits pushed to the master branch:
- 21f4eb2233a95be44a5db59b7791cd952ddbd56e: 6521141: DebugGraphics NPE @ setFont();
- 6e6ae596d6bd73909b90911e01fbd0c16f6335e1: 8292286: Convert PlaceholderTable to ResourceHashtable
- ea2c82e74f5580f396920f9e561cbec80c03f373: 8291949: Unexpected extending of SupportedGroups
- b5707b0376660cd8763e46d525ba614b08a59d7b: 8292196: Reduce runtime of java.util.regex microbenchmarks
- b00eedeb029445417f99e8aa4e8fca12e5c69155: 8291511: Redefinition of EXIT_FAILURE in libw2k_lsa_auth
- 3a090777bada2e00f573fe8ab113bfa3884982eb: 8291337: Reduce runtime of vm.lamdba microbenchmarks
- dd2034b00725f0fc777c1706b1db898475e89c5c: 8291972: Fix double copy of arguments when thawing two interpreted frames
- aa5b71893307b9fe6137bc3541edccaab73735ac: 8292182: [TESTLIB] Enhance JAXPPolicyManager to setup required permissions for jtreg version 7 jar
- 695bb3939135394a4627d1c41cfc30d11b19bf48: 8292347: Remove unused Type::is_ptr_to_boxing_obj
- ec96b1f1879ee8ee5164be22d0a178f9d5048ab9: 8290291: G1: Merge multiple calls of block_size in HeapRegion::block_start
- ... and 80 more: https://git.openjdk.org/jdk/compare/87cda21c5d85f6e6f628849b8670e2ecb4e105dd...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.
Thank you Alan and Peter for the reviews. tier1, tier2 and tier3 testing passed with these changes.
/integrate
Going to push as commit 4cc6cb9d9ddbcc540baac7b81398f2af83f93340.
Since your change was applied there have been 91 commits pushed to the master branch:
- d1edda8ff52e172a85d102d7d5062b9cc401beea: 8292338: aarch64: Use cbnz instruction in gen_continuation_enter when possible
- 21f4eb2233a95be44a5db59b7791cd952ddbd56e: 6521141: DebugGraphics NPE @ setFont();
- 6e6ae596d6bd73909b90911e01fbd0c16f6335e1: 8292286: Convert PlaceholderTable to ResourceHashtable
- ea2c82e74f5580f396920f9e561cbec80c03f373: 8291949: Unexpected extending of SupportedGroups
- b5707b0376660cd8763e46d525ba614b08a59d7b: 8292196: Reduce runtime of java.util.regex microbenchmarks
- b00eedeb029445417f99e8aa4e8fca12e5c69155: 8291511: Redefinition of EXIT_FAILURE in libw2k_lsa_auth
- 3a090777bada2e00f573fe8ab113bfa3884982eb: 8291337: Reduce runtime of vm.lamdba microbenchmarks
- dd2034b00725f0fc777c1706b1db898475e89c5c: 8291972: Fix double copy of arguments when thawing two interpreted frames
- aa5b71893307b9fe6137bc3541edccaab73735ac: 8292182: [TESTLIB] Enhance JAXPPolicyManager to setup required permissions for jtreg version 7 jar
- 695bb3939135394a4627d1c41cfc30d11b19bf48: 8292347: Remove unused Type::is_ptr_to_boxing_obj
- ... and 81 more: https://git.openjdk.org/jdk/compare/87cda21c5d85f6e6f628849b8670e2ecb4e105dd...master
Your commit was automatically rebased without conflicts.
@jaikiran Pushed as commit 4cc6cb9d9ddbcc540baac7b81398f2af83f93340.
:bulb: You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.