]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.garbage] runtime: replace ref with allocCount
authorRick Hudson <rlh@golang.org>
Tue, 16 Feb 2016 22:16:43 +0000 (17:16 -0500)
committerRick Hudson <rlh@golang.org>
Wed, 27 Apr 2016 21:54:49 +0000 (21:54 +0000)
This is a renaming of the field ref to the
more appropriate allocCount. The field
holds the number of objects in the span
that are currently allocated. Some throws
strings were adjusted to more accurately
convey the meaning of allocCount.

Change-Id: I10daf44e3e9cc24a10912638c7de3c1984ef8efe
Reviewed-on: https://go-review.googlesource.com/19518
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/malloc.go
src/runtime/mcache.go
src/runtime/mcentral.go
src/runtime/mheap.go
src/runtime/mstats.go
src/runtime/stack.go

index e635682caec5ec017a62cac571f45b23479adb8a..6db323a8d31a6a5160999265e09aca74c0e9e1cb 100644 (file)
@@ -509,8 +509,8 @@ func (c *mcache) nextFree(sizeclass int8) (v gclinkptr, shouldhelpgc bool) {
 
        if freeIndex == s.nelems {
                // The span is full.
-               if uintptr(s.ref) != s.nelems {
-                       throw("s.ref != s.nelems && freeIndex == s.nelems")
+               if uintptr(s.allocCount) != s.nelems {
+                       throw("s.allocCount != s.nelems && freeIndex == s.nelems")
                }
                systemstack(func() {
                        c.refill(int32(sizeclass))
@@ -526,9 +526,9 @@ func (c *mcache) nextFree(sizeclass int8) (v gclinkptr, shouldhelpgc bool) {
        v = gclinkptr(freeIndex*s.elemsize + s.base())
        // Advance the freeIndex.
        s.freeindex = freeIndex + 1
-       s.ref++
-       if uintptr(s.ref) > s.nelems {
-               throw("s.ref > s.nelems")
+       s.allocCount++
+       if uintptr(s.allocCount) > s.nelems {
+               throw("s.allocCount > s.nelems")
        }
        return
 }
index 424fa0efac7d5510322553206c9679cace2f26d1..5938e53ca8ced0115c45d0b67367ac14613cca17 100644 (file)
@@ -109,7 +109,7 @@ func (c *mcache) refill(sizeclass int32) *mspan {
        // Return the current cached span to the central lists.
        s := c.alloc[sizeclass]
 
-       if uintptr(s.ref) != s.nelems {
+       if uintptr(s.allocCount) != s.nelems {
                throw("refill of span with free space remaining")
        }
 
@@ -123,7 +123,7 @@ func (c *mcache) refill(sizeclass int32) *mspan {
                throw("out of memory")
        }
 
-       if uintptr(s.ref) == s.nelems {
+       if uintptr(s.allocCount) == s.nelems {
                throw("span has no free space")
        }
 
index 47d3ae2f81deac32f12e034f2b2a69a8de69efc9..5dafa28450e4a2f4bf08e6dd81e583103b2abbcb 100644 (file)
@@ -100,11 +100,11 @@ retry:
        // c is unlocked.
 havespan:
        cap := int32((s.npages << _PageShift) / s.elemsize)
-       n := cap - int32(s.ref)
+       n := cap - int32(s.allocCount)
        if n == 0 {
-               throw("empty span")
+               throw("span has no free objects")
        }
-       usedBytes := uintptr(s.ref) * s.elemsize
+       usedBytes := uintptr(s.allocCount) * s.elemsize
        if usedBytes > 0 {
                reimburseSweepCredit(usedBytes)
        }
@@ -127,12 +127,12 @@ func (c *mcentral) uncacheSpan(s *mspan) {
 
        s.incache = false
 
-       if s.ref == 0 {
-               throw("uncaching full span")
+       if s.allocCount == 0 {
+               throw("uncaching span but s.allocCount == 0")
        }
 
        cap := int32((s.npages << _PageShift) / s.elemsize)
-       n := cap - int32(s.ref)
+       n := cap - int32(s.allocCount)
        if n > 0 {
                c.empty.remove(s)
                c.nonempty.insert(s)
@@ -154,7 +154,7 @@ func (c *mcentral) freeSpan(s *mspan, n int32, start gclinkptr, end gclinkptr, p
                throw("freeSpan given cached span")
        }
 
-       s.ref -= uint16(n)
+       s.allocCount -= uint16(n)
 
        if preserve {
                // preserve is set only when called from MCentral_CacheSpan above,
@@ -180,7 +180,7 @@ func (c *mcentral) freeSpan(s *mspan, n int32, start gclinkptr, end gclinkptr, p
        // lock of c above.)
        atomic.Store(&s.sweepgen, mheap_.sweepgen)
 
-       if s.ref != 0 {
+       if s.allocCount != 0 {
                unlock(&c.lock)
                return false
        }
index d5dde5e72e1e3dba43dd3cd2f7c8e863b6d8944b..cd35acb6dd01455022da7b2a0cf4daa8464e9b30 100644 (file)
@@ -159,7 +159,7 @@ type mspan struct {
 
        sweepgen    uint32
        divMul      uint32   // for divide by elemsize - divMagic.mul
-       ref         uint16   // capacity - number of objects in freelist
+       allocCount  uint16   // capacity - number of objects in freelist
        sizeclass   uint8    // size class
        incache     bool     // being used by an mcache
        state       uint8    // mspaninuse etc
@@ -471,7 +471,7 @@ func (h *mheap) alloc_m(npage uintptr, sizeclass int32, large bool) *mspan {
                // able to map interior pointer to containing span.
                atomic.Store(&s.sweepgen, h.sweepgen)
                s.state = _MSpanInUse
-               s.ref = 0
+               s.allocCount = 0
                s.sizeclass = uint8(sizeclass)
                if sizeclass == 0 {
                        s.elemsize = s.npages << _PageShift
@@ -551,7 +551,7 @@ func (h *mheap) allocStack(npage uintptr) *mspan {
        if s != nil {
                s.state = _MSpanStack
                s.stackfreelist = 0
-               s.ref = 0
+               s.allocCount = 0
                memstats.stacks_inuse += uint64(s.npages << _PageShift)
        }
 
@@ -773,12 +773,12 @@ func (h *mheap) freeStack(s *mspan) {
 func (h *mheap) freeSpanLocked(s *mspan, acctinuse, acctidle bool, unusedsince int64) {
        switch s.state {
        case _MSpanStack:
-               if s.ref != 0 {
+               if s.allocCount != 0 {
                        throw("MHeap_FreeSpanLocked - invalid stack free")
                }
        case _MSpanInUse:
-               if s.ref != 0 || s.sweepgen != h.sweepgen {
-                       print("MHeap_FreeSpanLocked - span ", s, " ptr ", hex(s.start<<_PageShift), " ref ", s.ref, " sweepgen ", s.sweepgen, "/", h.sweepgen, "\n")
+               if s.allocCount != 0 || s.sweepgen != h.sweepgen {
+                       print("MHeap_FreeSpanLocked - span ", s, " ptr ", hex(s.start<<_PageShift), " allocCount ", s.allocCount, " sweepgen ", s.sweepgen, "/", h.sweepgen, "\n")
                        throw("MHeap_FreeSpanLocked - invalid free")
                }
                h.pagesInUse -= uint64(s.npages)
@@ -912,7 +912,7 @@ func (span *mspan) init(start pageID, npages uintptr) {
        span.list = nil
        span.start = start
        span.npages = npages
-       span.ref = 0
+       span.allocCount = 0
        span.sizeclass = 0
        span.incache = false
        span.elemsize = 0
index 84a79e312cbc943bc2c62c5b09ab48a4fcbecad3..2d75d2fef120e039d9964367e2b7efadb011fd29 100644 (file)
@@ -295,9 +295,9 @@ func updatememstats(stats *gcstats) {
                        memstats.nmalloc++
                        memstats.alloc += uint64(s.elemsize)
                } else {
-                       memstats.nmalloc += uint64(s.ref)
-                       memstats.by_size[s.sizeclass].nmalloc += uint64(s.ref)
-                       memstats.alloc += uint64(s.ref) * uint64(s.elemsize)
+                       memstats.nmalloc += uint64(s.allocCount)
+                       memstats.by_size[s.sizeclass].nmalloc += uint64(s.allocCount)
+                       memstats.alloc += uint64(s.allocCount) * uint64(s.elemsize)
                }
        }
        unlock(&mheap_.lock)
index 8fd7ef2bcf62422fe21599666d46e3711e2429c7..1ca737e920c04e46ca52498c8b5b74e28ba4e4b0 100644 (file)
@@ -191,8 +191,8 @@ func stackpoolalloc(order uint8) gclinkptr {
                if s == nil {
                        throw("out of memory")
                }
-               if s.ref != 0 {
-                       throw("bad ref")
+               if s.allocCount != 0 {
+                       throw("bad allocCount")
                }
                if s.stackfreelist.ptr() != nil {
                        throw("bad stackfreelist")
@@ -209,7 +209,7 @@ func stackpoolalloc(order uint8) gclinkptr {
                throw("span has no free stacks")
        }
        s.stackfreelist = x.ptr().next
-       s.ref++
+       s.allocCount++
        if s.stackfreelist.ptr() == nil {
                // all stacks in s are allocated.
                list.remove(s)
@@ -229,8 +229,8 @@ func stackpoolfree(x gclinkptr, order uint8) {
        }
        x.ptr().next = s.stackfreelist
        s.stackfreelist = x
-       s.ref--
-       if gcphase == _GCoff && s.ref == 0 {
+       s.allocCount--
+       if gcphase == _GCoff && s.allocCount == 0 {
                // Span is completely free. Return it to the heap
                // immediately if we're sweeping.
                //
@@ -1135,7 +1135,7 @@ func freeStackSpans() {
                list := &stackpool[order]
                for s := list.first; s != nil; {
                        next := s.next
-                       if s.ref == 0 {
+                       if s.allocCount == 0 {
                                list.remove(s)
                                s.stackfreelist = 0
                                mheap_.freeStack(s)