aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2023-05-31 14:45:30 -0400
committerGopher Robot <gobot@golang.org>2023-06-01 14:05:01 +0000
commit7911f7c21d4bba89eee0eab857d089b7ed6232d4 (patch)
treedfe2403ede32d9e1abf2211a2fca32f33aa4cfc2 /src/runtime/testdata
parent65dcddeb4e80b9a23ec6fc0157ecab388ba2f34f (diff)
downloadgo-7911f7c21d4bba89eee0eab857d089b7ed6232d4.tar.xz
runtime: only increment extraMInUse when actually in use
Currently lockextra always increments extraMInUse, even if the M won't be used (or doesn't even exist), such as in addExtraM. addExtraM fails to decrement extraMInUse, so it stays elevated forever. Fix this bug and simplify the model by moving extraMInUse out of lockextra to getExtraM, where we know the M will actually be used. While we're here, remove the nilokay argument from getExtraM, which is always false. Fixes #60540. Change-Id: I7a5d97456b3bc6ea1baeb06b5b2975e3b8dd96a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/499677 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/testdata')
-rw-r--r--src/runtime/testdata/testprogcgo/callback.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/runtime/testdata/testprogcgo/callback.go b/src/runtime/testdata/testprogcgo/callback.go
index 25f07159b8..319572fe10 100644
--- a/src/runtime/testdata/testprogcgo/callback.go
+++ b/src/runtime/testdata/testprogcgo/callback.go
@@ -32,6 +32,8 @@ import (
"fmt"
"os"
"runtime"
+ "sync/atomic"
+ _ "unsafe" // for go:linkname
)
func init() {
@@ -40,6 +42,11 @@ func init() {
//export go_callback
func go_callback() {
+ if e := extraMInUse.Load(); e == 0 {
+ fmt.Printf("in callback extraMInUse got %d want >0\n", e)
+ os.Exit(1)
+ }
+
runtime.GC()
grow()
runtime.GC()
@@ -69,6 +76,12 @@ func CgoCallbackGC() {
if os.Getenv("RUNTIME_TEST_SHORT") != "" {
P = 10
}
+
+ if e := extraMInUse.Load(); e != 0 {
+ fmt.Printf("before testing extraMInUse got %d want 0\n", e)
+ os.Exit(1)
+ }
+
done := make(chan bool)
// allocate a bunch of stack frames and spray them with pointers
for i := 0; i < P; i++ {
@@ -90,5 +103,14 @@ func CgoCallbackGC() {
for i := 0; i < P; i++ {
<-done
}
+
+ if e := extraMInUse.Load(); e != 0 {
+ fmt.Printf("after testing extraMInUse got %d want 0\n", e)
+ os.Exit(1)
+ }
+
fmt.Printf("OK\n")
}
+
+//go:linkname extraMInUse runtime.extraMInUse
+var extraMInUse atomic.Uint32