RFR: 8201650: Move iteration order randomization of unmodifiable Set and Map to iterators
Claes Redestad
claes.redestad at oracle.com
Sat Apr 28 09:30:56 UTC 2018
Hi Stuart,
On 2018-04-28 02:37, Stuart Marks wrote:
>
> Hi Claes,
>
> I finally got a chance to look at this. Overall looks fine. Although
> the randomness is "weaker" iterating in both directions will, I think,
> still have the desired effect of flushing out order dependencies.
thanks, glad you agree with the direction here...
> I have a test (forthcoming) that verifies that iteration order will
> vary from run to run, and it passes with both the old and new code.
Great!
>
> Not an issue, but I'm curious as to why the initial index is chosen
> this way:
>
> idx = Math.floorMod(SALT ^ remaining, elements.length);
>
> The floorMod with a divisor of elements.length makes perfect sense.
> I'm wondering why the dividend is (SALT ^ remaining) and not just SALT
> for example.
Right, adding " ^ remaning" was a play to see if I could increase the
randomness of initial idx distribution for "free" when comparing a set
of N elements with a set of N+1 elements. While it has near zero
performance cost (no added loads, just a quick xor on values we load
anyway), I never got around to measuring if it improved or even worsened
the starting point "randomness". In the end it's not that important, so
I'll just remove it.
/Claes
More information about the core-libs-dev
mailing list