]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make faketime more robust against GC
authorIan Lance Taylor <iant@golang.org>
Wed, 17 Nov 2021 19:07:44 +0000 (11:07 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 17 Nov 2021 21:26:25 +0000 (21:26 +0000)
When using faketime, only run the scavenger for one loop.
It tries to run for 1 ms, but with faketime that calculation fails.

Prohibit write barriers in the faketime write function, in case
the GC wants to print something (e.g., with GODEBUG=gctrace=1).

Fixes #49614

Change-Id: Iab5097fe78b6e0032ea8b493088264dfb25013c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/364757
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/runtime/mgcscavenge.go
src/runtime/time_fake.go

index 286aa1bbaef05cb040c6b3f47828d78eb0c90479..0399c2d21c2b781d5e4bf4a3c20c5ea4cf9fb7cb 100644 (file)
@@ -344,6 +344,11 @@ func bgscavenge(c chan int) {
                                crit += float64(end - start)
                        }
                        released += r
+
+                       // When using fake time just do one loop.
+                       if faketime != 0 {
+                               break
+                       }
                }
 
                if released == 0 {
index 107f6be335a2df132122a994cdd0b20ac7722b06..b5e04635883d9eae46312b693002147a411bd8b5 100644 (file)
@@ -41,6 +41,10 @@ func time_now() (sec int64, nsec int32, mono int64) {
        return faketime / 1e9, int32(faketime % 1e9), faketime
 }
 
+// write is like the Unix write system call.
+// We have to avoid write barriers to avoid potential deadlock
+// on write calls.
+//go:nowritebarrierrec
 func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
        if !(fd == 1 || fd == 2) {
                // Do an ordinary write.