diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-04-15 15:39:53 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-04-17 00:45:52 +0000 |
commit | 7ea40f6594ada6631b3fd153c87916c51628a7e2 (patch) | |
tree | 2bd5c3a360ed372d90504cfb38d37d806c629fa4 /src/runtime/malloc.go | |
parent | 415da71c5d2b02beab9067af4c2ff435de15bb9b (diff) | |
download | go-7ea40f6594ada6631b3fd153c87916c51628a7e2.tar.gz go-7ea40f6594ada6631b3fd153c87916c51628a7e2.zip |
runtime: use mcache0 if no P in profilealloc
A case that I missed in CL 205239: profilealloc can be called at
program startup if GOMAXPROCS is large enough.
Fixes #38474
Change-Id: I2f089fc6ec00c376680e1c0b8a2557b62789dd7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/228420
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r-- | src/runtime/malloc.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 5a0d85f645..e1ec5e6496 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -1207,7 +1207,16 @@ func reflect_unsafe_NewArray(typ *_type, n int) unsafe.Pointer { } func profilealloc(mp *m, x unsafe.Pointer, size uintptr) { - mp.p.ptr().mcache.next_sample = nextSample() + var c *mcache + if mp.p != 0 { + c = mp.p.ptr().mcache + } else { + c = mcache0 + if c == nil { + throw("profilealloc called with no P") + } + } + c.next_sample = nextSample() mProf_Malloc(x, size) } |