Commit c84ae1c4 authored by Austin Clements's avatar Austin Clements

runtime: eliminate write barriers from mem_plan9.go

This replaces *memHdr with memHdrPtr.

Updates #10600.

Change-Id: I673aa2cd20f29abec8ab91ed7e783718c8479ce1
Reviewed-on: https://go-review.googlesource.com/17009
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: default avatarDmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid du Colombier <0intro@gmail.com>
parent e9aef43d
...@@ -12,16 +12,21 @@ var bloc uintptr ...@@ -12,16 +12,21 @@ var bloc uintptr
var memlock mutex var memlock mutex
type memHdr struct { type memHdr struct {
next *memHdr next memHdrPtr
size uintptr size uintptr
} }
var memFreelist *memHdr // sorted in ascending order var memFreelist memHdrPtr // sorted in ascending order
type memHdrPtr uintptr
func (p memHdrPtr) ptr() *memHdr { return (*memHdr)(unsafe.Pointer(p)) }
func (p *memHdrPtr) set(x *memHdr) { *p = memHdrPtr(unsafe.Pointer(x)) }
func memAlloc(n uintptr) unsafe.Pointer { func memAlloc(n uintptr) unsafe.Pointer {
n = memRound(n) n = memRound(n)
var prevp *memHdr var prevp *memHdr
for p := memFreelist; p != nil; p = p.next { for p := memFreelist.ptr(); p != nil; p = p.next.ptr() {
if p.size >= n { if p.size >= n {
if p.size == n { if p.size == n {
if prevp != nil { if prevp != nil {
...@@ -47,31 +52,31 @@ func memFree(ap unsafe.Pointer, n uintptr) { ...@@ -47,31 +52,31 @@ func memFree(ap unsafe.Pointer, n uintptr) {
bp := (*memHdr)(ap) bp := (*memHdr)(ap)
bp.size = n bp.size = n
bpn := uintptr(ap) bpn := uintptr(ap)
if memFreelist == nil { if memFreelist == 0 {
bp.next = nil bp.next = 0
memFreelist = bp memFreelist.set(bp)
return return
} }
p := memFreelist p := memFreelist.ptr()
if bpn < uintptr(unsafe.Pointer(p)) { if bpn < uintptr(unsafe.Pointer(p)) {
memFreelist = bp memFreelist.set(bp)
if bpn+bp.size == uintptr(unsafe.Pointer(p)) { if bpn+bp.size == uintptr(unsafe.Pointer(p)) {
bp.size += p.size bp.size += p.size
bp.next = p.next bp.next = p.next
memclr(unsafe.Pointer(p), unsafe.Sizeof(memHdr{})) memclr(unsafe.Pointer(p), unsafe.Sizeof(memHdr{}))
} else { } else {
bp.next = p bp.next.set(p)
} }
return return
} }
for ; p.next != nil; p = p.next { for ; p.next != 0; p = p.next.ptr() {
if bpn > uintptr(unsafe.Pointer(p)) && bpn < uintptr(unsafe.Pointer(p.next)) { if bpn > uintptr(unsafe.Pointer(p)) && bpn < uintptr(unsafe.Pointer(p.next)) {
break break
} }
} }
if bpn+bp.size == uintptr(unsafe.Pointer(p.next)) { if bpn+bp.size == uintptr(unsafe.Pointer(p.next)) {
bp.size += p.next.size bp.size += p.next.ptr().size
bp.next = p.next.next bp.next = p.next.ptr().next
memclr(unsafe.Pointer(p.next), unsafe.Sizeof(memHdr{})) memclr(unsafe.Pointer(p.next), unsafe.Sizeof(memHdr{}))
} else { } else {
bp.next = p.next bp.next = p.next
...@@ -81,7 +86,7 @@ func memFree(ap unsafe.Pointer, n uintptr) { ...@@ -81,7 +86,7 @@ func memFree(ap unsafe.Pointer, n uintptr) {
p.next = bp.next p.next = bp.next
memclr(unsafe.Pointer(bp), unsafe.Sizeof(memHdr{})) memclr(unsafe.Pointer(bp), unsafe.Sizeof(memHdr{}))
} else { } else {
p.next = bp p.next.set(bp)
} }
} }
...@@ -89,7 +94,7 @@ func memCheck() { ...@@ -89,7 +94,7 @@ func memCheck() {
if memDebug == false { if memDebug == false {
return return
} }
for p := memFreelist; p != nil && p.next != nil; p = p.next { for p := memFreelist.ptr(); p != nil && p.next != 0; p = p.next.ptr() {
if uintptr(unsafe.Pointer(p)) == uintptr(unsafe.Pointer(p.next)) { if uintptr(unsafe.Pointer(p)) == uintptr(unsafe.Pointer(p.next)) {
print("runtime: ", unsafe.Pointer(p), " == ", unsafe.Pointer(p.next), "\n") print("runtime: ", unsafe.Pointer(p), " == ", unsafe.Pointer(p.next), "\n")
throw("mem: infinite loop") throw("mem: infinite loop")
......
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