runtime: correct counters in sweep

In the sweep code we can sometimes see incorrect counts when
conservative stack scanning causes us to grey an object that we
earlier decided could be freed.  We already ignored this check, but
adjust this case to maintain correct span counts when it happens.
This gives us slightly more correct numbers in MemStats, and helps
avoid a rare failure in TestReadMemStats.

Also fix the free index, and cope with finding a full span when
allocating a new one.

Change-Id: I652723bd575fe32f849ab70dbce3e24908791dc7
Reviewed-on: https://go-review.googlesource.com/134216
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2 files changed