Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-20 Thread Andrew Haley
On 2/11/22 19:25, XenoAmess wrote: On Fri, 11 Feb 2022 18:24:49 GMT, Andrew Haley wrote: Just multiply by 0.75. On a modern design, floating-point multiply is 4 clocks latency, 4 ops/clock throughput. FP max is 2 clocks latency, conversions int-float and vice versa 3 clocks latency, 4 ops/c

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread XenoAmess
On Fri, 11 Feb 2022 18:24:49 GMT, Andrew Haley wrote: > Just multiply by 0.75. > > On a modern design, floating-point multiply is 4 clocks latency, 4 ops/clock > throughput. FP max is 2 clocks latency, conversions int-float and vice versa > 3 clocks latency, 4 ops/clock throughput. Long divisi

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread Andrew Haley
On Fri, 11 Feb 2022 18:13:36 GMT, Roger Riggs wrote: >> @RogerRiggs >> so you recommend `(int) Math.min(((m.size() * 4L + 2L) / 3L), >> Integer.MAX_VALUE)`? OK then, changed it. >> please review again, thanks! > > Works for me. Thanks Just multiply by 0.75. On a modern design, floating-point

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread Roger Riggs
On Fri, 11 Feb 2022 17:04:14 GMT, XenoAmess wrote: >> Performance is a lesser issue. Given all of the other computation that >> occurs to populate the map, this computation is in the noise. It is also >> likely that with more instructions to fetch and execute and a possible >> branch, the int

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread XenoAmess
On Fri, 11 Feb 2022 16:32:29 GMT, Roger Riggs wrote: >> @RogerRiggs >> >> Hi. I added a overflow check. >> >> The check makes sure it cannot overflow now. >> >> I wrote a test to show this overflow check be correct. >> >> >> public class A { >> >> /** >> * use for calculate HashMap

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread Roger Riggs
On Fri, 11 Feb 2022 15:48:44 GMT, XenoAmess wrote: >> src/java.base/share/classes/java/util/WeakHashMap.java line 247: >> >>> 245: */ >>> 246: private static int calculateHashMapCapacity(int size){ >>> 247: return size + (size + 2) / 3; >> >> Consider integer overflow; if size

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread XenoAmess
On Fri, 11 Feb 2022 15:04:03 GMT, Roger Riggs wrote: >> XenoAmess has refreshed the contents of this pull request, and previous >> commits have been removed. The incremental views will show differences >> compared to the previous content of the PR. The pull request contains one >> new commit s

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread XenoAmess
On Fri, 11 Feb 2022 15:04:03 GMT, Roger Riggs wrote: > if size were Integer.MAX_VALUE / 2; the computation would overflow Actually will not, it must be slightly larger. it will only overflow when it be larger than Integer.MAX_VALUE * 0.75 But yes, it can overflow when there be a map as large a

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread Roger Riggs
On Fri, 11 Feb 2022 13:04:38 GMT, XenoAmess wrote: >> 8281631: HashMap.putAll can cause redundant space waste > > XenoAmess has refreshed the contents of this pull request, and previous > commits have been removed. The incremental views will show differences > compared to the previous content o

Re: RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]

2022-02-11 Thread XenoAmess
> 8281631: HashMap.putAll can cause redundant space waste XenoAmess has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the