RFR: 8247373: ArraysSupport.newLength doc, test, and exception message
Stuart Marks
stuart.marks at oracle.com
Fri Dec 4 06:58:50 UTC 2020
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:
> 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:
>
> 1. 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!
>
> 2. 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.
>
> -------------
>
> Commit messages:
> - 8247373: ArraysSupport.newLength doc, test, and exception message
>
> Changes: https://git.openjdk.java.net/jdk/pull/1617/files
> Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1617&range=00
> Issue: https://bugs.openjdk.java.net/browse/JDK-8247373
> Stats: 171 lines in 4 files changed: 137 ins; 3 del; 31 mod
> Patch: https://git.openjdk.java.net/jdk/pull/1617.diff
> Fetch: git fetch https://git.openjdk.java.net/jdk pull/1617/head:pull/1617
>
> PR: https://git.openjdk.java.net/jdk/pull/1617
>
More information about the core-libs-dev
mailing list