]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: improve mheap.alloc doc and let compiler check system stack
authorAustin Clements <austin@google.com>
Fri, 30 Jun 2017 16:10:01 +0000 (12:10 -0400)
committerAustin Clements <austin@google.com>
Fri, 5 Oct 2018 16:05:17 +0000 (16:05 +0000)
The alloc_m documentation refers to concepts that don't exist (and
maybe never did?). alloc_m is also not the API entry point to span
allocation.

Hence, rewrite the documentation for alloc and alloc_m. While we're
here, document why alloc_m must run on the system stack and replace
alloc_m's hand-implemented system stack check with a go:systemstack
annotation.

Change-Id: I30e263d8e53c2774a6614e1b44df5464838cef09
Reviewed-on: https://go-review.googlesource.com/c/139459
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/mheap.go

index 7a11bdc0588d9f1d4d3f75257bebc56b7817b437..b92e27e4e05e6e6295f89d9d5507e631ad423367 100644 (file)
@@ -657,13 +657,14 @@ func (h *mheap) reclaim(npage uintptr) {
        lock(&h.lock)
 }
 
-// Allocate a new span of npage pages from the heap for GC'd memory
-// and record its size class in the HeapMap and HeapMapCache.
+// alloc_m is the internal implementation of mheap.alloc.
+//
+// alloc_m must run on the system stack because it locks the heap, so
+// any stack growth during alloc_m would self-deadlock.
+//
+//go:systemstack
 func (h *mheap) alloc_m(npage uintptr, spanclass spanClass, large bool) *mspan {
        _g_ := getg()
-       if _g_ != _g_.m.g0 {
-               throw("_mheap_alloc not on g0 stack")
-       }
        lock(&h.lock)
 
        // To prevent excessive heap growth, before allocating n pages
@@ -752,6 +753,12 @@ func (h *mheap) alloc_m(npage uintptr, spanclass spanClass, large bool) *mspan {
        return s
 }
 
+// alloc allocates a new span of npage pages from the GC'd heap.
+//
+// Either large must be true or spanclass must indicates the span's
+// size class and scannability.
+//
+// If needzero is true, the memory for the returned span will be zeroed.
 func (h *mheap) alloc(npage uintptr, spanclass spanClass, large bool, needzero bool) *mspan {
        // Don't do any operations that lock the heap on the G stack.
        // It might trigger stack growth, and the stack growth code needs