diff options
| author | David Chase <drchase@google.com> | 2023-01-13 16:12:47 -0500 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2023-01-23 15:51:32 +0000 |
| commit | e22bd2348c8e3bfdf12197d0b0e194b66bbf5a36 (patch) | |
| tree | 0c61869dae136d804b1e82091fc562cde4bf7efe /src/runtime/map_test.go | |
| parent | e2fe35363d070bf37326d04ed28964e6ba3892da (diff) | |
| download | go-e22bd2348c8e3bfdf12197d0b0e194b66bbf5a36.tar.xz | |
internal/abi,runtime: refactor map constants into one place
Previously TryBot-tested with bucket bits = 4.
Also tested locally with bucket bits = 5.
This makes it much easier to change the size of map
buckets, and hopefully provides pointers to all the
code that in some way depends on details of map layout.
Change-Id: I9f6669d1eadd02f182d0bc3f959dc5f385fa1683
Reviewed-on: https://go-review.googlesource.com/c/go/+/462115
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/map_test.go')
| -rw-r--r-- | src/runtime/map_test.go | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/runtime/map_test.go b/src/runtime/map_test.go index 4afbae6bc4..3675106d9c 100644 --- a/src/runtime/map_test.go +++ b/src/runtime/map_test.go @@ -6,6 +6,7 @@ package runtime_test import ( "fmt" + "internal/abi" "internal/goarch" "math" "reflect" @@ -506,7 +507,12 @@ func TestMapNanGrowIterator(t *testing.T) { } func TestMapIterOrder(t *testing.T) { - for _, n := range [...]int{3, 7, 9, 15} { + sizes := []int{3, 7, 9, 15} + if abi.MapBucketCountBits >= 5 { + // it gets flaky (often only one iteration order) at size 3 when abi.MapBucketCountBits >=5. + t.Fatalf("This test becomes flaky if abi.MapBucketCountBits(=%d) is 5 or larger", abi.MapBucketCountBits) + } + for _, n := range sizes { for i := 0; i < 1000; i++ { // Make m be {0: true, 1: true, ..., n-1: true}. m := make(map[int]bool) @@ -673,6 +679,17 @@ func TestIgnoreBogusMapHint(t *testing.T) { } } +const bs = abi.MapBucketCount + +// belowOverflow should be a pretty-full pair of buckets; +// atOverflow is 1/8 bs larger = 13/8 buckets or two buckets +// that are 13/16 full each, which is the overflow boundary. +// Adding one to that should ensure overflow to the next higher size. +const ( + belowOverflow = bs * 3 / 2 // 1.5 bs = 2 buckets @ 75% + atOverflow = belowOverflow + bs/8 // 2 buckets at 13/16 fill. +) + var mapBucketTests = [...]struct { n int // n is the number of map elements noescape int // number of expected buckets for non-escaping map @@ -682,11 +699,16 @@ var mapBucketTests = [...]struct { {-1, 1, 1}, {0, 1, 1}, {1, 1, 1}, - {8, 1, 1}, - {9, 2, 2}, - {13, 2, 2}, - {14, 4, 4}, - {26, 4, 4}, + {bs, 1, 1}, + {bs + 1, 2, 2}, + {belowOverflow, 2, 2}, // 1.5 bs = 2 buckets @ 75% + {atOverflow + 1, 4, 4}, // 13/8 bs + 1 == overflow to 4 + + {2 * belowOverflow, 4, 4}, // 3 bs = 4 buckets @75% + {2*atOverflow + 1, 8, 8}, // 13/4 bs + 1 = overflow to 8 + + {4 * belowOverflow, 8, 8}, // 6 bs = 8 buckets @ 75% + {4*atOverflow + 1, 16, 16}, // 13/2 bs + 1 = overflow to 16 } func TestMapBuckets(t *testing.T) { |
