Array max size auditing and fixes#6671
Merged
headius merged 5 commits intojruby:jruby-9.2from May 13, 2021
Merged
Conversation
This also reduces the fallback maximum to Integer.MAX_VALUE - 2, which seems to be the actual effective size for allocating a new array. See jruby#6670.
Member
Author
|
Hmm... so it turns out this effective max array size varies across VMs. As pointed out in some answers here, the OpenJDK ArrayList impl uses MAX_VALUE - 8 to be safe, but there does not appear to be any way to query for the actual effective maximum. We may want to make our max also MAX_VALUE - 8 since that would correspond to a 64-bit pointer alignment. |
Based on explorations for jruby#6670 we found that the effective max array size is actually Integer.MAX_VALUE - 2, so this localizes the multiplication logic and uses that limit as the upper bound. $ jruby -w -e 'foo = "x" * 2147483645; p :ok' :ok $ jruby -w -e 'foo = "x" * 2147483646; p :ok' ArgumentError: argument too big * at org/jruby/RubyString.java:1197 <main> at -e:1
3a335e5 to
eada15f
Compare
Member
Author
|
The array size maximum from AbstractCollection (mentioned in the SO answers above) appears to have been refactored into a utility similar to what we have in this PR: openjdk/jdk@218204b#diff-62a6afd2b76188557fb1b7ccabcfd8398d08eec42983af0c562ef72a588324bf I think it is probably appropriate for us to use |
See refactoring that occurred in OpenJDK here, normalizing many array-allocating paths to MAX - 8: openjdk/jdk@218204b#diff-62a6afd2b76188557fb1b7ccabcfd8398d08eec42983af0c562ef72a588324bf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a follow-up to #6670 that audits other locations we allocate arrays.