runtime: rewrite malloc in Go.
This change introduces gomallocgc, a Go clone of mallocgc.
Only a few uses have been moved over, so there are still
lots of uses from C. Many of these C uses will be moved
over to Go (e.g. in slice.goc), but probably not all.
What should remain of C's mallocgc is an open question.
LGTM=rsc, dvyukov
R=rsc, khr, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/108840046
diff --git a/src/pkg/runtime/hashmap.go b/src/pkg/runtime/hashmap.go
index 68ad37c..d181f9c 100644
--- a/src/pkg/runtime/hashmap.go
+++ b/src/pkg/runtime/hashmap.go
@@ -221,14 +221,14 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- buckets = unsafe_NewArray(t.bucket, uintptr(1)<<B)
+ buckets = newarray(t.bucket, uintptr(1)<<B)
}
// initialize Hmap
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- h := (*hmap)(unsafe_New(t.hmap))
+ h := (*hmap)(newobject(t.hmap))
h.count = 0
h.B = B
h.flags = flags
@@ -405,7 +405,7 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- h.buckets = unsafe_NewArray(t.bucket, 1)
+ h.buckets = newarray(t.bucket, 1)
}
again:
@@ -467,7 +467,7 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- newb := (*bmap)(unsafe_New(t.bucket))
+ newb := (*bmap)(newobject(t.bucket))
b.overflow = newb
inserti = &newb.tophash[0]
insertk = add(unsafe.Pointer(newb), dataOffset)
@@ -479,7 +479,7 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- kmem := unsafe_New(t.key)
+ kmem := newobject(t.key)
*(*unsafe.Pointer)(insertk) = kmem
insertk = kmem
}
@@ -487,7 +487,7 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- vmem := unsafe_New(t.elem)
+ vmem := newobject(t.elem)
*(*unsafe.Pointer)(insertv) = vmem
insertv = vmem
}
@@ -742,7 +742,7 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- newbuckets := unsafe_NewArray(t.bucket, uintptr(1)<<(h.B+1))
+ newbuckets := newarray(t.bucket, uintptr(1)<<(h.B+1))
flags := h.flags &^ (iterator | oldIterator)
if h.flags&iterator != 0 {
flags |= oldIterator
@@ -835,7 +835,7 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- newx := (*bmap)(unsafe_New(t.bucket))
+ newx := (*bmap)(newobject(t.bucket))
x.overflow = newx
x = newx
xi = 0
@@ -862,7 +862,7 @@
if checkgc {
memstats.next_gc = memstats.heap_alloc
}
- newy := (*bmap)(unsafe_New(t.bucket))
+ newy := (*bmap)(newobject(t.bucket))
y.overflow = newy
y = newy
yi = 0