diff options
| author | Michael Pratt <mpratt@google.com> | 2025-11-12 15:20:54 -0500 |
|---|---|---|
| committer | Michael Pratt <mpratt@google.com> | 2025-11-12 13:54:59 -0800 |
| commit | f03d06ec1a69d77b4c43971cc474c3111a424c3a (patch) | |
| tree | a0abb10433b62babf83bfdf80e0c6b0f2e618eeb /src/runtime | |
| parent | 48127f656b53bfb5d73e7281ad525dbc371eb4c6 (diff) | |
| download | go-f03d06ec1a69d77b4c43971cc474c3111a424c3a.tar.xz | |
runtime: fix list test memory management for mayMoreStack
The NIH tests simply failed to allocate the nodes outside the heap at
all. The Manual tests failed to keep the nodes alive, allowing the GC to
collect them.
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest
Change-Id: I6a6a636c434bb703d6888383d32dbf95fb0a15ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/719962
TryBot-Bypass: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/list_manual_test.go | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/runtime/list_manual_test.go b/src/runtime/list_manual_test.go index 281a06ac86..f0b64b48ec 100644 --- a/src/runtime/list_manual_test.go +++ b/src/runtime/list_manual_test.go @@ -21,10 +21,19 @@ type listedValManual struct { bNode runtime.ListNodeManual } +// ListHeadManual is intended to be used with objects where the lifetime of the +// object is managed explicitly, so it is OK to store as uintptr. +// +// This means that our test values must outlive the test, and must not live on +// the stack (which may move). +var allListedValManual []*listedValManual + func newListedValManual(v int) *listedValManual { - return &listedValManual{ + lv := &listedValManual{ val: v, } + allListedValManual = append(allListedValManual, lv) + return lv } func TestListManualPush(t *testing.T) { @@ -239,13 +248,13 @@ func TestListNIHPush(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) p := headA.Pop() @@ -296,13 +305,13 @@ func TestListNIHRemoveHead(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(three)) @@ -326,13 +335,13 @@ func TestListNIHRemoveMiddle(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(two)) @@ -356,13 +365,13 @@ func TestListNIHRemoveTail(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(one)) @@ -386,13 +395,13 @@ func TestListNIHRemoveAll(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(one)) |
