1
0
mirror of https://github.com/golang/go synced 2024-11-16 19:04:39 -07:00

runtime: make faketime more robust against GC

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>
This commit is contained in:
Ian Lance Taylor 2021-11-17 11:07:44 -08:00
parent a218365fae
commit 0440fb8334
2 changed files with 9 additions and 0 deletions

View 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 {

View 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.