aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/map_test.go
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2018-01-29 21:40:57 +0100
committerMartin Möhrmann <moehrmann@google.com>2018-05-06 05:46:06 +0000
commit4ebc67d334336561af5844d8105b5daa81591b04 (patch)
treee99463e40fdf4fa29bb02a5939be89d021ae32ac /src/runtime/map_test.go
parentb9a59d9f2e78ce497b38a984f62094a53e7dfce7 (diff)
downloadgo-4ebc67d334336561af5844d8105b5daa81591b04.tar.xz
runtime: remove hmap field from maptypes
The hmap field in the maptype is only used by the runtime to check the sizes of the hmap structure created by the compiler and runtime agree. Comments are already present about the hmap structure definitions in the compiler and runtime needing to be in sync. Add a test that checks the runtimes hmap size is as expected to detect when the compilers and runtimes hmap sizes diverge instead of checking this at runtime when a map is created. Change-Id: I974945ebfdb66883a896386a17bbcae62a18cf2a Reviewed-on: https://go-review.googlesource.com/91796 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'src/runtime/map_test.go')
-rw-r--r--src/runtime/map_test.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/runtime/map_test.go b/src/runtime/map_test.go
index 5c6bbc5c31..0f20c84e77 100644
--- a/src/runtime/map_test.go
+++ b/src/runtime/map_test.go
@@ -9,6 +9,7 @@ import (
"math"
"reflect"
"runtime"
+ "runtime/internal/sys"
"sort"
"strconv"
"strings"
@@ -16,6 +17,17 @@ import (
"testing"
)
+func TestHmapSize(t *testing.T) {
+ // The structure of hmap is defined in runtime/map.go
+ // and in cmd/compile/internal/gc/reflect.go and must be in sync.
+ // The size of hmap should be 48 bytes on 64 bit and 28 bytes on 32 bit platforms.
+ var hmapSize = uintptr(8 + 5*sys.PtrSize)
+ if runtime.RuntimeHmapSize != hmapSize {
+ t.Errorf("sizeof(runtime.hmap{})==%d, want %d", runtime.RuntimeHmapSize, hmapSize)
+ }
+
+}
+
// negative zero is a good test because:
// 1) 0 and -0 are equal, yet have distinct representations.
// 2) 0 is represented as all zeros, -0 isn't.