Commit 66e849b1 authored by Austin Clements's avatar Austin Clements

runtime: eliminate mheap.nspan and use range loops

This was necessary in the C days when allspans was an mspan**, but now
that allspans is a Go slice, this is redundant with len(allspans) and
we can use range loops over allspans.

Change-Id: Ie1dc39611e574e29a896e01690582933f4c5be7e
Reviewed-on: https://go-review.googlesource.com/30531
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRick Hudson <rlh@golang.org>
parent 4d620779
...@@ -437,9 +437,7 @@ func dumproots() { ...@@ -437,9 +437,7 @@ func dumproots() {
dumpfields(firstmoduledata.gcbssmask) dumpfields(firstmoduledata.gcbssmask)
// MSpan.types // MSpan.types
allspans := mheap_.allspans for _, s := range mheap_.allspans {
for spanidx := uint32(0); spanidx < mheap_.nspan; spanidx++ {
s := allspans[spanidx]
if s.state == _MSpanInUse { if s.state == _MSpanInUse {
// Finalizers // Finalizers
for sp := s.specials; sp != nil; sp = sp.next { for sp := s.specials; sp != nil; sp = sp.next {
...@@ -462,8 +460,7 @@ func dumproots() { ...@@ -462,8 +460,7 @@ func dumproots() {
var freemark [_PageSize / 8]bool var freemark [_PageSize / 8]bool
func dumpobjs() { func dumpobjs() {
for i := uintptr(0); i < uintptr(mheap_.nspan); i++ { for _, s := range mheap_.allspans {
s := mheap_.allspans[i]
if s.state != _MSpanInUse { if s.state != _MSpanInUse {
continue continue
} }
...@@ -608,9 +605,7 @@ func dumpmemprof_callback(b *bucket, nstk uintptr, pstk *uintptr, size, allocs, ...@@ -608,9 +605,7 @@ func dumpmemprof_callback(b *bucket, nstk uintptr, pstk *uintptr, size, allocs,
func dumpmemprof() { func dumpmemprof() {
iterate_memprof(dumpmemprof_callback) iterate_memprof(dumpmemprof_callback)
allspans := mheap_.allspans for _, s := range mheap_.allspans {
for spanidx := uint32(0); spanidx < mheap_.nspan; spanidx++ {
s := allspans[spanidx]
if s.state != _MSpanInUse { if s.state != _MSpanInUse {
continue continue
} }
...@@ -631,8 +626,7 @@ var dumphdr = []byte("go1.7 heap dump\n") ...@@ -631,8 +626,7 @@ var dumphdr = []byte("go1.7 heap dump\n")
func mdump() { func mdump() {
// make sure we're done sweeping // make sure we're done sweeping
for i := uintptr(0); i < uintptr(mheap_.nspan); i++ { for _, s := range mheap_.allspans {
s := mheap_.allspans[i]
if s.state == _MSpanInUse { if s.state == _MSpanInUse {
s.ensureSwept() s.ensureSwept()
} }
......
...@@ -48,14 +48,11 @@ type mheap struct { ...@@ -48,14 +48,11 @@ type mheap struct {
// must ensure that allocation cannot happen around the // must ensure that allocation cannot happen around the
// access (since that may free the backing store). // access (since that may free the backing store).
allspans []*mspan // all spans out there allspans []*mspan // all spans out there
nspan uint32
// span lookup // span lookup
spans **mspan spans **mspan
spans_mapped uintptr spans_mapped uintptr
_ uint32 // align uint64 fields on 32-bit for atomics
// Proportional sweep // Proportional sweep
pagesInUse uint64 // pages of spans in stats _MSpanInUse; R/W with mheap.lock pagesInUse uint64 // pages of spans in stats _MSpanInUse; R/W with mheap.lock
spanBytesAlloc uint64 // bytes of spans allocated this cycle; updated atomically spanBytesAlloc uint64 // bytes of spans allocated this cycle; updated atomically
...@@ -282,7 +279,6 @@ func recordspan(vh unsafe.Pointer, p unsafe.Pointer) { ...@@ -282,7 +279,6 @@ func recordspan(vh unsafe.Pointer, p unsafe.Pointer) {
} }
} }
h.allspans = append(h.allspans, s) h.allspans = append(h.allspans, s)
h.nspan = uint32(len(h.allspans))
} }
// inheap reports whether b is a pointer into a (potentially dead) heap object. // inheap reports whether b is a pointer into a (potentially dead) heap object.
......
...@@ -528,8 +528,7 @@ func updatememstats(stats *gcstats) { ...@@ -528,8 +528,7 @@ func updatememstats(stats *gcstats) {
// Scan all spans and count number of alive objects. // Scan all spans and count number of alive objects.
lock(&mheap_.lock) lock(&mheap_.lock)
for i := uint32(0); i < mheap_.nspan; i++ { for _, s := range mheap_.allspans {
s := mheap_.allspans[i]
if s.state != mSpanInUse { if s.state != mSpanInUse {
continue continue
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment