]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: eliminate mheap.nspan and use range loops
authorAustin Clements <austin@google.com>
Tue, 4 Oct 2016 19:56:19 +0000 (15:56 -0400)
committerAustin Clements <austin@google.com>
Tue, 25 Oct 2016 22:32:45 +0000 (22:32 +0000)
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: Rick Hudson <rlh@golang.org>
src/runtime/heapdump.go
src/runtime/mheap.go
src/runtime/mstats.go

index 3ad83532cf63f76fd8a48ed6eabd5d9b9ad48067..8cdccb877a71ac32ebcfaa462c537b2a7775b508 100644 (file)
@@ -437,9 +437,7 @@ func dumproots() {
        dumpfields(firstmoduledata.gcbssmask)
 
        // MSpan.types
-       allspans := mheap_.allspans
-       for spanidx := uint32(0); spanidx < mheap_.nspan; spanidx++ {
-               s := allspans[spanidx]
+       for _, s := range mheap_.allspans {
                if s.state == _MSpanInUse {
                        // Finalizers
                        for sp := s.specials; sp != nil; sp = sp.next {
@@ -462,8 +460,7 @@ func dumproots() {
 var freemark [_PageSize / 8]bool
 
 func dumpobjs() {
-       for i := uintptr(0); i < uintptr(mheap_.nspan); i++ {
-               s := mheap_.allspans[i]
+       for _, s := range mheap_.allspans {
                if s.state != _MSpanInUse {
                        continue
                }
@@ -608,9 +605,7 @@ func dumpmemprof_callback(b *bucket, nstk uintptr, pstk *uintptr, size, allocs,
 
 func dumpmemprof() {
        iterate_memprof(dumpmemprof_callback)
-       allspans := mheap_.allspans
-       for spanidx := uint32(0); spanidx < mheap_.nspan; spanidx++ {
-               s := allspans[spanidx]
+       for _, s := range mheap_.allspans {
                if s.state != _MSpanInUse {
                        continue
                }
@@ -631,8 +626,7 @@ var dumphdr = []byte("go1.7 heap dump\n")
 
 func mdump() {
        // make sure we're done sweeping
-       for i := uintptr(0); i < uintptr(mheap_.nspan); i++ {
-               s := mheap_.allspans[i]
+       for _, s := range mheap_.allspans {
                if s.state == _MSpanInUse {
                        s.ensureSwept()
                }
index 9d02343dbea9b78aeb8409ceecf9124352072476..f6ad4a170e8a04547f8c07766c21ac90024122db 100644 (file)
@@ -48,14 +48,11 @@ type mheap struct {
        // must ensure that allocation cannot happen around the
        // access (since that may free the backing store).
        allspans []*mspan // all spans out there
-       nspan    uint32
 
        // span lookup
        spans        **mspan
        spans_mapped uintptr
 
-       _ uint32 // align uint64 fields on 32-bit for atomics
-
        // Proportional sweep
        pagesInUse        uint64  // pages of spans in stats _MSpanInUse; R/W with mheap.lock
        spanBytesAlloc    uint64  // bytes of spans allocated this cycle; updated atomically
@@ -282,7 +279,6 @@ func recordspan(vh unsafe.Pointer, p unsafe.Pointer) {
                }
        }
        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.
index 38ae45bd1df38bfbf60cc5c11eca738a9488fb2d..f921f02f5a8986d8706ce25c3b161e9276b9c0fa 100644 (file)
@@ -528,8 +528,7 @@ func updatememstats(stats *gcstats) {
 
        // Scan all spans and count number of alive objects.
        lock(&mheap_.lock)
-       for i := uint32(0); i < mheap_.nspan; i++ {
-               s := mheap_.allspans[i]
+       for _, s := range mheap_.allspans {
                if s.state != mSpanInUse {
                        continue
                }