]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make mcache.tiny a uintptr
authorAustin Clements <austin@google.com>
Mon, 16 Nov 2015 20:31:50 +0000 (15:31 -0500)
committerAustin Clements <austin@google.com>
Mon, 16 Nov 2015 22:07:41 +0000 (22:07 +0000)
mcache.tiny is in non-GC'd memory, but points to heap memory. As a
result, there may or may not be write barriers when writing to
mcache.tiny. Make it clearer that funny things are going on by making
mcache.tiny a uintptr instead of an unsafe.Pointer.

Change-Id: I732a5b7ea17162f196a9155154bbaff8d4d00eac
Reviewed-on: https://go-review.googlesource.com/16963
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/malloc.go
src/runtime/mcache.go

index d9f52399b8f2165795939ce231e9d7262fbf9355..ad1123be96c39e241cd737899c9889220d082306 100644 (file)
@@ -589,9 +589,9 @@ func mallocgc(size uintptr, typ *_type, flags uint32) unsafe.Pointer {
                        } else if size&1 == 0 {
                                off = round(off, 2)
                        }
-                       if off+size <= maxTinySize && c.tiny != nil {
+                       if off+size <= maxTinySize && c.tiny != 0 {
                                // The object fits into existing tiny block.
-                               x = add(c.tiny, off)
+                               x = unsafe.Pointer(c.tiny + off)
                                c.tinyoffset = off + size
                                c.local_tinyallocs++
                                mp.mallocing = 0
@@ -618,8 +618,8 @@ func mallocgc(size uintptr, typ *_type, flags uint32) unsafe.Pointer {
                        (*[2]uint64)(x)[1] = 0
                        // See if we need to replace the existing tiny block with the new one
                        // based on amount of remaining free space.
-                       if size < c.tinyoffset || c.tiny == nil {
-                               c.tiny = x
+                       if size < c.tinyoffset || c.tiny == 0 {
+                               c.tiny = uintptr(x)
                                c.tinyoffset = size
                        }
                        size = maxTinySize
index c80c5b095ac6648e6409db0bdb2af0cab92d1064..c843fb2096dbea1638b9c74dc488342b9772a35d 100644 (file)
@@ -27,7 +27,7 @@ type mcache struct {
        // tiny is a heap pointer. Since mcache is in non-GC'd memory,
        // we handle it by clearing it in releaseAll during mark
        // termination.
-       tiny             unsafe.Pointer
+       tiny             uintptr
        tinyoffset       uintptr
        local_tinyallocs uintptr // number of tiny allocs not counted in other stats
 
@@ -139,6 +139,6 @@ func (c *mcache) releaseAll() {
                }
        }
        // Clear tinyalloc pool.
-       c.tiny = nil
+       c.tiny = 0
        c.tinyoffset = 0
 }