]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use mcache0 if no P in profilealloc
authorIan Lance Taylor <iant@golang.org>
Wed, 15 Apr 2020 22:39:53 +0000 (15:39 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 17 Apr 2020 00:45:52 +0000 (00:45 +0000)
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>
src/runtime/malloc.go
src/runtime/proc_test.go

index 5a0d85f6454bbac06020d03574a4311b742a15d6..e1ec5e6496b9f87f2766c2fc42fd8ae2863c39ae 100644 (file)
@@ -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)
 }
 
index 81bcb98aeb45ad0e5021a8a469497c5a12748627..27dba95effb8f92adefddafa0abfc933f6ed5c26 100644 (file)
@@ -1037,3 +1037,16 @@ loop:
                t.Errorf("netpollBreak did not interrupt netpoll: slept for: %v", dur)
        }
 }
+
+// TestBigGOMAXPROCS tests that setting GOMAXPROCS to a large value
+// doesn't cause a crash at startup. See issue 38474.
+func TestBigGOMAXPROCS(t *testing.T) {
+       t.Parallel()
+       output := runTestProg(t, "testprog", "NonexistentTest", "GOMAXPROCS=1024")
+       if strings.Contains(output, "failed to create new OS thread") {
+               t.Skipf("failed to create 1024 threads")
+       }
+       if !strings.Contains(output, "unknown function: NonexistentTest") {
+               t.Errorf("output:\n%s\nwanted:\nunknown function: NonexistentTest", output)
+       }
+}