From: Austin Clements Date: Wed, 4 Apr 2018 16:54:47 +0000 (-0400) Subject: runtime: stop when we run out of hints in race mode X-Git-Tag: go1.11beta1~975 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4946d9e87b7340b7846fa2e5f4aea28c4d5f6ab4;p=gostls13.git runtime: stop when we run out of hints in race mode Currently, the runtime falls back to asking for any address the OS can offer for the heap when it runs out of hint addresses. However, the race detector assumes the heap lives in [0x00c000000000, 0x00e000000000), and will fail in a non-obvious way if we go outside this region. Fix this by actively throwing a useful error if we run out of heap hints in race mode. This problem is currently being triggered by TestArenaCollision, which intentionally triggers this fallback behavior. Fix the test to look for the new panic message in race mode. Fixes #24670. Updates #24133. Change-Id: I57de6d17a3495dc1f1f84afc382cd18a6efc2bf7 Reviewed-on: https://go-review.googlesource.com/104717 Run-TryBot: Austin Clements Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 6e04f50e1d..5738a96a87 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -557,6 +557,14 @@ func (h *mheap) sysAlloc(n uintptr) (v unsafe.Pointer, size uintptr) { } if size == 0 { + if raceenabled { + // The race detector assumes the heap lives in + // [0x00c000000000, 0x00e000000000), but we + // just ran out of hints in this region. Give + // a nice failure. + throw("too many address space collisions for -race mode") + } + // All of the hints failed, so we'll take any // (sufficiently aligned) address the kernel will give // us. diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go index 854533f238..0bce059f7f 100644 --- a/src/runtime/malloc_test.go +++ b/src/runtime/malloc_test.go @@ -7,6 +7,7 @@ package runtime_test import ( "flag" "fmt" + "internal/race" "internal/testenv" "os" "os/exec" @@ -170,7 +171,17 @@ func TestArenaCollision(t *testing.T) { if os.Getenv("TEST_ARENA_COLLISION") != "1" { cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestArenaCollision", "-test.v")) cmd.Env = append(cmd.Env, "TEST_ARENA_COLLISION=1") - if out, err := cmd.CombinedOutput(); !strings.Contains(string(out), "PASS\n") || err != nil { + out, err := cmd.CombinedOutput() + if race.Enabled { + // This test runs the runtime out of hint + // addresses, so it will start mapping the + // heap wherever it can. The race detector + // doesn't support this, so look for the + // expected failure. + if want := "too many address space collisions"; !strings.Contains(string(out), want) { + t.Fatalf("want %q, got:\n%s", want, string(out)) + } + } else if !strings.Contains(string(out), "PASS\n") || err != nil { t.Fatalf("%s\n(exit status %v)", string(out), err) } return