RFR: 8322149: ConcurrentHashMap smarter presizing for copy constructor and putAll [v3]
ExE Boss
duke at openjdk.org
Thu Jan 18 07:20:15 UTC 2024
On Thu, 18 Jan 2024 05:32:26 GMT, jmehrens <duke at openjdk.org> wrote:
>> Joshua Cao has updated the pull request incrementally with one additional commit since the last revision:
>>
>> putAll presize based on sum on both map sizes
>
> src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java line 1088:
>
>> 1086: public void putAll(Map<? extends K, ? extends V> m) {
>> 1087: if (table != null) {
>> 1088: tryPresize(size() + m.size());
>
> Is overflow not an issue here because calling tryPresize with a negative value will invoke tableSizeFor?
When `tableSizeFor` is called with a negative value greater than `Integer.MIN_VALUE`, it’ll just return `+1`:
https://github.com/openjdk/jdk/blob/ff8cc268fdaaf85299c94088a226b73e7eaf6bdb/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java#L704-L707
This will in turn cause `tryPresize` to do nothing when `table` is already initialized.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17116#discussion_r1457023596
More information about the core-libs-dev
mailing list