-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8247373: ArraysSupport.newLength doc, test, and exception message #1617
8247373: ArraysSupport.newLength doc, test, and exception message #1617
Conversation
👋 Welcome back smarks! A progress list of the required criteria for merging this PR into |
@stuart-marks The following label will be automatically applied to this pull request:
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. |
Webrevs
|
Mailing list message from Stuart Marks on core-libs-dev: Hi Martin, I'd appreciate it if you could take a look at this. Thanks, s'marks On 12/3/20 10:57 PM, Stuart Marks wrote: |
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.
Nice clean description of the algorithm.
{ SOFT+1, 1, IMAX, SOFT+2 }, | ||
{ IMAX-2, 1, IMAX, IMAX-1 }, | ||
{ IMAX-1, 1, IMAX, IMAX } | ||
}; |
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.
Adding test cases for zero (0) for the min and preferred would be good to include and show any unpredictable behavior.
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.
No, I don't want to add test cases that violate the preconditions. I guess I could add a prefGrowth==0 case though.
* might exceed the JVM's implementation limit. In that case, the caller will likely | ||
* attempt an array allocation with that length and encounter an OutOfMemoryError. | ||
* Of course, regardless of the length value returned from this method, the caller | ||
* may encounter OutOfMemoryError if there is insufficient heap to fufill the request. |
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.
typo in line 626: fufill -> fulfill
For what it's worth, the following code: var list = Collections.nCopies(Integer.MAX_VALUE - 3, "");
var list2 = new ArrayList<>(list);
list2.addAll(list); results in
|
@stuart-marks 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:
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 1192 new commits pushed to the
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 |
src/java.base/share/classes/jdk/internal/util/ArraysSupport.java
Outdated
Show resolved
Hide resolved
@Martin-Buchholz Any comments on this? |
@stuart-marks 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! |
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.
Many years ago, when I wrote the unfactored MAX_ARRAY_LENGTH code, I considered refactoring it, but didn't follow through because various implementations had too many small differences . I'm glad you made it work.
I'm happy to see good tests added. Testability is a benefit of refactoring.
I'm happy to see the name change to SOFT_MAX_ARRAY_LENGTH - that's a better name.
src/java.base/share/classes/jdk/internal/util/ArraysSupport.java
Outdated
Show resolved
Hide resolved
} catch (OutOfMemoryError oome) { | ||
// ok |
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.
Instead of an //ok comment, I like to give the exception a name that makes the intent clear.
} catch (IllegalArgumentException success) {}
The new docs and tests are superb. |
@stuart-marks 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! |
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.
Overall this looks good.
src/java.base/share/classes/jdk/internal/util/ArraysSupport.java
Outdated
Show resolved
Hide resolved
/integrate |
@stuart-marks Since your change was applied there have been 1192 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit f18c019. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This rewrites the doc of ArraysSupport.newLength, adds detail to the exception message, and adds a test. In addition to some renaming and a bit of refactoring of the actual code, I also made two changes of substance to the code:
I fixed a problem with overflow checking. In the original code, if oldLength and prefGrowth were both very large (say, Integer.MAX_VALUE), this method could return a negative value. It turns out that writing tests helps find bugs!
Under the old policy, if oldLength and minGrowth required a length above SOFT_MAX_ARRAY_LENGTH but not above Integer.MAX_VALUE, this method would return Integer.MAX_VALUE. That doesn't make any sense, because attempting to allocate an array of that length will almost certainly cause the Hotspot to throw OOME because its implementation limit was exceeded. Instead, if the required length is in this range, this method returns that required length.
Separately, I'll work on retrofitting various call sites around the JDK to use this method.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1617/head:pull/1617
$ git checkout pull/1617