runtime: merge mallocgc, gomallocgc
I assumed they were the same when I wrote
cgocallback.go earlier today. Merge them
to eliminate confusion.
I can't tell what gomallocgc did before with
a nil type but without FlagNoScan.
I created a call like that in cgocallback.go
this morning, translating from a C file.
It was supposed to do what the C version did,
namely treat the block conservatively.
Now it will.
LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/141810043
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 8181312..ca7cb6d 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -51,12 +51,16 @@
// Allocate an object of size bytes.
// Small objects are allocated from the per-P cache's free lists.
// Large objects (> 32 kB) are allocated straight from the heap.
-func gomallocgc(size uintptr, typ *_type, flags int) unsafe.Pointer {
+func mallocgc(size uintptr, typ *_type, flags int) unsafe.Pointer {
if size == 0 {
return unsafe.Pointer(&zeroObject)
}
size0 := size
+ if flags&flagNoScan == 0 && typ == nil {
+ gothrow("malloc missing type")
+ }
+
// This function must be atomic wrt GC, but for performance reasons
// we don't acquirem/releasem on fast path. The code below does not have
// split stack checks, so it can't be preempted by GC.
@@ -338,18 +342,13 @@
return x
}
-// cmallocgc is a trampoline used to call the Go malloc from C.
-func cmallocgc(size uintptr, typ *_type, flags int, ret *unsafe.Pointer) {
- *ret = gomallocgc(size, typ, flags)
-}
-
// implementation of new builtin
func newobject(typ *_type) unsafe.Pointer {
flags := 0
if typ.kind&kindNoPointers != 0 {
flags |= flagNoScan
}
- return gomallocgc(uintptr(typ.size), typ, flags)
+ return mallocgc(uintptr(typ.size), typ, flags)
}
// implementation of make builtin for slices
@@ -361,13 +360,13 @@
if int(n) < 0 || (typ.size > 0 && n > maxMem/uintptr(typ.size)) {
panic("runtime: allocation size out of range")
}
- return gomallocgc(uintptr(typ.size)*n, typ, flags)
+ return mallocgc(uintptr(typ.size)*n, typ, flags)
}
// rawmem returns a chunk of pointerless memory. It is
// not zeroed.
func rawmem(size uintptr) unsafe.Pointer {
- return gomallocgc(size, nil, flagNoScan|flagNoZero)
+ return mallocgc(size, nil, flagNoScan|flagNoZero)
}
// round size up to next size class
@@ -725,7 +724,7 @@
// all not yet finalized objects are stored in finq.
// If we do not mark it as FlagNoScan,
// the last finalized object is not collected.
- frame = gomallocgc(framesz, nil, flagNoScan)
+ frame = mallocgc(framesz, nil, flagNoScan)
framecap = framesz
}