Skip to content

Commit 96e142b

Browse files
committed
runtime: skip TestArenaCollision if we run out of hints
This seems failure mode seems to have become more common on Windows. I suspect the randomized heap base address has something to do with it, but I'm not 100% sure. What's definitely certain is that we're running out of hints, since we're seeing failures that mheap_.arenaHints is nil and GetNextArenaHint doesn't actually check that. At the very least we can check that and skip. We know that in this case there's not that much we can do. Fixes #76566. Change-Id: I8ccc8994806b6c95e3157eb296b09705637564b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/726527 Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent fe4952f commit 96e142b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/runtime/export_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,11 @@ func MapNextArenaHint() (start, end uintptr, ok bool) {
551551
return
552552
}
553553

554-
func GetNextArenaHint() uintptr {
555-
return mheap_.arenaHints.addr
554+
func NextArenaHint() (uintptr, bool) {
555+
if mheap_.arenaHints == nil {
556+
return 0, false
557+
}
558+
return mheap_.arenaHints.addr, true
556559
}
557560

558561
type G = g

src/runtime/malloc_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,10 +664,24 @@ func TestArenaCollision(t *testing.T) {
664664
}
665665
t.Logf("reserved [%#x, %#x)", start, end)
666666
disallowed = append(disallowed, [2]uintptr{start, end})
667+
668+
hint, ok := NextArenaHint()
669+
if !ok {
670+
// We're out of arena hints. There's not much we can do now except give up.
671+
// This might happen for a number of reasons, like if there's just something
672+
// else already mapped in the address space where we put our hints. This is
673+
// a bit more common than it used to be thanks to heap base randomization.
674+
t.Skip("ran out of arena hints")
675+
}
676+
667677
// Allocate until the runtime tries to use the hint we
668678
// just mapped over.
669-
hint := GetNextArenaHint()
670-
for GetNextArenaHint() == hint {
679+
for {
680+
if next, ok := NextArenaHint(); !ok {
681+
t.Skip("ran out of arena hints")
682+
} else if next != hint {
683+
break
684+
}
671685
ac := new(acLink)
672686
arenaCollisionSink = append(arenaCollisionSink, ac)
673687
// The allocation must not have fallen into

0 commit comments

Comments
 (0)