Skip to content

Commit f03d06e

Browse files
committed
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 <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 48127f6 commit f03d06e

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/runtime/list_manual_test.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ type listedValManual struct {
2121
bNode runtime.ListNodeManual
2222
}
2323

24+
// ListHeadManual is intended to be used with objects where the lifetime of the
25+
// object is managed explicitly, so it is OK to store as uintptr.
26+
//
27+
// This means that our test values must outlive the test, and must not live on
28+
// the stack (which may move).
29+
var allListedValManual []*listedValManual
30+
2431
func newListedValManual(v int) *listedValManual {
25-
return &listedValManual{
32+
lv := &listedValManual{
2633
val: v,
2734
}
35+
allListedValManual = append(allListedValManual, lv)
36+
return lv
2837
}
2938

3039
func TestListManualPush(t *testing.T) {
@@ -239,13 +248,13 @@ func TestListNIHPush(t *testing.T) {
239248
headA := newListHeadNIH()
240249
headA.Init(unsafe.Offsetof(listedValNIH{}.aNode))
241250

242-
one := newListedVal(1)
251+
one := newListedValNIH(1)
243252
headA.Push(unsafe.Pointer(one))
244253

245-
two := newListedVal(2)
254+
two := newListedValNIH(2)
246255
headA.Push(unsafe.Pointer(two))
247256

248-
three := newListedVal(3)
257+
three := newListedValNIH(3)
249258
headA.Push(unsafe.Pointer(three))
250259

251260
p := headA.Pop()
@@ -296,13 +305,13 @@ func TestListNIHRemoveHead(t *testing.T) {
296305
headA := newListHeadNIH()
297306
headA.Init(unsafe.Offsetof(listedValNIH{}.aNode))
298307

299-
one := newListedVal(1)
308+
one := newListedValNIH(1)
300309
headA.Push(unsafe.Pointer(one))
301310

302-
two := newListedVal(2)
311+
two := newListedValNIH(2)
303312
headA.Push(unsafe.Pointer(two))
304313

305-
three := newListedVal(3)
314+
three := newListedValNIH(3)
306315
headA.Push(unsafe.Pointer(three))
307316

308317
headA.Remove(unsafe.Pointer(three))
@@ -326,13 +335,13 @@ func TestListNIHRemoveMiddle(t *testing.T) {
326335
headA := newListHeadNIH()
327336
headA.Init(unsafe.Offsetof(listedValNIH{}.aNode))
328337

329-
one := newListedVal(1)
338+
one := newListedValNIH(1)
330339
headA.Push(unsafe.Pointer(one))
331340

332-
two := newListedVal(2)
341+
two := newListedValNIH(2)
333342
headA.Push(unsafe.Pointer(two))
334343

335-
three := newListedVal(3)
344+
three := newListedValNIH(3)
336345
headA.Push(unsafe.Pointer(three))
337346

338347
headA.Remove(unsafe.Pointer(two))
@@ -356,13 +365,13 @@ func TestListNIHRemoveTail(t *testing.T) {
356365
headA := newListHeadNIH()
357366
headA.Init(unsafe.Offsetof(listedValNIH{}.aNode))
358367

359-
one := newListedVal(1)
368+
one := newListedValNIH(1)
360369
headA.Push(unsafe.Pointer(one))
361370

362-
two := newListedVal(2)
371+
two := newListedValNIH(2)
363372
headA.Push(unsafe.Pointer(two))
364373

365-
three := newListedVal(3)
374+
three := newListedValNIH(3)
366375
headA.Push(unsafe.Pointer(three))
367376

368377
headA.Remove(unsafe.Pointer(one))
@@ -386,13 +395,13 @@ func TestListNIHRemoveAll(t *testing.T) {
386395
headA := newListHeadNIH()
387396
headA.Init(unsafe.Offsetof(listedValNIH{}.aNode))
388397

389-
one := newListedVal(1)
398+
one := newListedValNIH(1)
390399
headA.Push(unsafe.Pointer(one))
391400

392-
two := newListedVal(2)
401+
two := newListedValNIH(2)
393402
headA.Push(unsafe.Pointer(two))
394403

395-
three := newListedVal(3)
404+
three := newListedValNIH(3)
396405
headA.Push(unsafe.Pointer(three))
397406

398407
headA.Remove(unsafe.Pointer(one))

0 commit comments

Comments
 (0)