mirror of
https://github.com/golang/go
synced 2024-11-24 06:30:22 -07:00
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: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David du Colombier <0intro@gmail.com>
This commit is contained in:
parent
e9aef43d87
commit
c84ae1c499
@ -12,16 +12,21 @@ var bloc uintptr
|
||||
var memlock mutex
|
||||
|
||||
type memHdr struct {
|
||||
next *memHdr
|
||||
next memHdrPtr
|
||||
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 {
|
||||
n = memRound(n)
|
||||
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 prevp != nil {
|
||||
@ -47,31 +52,31 @@ func memFree(ap unsafe.Pointer, n uintptr) {
|
||||
bp := (*memHdr)(ap)
|
||||
bp.size = n
|
||||
bpn := uintptr(ap)
|
||||
if memFreelist == nil {
|
||||
bp.next = nil
|
||||
memFreelist = bp
|
||||
if memFreelist == 0 {
|
||||
bp.next = 0
|
||||
memFreelist.set(bp)
|
||||
return
|
||||
}
|
||||
p := memFreelist
|
||||
p := memFreelist.ptr()
|
||||
if bpn < uintptr(unsafe.Pointer(p)) {
|
||||
memFreelist = bp
|
||||
memFreelist.set(bp)
|
||||
if bpn+bp.size == uintptr(unsafe.Pointer(p)) {
|
||||
bp.size += p.size
|
||||
bp.next = p.next
|
||||
memclr(unsafe.Pointer(p), unsafe.Sizeof(memHdr{}))
|
||||
} else {
|
||||
bp.next = p
|
||||
bp.next.set(p)
|
||||
}
|
||||
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)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if bpn+bp.size == uintptr(unsafe.Pointer(p.next)) {
|
||||
bp.size += p.next.size
|
||||
bp.next = p.next.next
|
||||
bp.size += p.next.ptr().size
|
||||
bp.next = p.next.ptr().next
|
||||
memclr(unsafe.Pointer(p.next), unsafe.Sizeof(memHdr{}))
|
||||
} else {
|
||||
bp.next = p.next
|
||||
@ -81,7 +86,7 @@ func memFree(ap unsafe.Pointer, n uintptr) {
|
||||
p.next = bp.next
|
||||
memclr(unsafe.Pointer(bp), unsafe.Sizeof(memHdr{}))
|
||||
} else {
|
||||
p.next = bp
|
||||
p.next.set(bp)
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +94,7 @@ func memCheck() {
|
||||
if memDebug == false {
|
||||
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)) {
|
||||
print("runtime: ", unsafe.Pointer(p), " == ", unsafe.Pointer(p.next), "\n")
|
||||
throw("mem: infinite loop")
|
||||
|
Loading…
Reference in New Issue
Block a user