From f4dcc9b29b052b99b97d0e445cda589f08bfc798 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 18 Oct 2016 17:29:37 -0400 Subject: [PATCH] runtime: make _MSpanDead be the zero state Currently the zero value of an mspan is in the "in use" state. This seems like a bad idea in general. But it's going to wreak havoc when we make fixalloc zero allocations: even "freed" mspan objects are still on the allspans list and still get looked at by the garbage collector. Hence, if we leave the mspan states the way they are, allocating a span that reuses old memory will temporarily pass that span (which is visible to GC!) through the "in use" state, which can cause "unswept span" panics. Fix all of this by making the zero state "dead". Updates #17503. Change-Id: I77c7ac06e297af4b9e6258bc091c37abe102acc3 Reviewed-on: https://go-review.googlesource.com/31367 Reviewed-by: Keith Randall Reviewed-by: Rick Hudson --- src/runtime/mheap.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 9c691c6887..d17363261e 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -141,19 +141,19 @@ var mheap_ mheap type mSpanState uint8 const ( - _MSpanInUse mSpanState = iota // allocated for garbage collected heap - _MSpanStack // allocated for use by stack allocator + _MSpanDead mSpanState = iota + _MSpanInUse // allocated for garbage collected heap + _MSpanStack // allocated for use by stack allocator _MSpanFree - _MSpanDead ) // mSpanStateNames are the names of the span states, indexed by // mSpanState. var mSpanStateNames = []string{ + "_MSpanDead", "_MSpanInUse", "_MSpanStack", "_MSpanFree", - "_MSpanDead", } // mSpanList heads a linked list of spans. -- 2.48.1