8341243: Use ArraySupport.SOFT_MAX_ARRAY_LENGTH for max array size in java.base #21268
+55
−41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please review this cleanup PR which updates code and tests in
java.base
to consistently usejdk.internal.util.ArraySupport.SOFT_MAX_ARRAY_LENGTH
when referring to the JVM's maximum array size implementation limit. Currently, instances ofInteger.MAX_VALUE - 8
are found across the code base, with varying degrees of documentation. It would be good to consolidate on a single source of truth, with proper documentation.This PR is a follow-up to #20905 where the same change was requested in
java.util.zip
.My understanding is that javac will fold this constant value into the byte code of the compiled use sites, as such this change should not affect class loading or cause startup issues.
Instances selected for this PR were found searching for "Integer.MAX_VALUE - 8". The PR replaces these with
ArraySupport.SOFT_MAX_ARRAY_LENGTH
, while trimming or amending some code comments where appropriate. (SOFT_MAX_ARRAY_LENGTH
already has a good explainer which does not need repetition at each use site).I also searched for instances of
Integer.MAX_VALUE - 1
andInteger.MAX_VALUE - 2
, no convincing candidates were found.Instances outside
java.base
were deliberately left out to limit the scope and review cost of this PR.Tests updated to use
SOFT_MAX_ARRAY_LENGTH
are updated with the jtreg tag@modules java.base/jdk.internal.util
.Testing: No new tests are added in this PR, the
noreg-cleanup
label is added to the JBS. The five affected tests have been run manually. GHA tests run green.Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21268/head:pull/21268
$ git checkout pull/21268
Update a local copy of the PR:
$ git checkout pull/21268
$ git pull https://git.openjdk.org/jdk.git pull/21268/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21268
View PR using the GUI difftool:
$ git pr show -t 21268
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21268.diff
Webrev
Link to Webrev Comment