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

8284780: Need methods to create pre-sized HashSet and LinkedHashSet #8302

Closed
wants to merge 28 commits into from

Conversation

XenoAmess
Copy link
Contributor

@XenoAmess XenoAmess commented Apr 19, 2022

as title.


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
  • Change requires a CSR request to be approved

Issues

  • JDK-8284780: Need methods to create pre-sized HashSet and LinkedHashSet
  • JDK-8287419: Need methods to create pre-sized HashSet and LinkedHashSet (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8302/head:pull/8302
$ git checkout pull/8302

Update a local copy of the PR:
$ git checkout pull/8302
$ git pull https://git.openjdk.java.net/jdk pull/8302/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 8302

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8302.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 19, 2022

👋 Welcome back XenoAmess! 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 Apr 19, 2022

@XenoAmess 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.

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review labels Apr 19, 2022
@mlbridge
Copy link

mlbridge bot commented Apr 19, 2022

@liach
Copy link
Member

liach commented Apr 19, 2022

Need to add apiNote documentation section to capacity-based constructors like for maps.

@dfuch
Copy link
Member

dfuch commented Apr 20, 2022

/csr needed

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Apr 20, 2022
@openjdk
Copy link

openjdk bot commented Apr 20, 2022

@dfuch has indicated that a compatibility and specification (CSR) request is needed for this pull request.
@XenoAmess please create a CSR request for issue JDK-8284780. This pull request cannot be integrated until the CSR request is approved.

@XenoAmess
Copy link
Contributor Author

/csr needed

@stuart-marks csr please

@XenoAmess
Copy link
Contributor Author

Need to add apiNote documentation section to capacity-based constructors like for maps.

@liach done.

@bridgekeeper
Copy link

bridgekeeper bot commented May 18, 2022

@XenoAmess This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@stuart-marks
Copy link
Member

@XenoAmess oops, sorry for the delay. I think it would be good to get these into 19 as companions to HashMap.newHashMap et. al.

As before, I'd suggest reducing the number of changes to use sites in order to make review easier. I would suggest keeping the changes under src in java.base, java.net.http, java.rmi, and jdk.zipfs, and omitting all the other changes. Also keep the changes under test/jdk.

There needs to be a test for these new methods. I haven't thought much how to do that. My first attempt would be to modify our favorite WhiteBoxResizeTest and add a bit of machinery that asserts the table length of the HashMap contained within the created HashSet/LinkedHashSet. I haven't looked at it though, so it might not work out, in which case you should pursue an alternative approach.

I'll look at the specs and suggest updates as necessary and then handle filing of a CSR.

@XenoAmess
Copy link
Contributor Author

XenoAmess commented May 24, 2022

@stuart-marks

suggest keeping the changes under src in java.base, java.net.http, java.rmi, and jdk.zipfs, and omitting all the other changes. Also keep the changes under test/jdk.

Done.

modify our favorite WhiteBoxResizeTest and add a bit of machinery that asserts the table length of the HashMap contained within the created HashSet/LinkedHashSet.

Test added...I don't really know if the test be done in the way you want, but I think it could work.

Copy link
Member

@stuart-marks stuart-marks left a comment

Choose a reason for hiding this comment

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

I looked at all the use sites and they look fine. Some look like they could use additional cleanup, but that's probably beyond the scope of this change. (Also, I haven't seen StringTokenizer in a long time....) It's amazing how many bugs there are -- the majority look like they allocated the HashSet with the wrong capacity! Again, this proves the worth of these new APIs.

test/jdk/java/util/HashMap/WhiteBoxResizeTest.java Outdated Show resolved Hide resolved
@naotoj
Copy link
Member

naotoj commented May 25, 2022

(Also, I haven't seen StringTokenizer in a long time....)

That's some old code lingering in locale-related stuff. Will fix them after this PR gets integrated.

@stuart-marks
Copy link
Member

Reviewers for i18n, net, nio, and security, please review call site changes in your areas. Thanks.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Jun 1, 2022
Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

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

Reviewed i18n-related changes and they look good. One minor suggestion in Calendar, but that can be applied later.

src/java.base/share/classes/java/util/Calendar.java Outdated Show resolved Hide resolved
@openjdk
Copy link

openjdk bot commented Jun 1, 2022

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

8284780: Need methods to create pre-sized HashSet and LinkedHashSet

Reviewed-by: naoto, bpb, dfuchs, ascarpino

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

  • 130ce7c: 8288052: Small logging clarification during failed heap shrinkage
  • b623398: 8287901: Loom: Failures with -XX:+VerifyStack
  • 04f02ac: 8214976: Warn about uses of functions replaced for portability
  • 024a240: 8287333: Clean up ParamTaglet and ThrowsTaglet
  • c8cff1b: 8202449: overflow handling in Random.doubles
  • c15e10f: 8233760: Result of BigDecimal.toString throws overflow exception on new BigDecimal(str)
  • b92ce26: 8281001: Class::forName(String) defaults to system class loader if the caller is null
  • c68419f: 8286990: Add compiler name to warning messages in Compiler Directive
  • 6fb84e2: 8287541: Files.writeString fails to throw IOException for charset "windows-1252"
  • a9b9831: 8286663: Resolve IDE warnings in WTrayIconPeer and SystemTray
  • ... and 192 more: https://git.openjdk.java.net/jdk/compare/7cb368b34df97614f0d208b8b0b93aa714a49282...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 (@stuart-marks, @naotoj, @bplb, @dfuch, @ascarpino) 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 Jun 1, 2022
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.

java.io and java.nio look all right.

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

Changes to net and http look good.

@openjdk-notifier
Copy link

@XenoAmess Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information.

@XenoAmess
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 8, 2022
@openjdk
Copy link

openjdk bot commented Jun 8, 2022

@XenoAmess
Your change (at version 95d59b9) is now ready to be sponsored by a Committer.

@stuart-marks
Copy link
Member

Running tests and awaiting review from security team. Our internal test system is backlogged and tests might not complete in time to get into JDK 19.

Copy link
Contributor

@ascarpino ascarpino left a comment

Choose a reason for hiding this comment

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

I gave a quick look at the security files touched and seems straightforward. I didn't see any problems

@stuart-marks
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 9, 2022

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

  • a941bc2: 8288082: Build failure due to clang_major is not defined after JDK-8214976
  • 65f0829: 8288068: Javadoc contains spurious reference to CLinker
  • 130ce7c: 8288052: Small logging clarification during failed heap shrinkage
  • b623398: 8287901: Loom: Failures with -XX:+VerifyStack
  • 04f02ac: 8214976: Warn about uses of functions replaced for portability
  • 024a240: 8287333: Clean up ParamTaglet and ThrowsTaglet
  • c8cff1b: 8202449: overflow handling in Random.doubles
  • c15e10f: 8233760: Result of BigDecimal.toString throws overflow exception on new BigDecimal(str)
  • b92ce26: 8281001: Class::forName(String) defaults to system class loader if the caller is null
  • c68419f: 8286990: Add compiler name to warning messages in Compiler Directive
  • ... and 194 more: https://git.openjdk.java.net/jdk/compare/7cb368b34df97614f0d208b8b0b93aa714a49282...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 9, 2022
@openjdk openjdk bot closed this Jun 9, 2022
@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 Jun 9, 2022
@openjdk
Copy link

openjdk bot commented Jun 9, 2022

@stuart-marks @XenoAmess Pushed as commit e01cd7c.

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

arteam added a commit to elastic/elasticsearch that referenced this pull request Jun 23, 2022
The HashSet(int) constructor accepts the capacity of the set rather than its size. Unfortunately, HashSet requires N/0.75 capacity to hold N elements. So, if we call new HashSet(n) to hold N elements, the map will be too small and need to be
resized/rehashed midway.

We add a new methods Sets.newHashSetWithExpectedSize and Sets.newLinkedHashSetWithExpectedSize that calculate the correct capacity for the specified expected size.

See

* https://bugs.openjdk.org/browse/JDK-8284975
* https://bugs.openjdk.org/browse/JDK-8287419
* openjdk/jdk#8302
arteam added a commit to arteam/elasticsearch that referenced this pull request Jun 23, 2022
The HashSet(int) constructor accepts the capacity of the set rather than its size. Unfortunately, HashSet requires N/0.75 capacity to hold N elements. So, if we call new HashSet(n) to hold N elements, the map will be too small and need to be
resized/rehashed midway.

We add a new methods Sets.newHashSetWithExpectedSize and Sets.newLinkedHashSetWithExpectedSize that calculate the correct capacity for the specified expected size.

See

* https://bugs.openjdk.org/browse/JDK-8284975
* https://bugs.openjdk.org/browse/JDK-8287419
* openjdk/jdk#8302

(cherry picked from commit 26c1d33)
arteam added a commit to elastic/elasticsearch that referenced this pull request Jun 23, 2022
The HashSet(int) constructor accepts the capacity of the set rather than its size. Unfortunately, HashSet requires N/0.75 capacity to hold N elements. So, if we call new HashSet(n) to hold N elements, the map will be too small and need to be
resized/rehashed midway.

We add a new methods Sets.newHashSetWithExpectedSize and Sets.newLinkedHashSetWithExpectedSize that calculate the correct capacity for the specified expected size.

See

* https://bugs.openjdk.org/browse/JDK-8284975
* https://bugs.openjdk.org/browse/JDK-8287419
* openjdk/jdk#8302

(cherry picked from commit 26c1d33)
@stuart-marks
Copy link
Member

@liach

'the new' fix should be applied to newHashMap etc. too.

I've filed JDK-8289872 for this. It's a small thing but best to fix it before we forget about it.

@XenoAmess
Copy link
Contributor Author

@liach

'the new' fix should be applied to newHashMap etc. too.

I've filed JDK-8289872 for this. It's a small thing but best to fix it before we forget about it.

Sorry for I already forgotten it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated net net-dev@openjdk.org nio nio-dev@openjdk.org security security-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

8 participants