runtime: fix bug in maps at the intersection of iterators, growing, and NaN keys
If an iterator is started while a map is in the middle of a grow,
and the map has NaN keys, then those keys might get returned by
the iterator more than once. This fix makes the evacuation decision
deterministic and repeatable for NaN keys so each one gets returned
only once.
On Fri, Oct 4, 2013 at 9:20 AM, <iant@golang.org> wrote: > > https://codereview.appspot.**com/14367043/diff/6001/src/** > pkg/runtime/hashmap.c<https://codereview.appspot.com/14367043/diff/6001/src/pkg/runtime/hashmap.c> ...
11 years, 7 months ago
(2013-10-04 20:04:06 UTC)
#6
On Fri, Oct 4, 2013 at 9:20 AM, <iant@golang.org> wrote:
>
> https://codereview.appspot.**com/14367043/diff/6001/src/**
>
pkg/runtime/hashmap.c<https://codereview.appspot.com/14367043/diff/6001/src/pkg/runtime/hashmap.c>
> File src/pkg/runtime/hashmap.c (right):
>
> https://codereview.appspot.**com/14367043/diff/6001/src/**
>
pkg/runtime/hashmap.c#**newcode886<https://codereview.appspot.com/14367043/diff/6001/src/pkg/runtime/hashmap.c#newcode886>
> src/pkg/runtime/hashmap.c:886: if(check_bucket >> (it->B - 1) !=
> (b->tophash[i] & 1)) {
> I don't understand why this condition is using check_bucket. If I'm
> following this code, what you want here is a condition that is random
> and can also be repeated in evacuate. But evacuate isn't using
> check_bucket or anything like it. What am I missing?
>
They are working in opposite directions, so it's a bit confusing. evacuate
is starting from an old bucket and moving to a new bucket. The relevant
part of hash_iter is starting with a new bucket and figuring out which of
the items in the old bucket will eventually end up there. check_bucket is
the new bucket ID when we are iterating through the old bucket, but really
it could just be a 1-bit value, as we know the rest of the bits must match
(at least for non-NaNs).
So evacuate is using the low bit of tophash to pick among the two
newbuckets to send an object to. hash_iter is using the low bit of tophash
to decide whether the the oldbucket item will come to the newbucket or not.
Make any sense?
>
>
https://codereview.appspot.**com/14367043/<https://codereview.appspot.com/143...
>
*** Submitted as https://code.google.com/p/go/source/detail?r=4b40cc3a2641 *** runtime: fix bug in maps at the intersection of iterators, ...
11 years, 7 months ago
(2013-10-04 20:54:06 UTC)
#10
*** Submitted as https://code.google.com/p/go/source/detail?r=4b40cc3a2641 ***
runtime: fix bug in maps at the intersection of iterators, growing, and NaN keys
If an iterator is started while a map is in the middle of a grow,
and the map has NaN keys, then those keys might get returned by
the iterator more than once. This fix makes the evacuation decision
deterministic and repeatable for NaN keys so each one gets returned
only once.
R=golang-dev, r, khr, iant
CC=golang-dev
https://codereview.appspot.com/14367043
Issue 14367043: code review 14367043: runtime: fix bug in maps at the intersection of iterato...
(Closed)
Created 11 years, 7 months ago by khr
Modified 11 years, 7 months ago
Reviewers:
Base URL:
Comments: 4