diff options
author | Austin Clements <austin@google.com> | 2017-09-25 14:58:13 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2017-09-26 21:55:05 +0000 |
commit | 0744c21b98e916470c97ff5816630398cf3213c8 (patch) | |
tree | daad80ad7ed26808c44948209300828a0ad9ab55 /src/runtime/gc_test.go | |
parent | 382d4928b8a758a91f06de9e6cb10b92bb882eff (diff) | |
download | go-0744c21b98e916470c97ff5816630398cf3213c8.tar.gz go-0744c21b98e916470c97ff5816630398cf3213c8.zip |
runtime: make runtime.GC() trigger GC even if GOGC=off
Currently, the priority of checks in (gcTrigger).test() puts the
gcpercent<0 test above gcTriggerCycle, which is used for runtime.GC().
This is an unintentional change from 1.8 and before, where
runtime.GC() triggered a GC even if GOGC=off.
Fix this by rearranging the priority so the gcTriggerCycle test
executes even if gcpercent < 0.
Fixes #22023.
Change-Id: I109328d7b643b6824eb9d79061a9e775f0149575
Reviewed-on: https://go-review.googlesource.com/65994
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/gc_test.go')
-rw-r--r-- | src/runtime/gc_test.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/runtime/gc_test.go b/src/runtime/gc_test.go index 03acc8aaa6..ece5641e1f 100644 --- a/src/runtime/gc_test.go +++ b/src/runtime/gc_test.go @@ -499,3 +499,19 @@ func BenchmarkReadMemStats(b *testing.B) { hugeSink = nil } + +func TestUserForcedGC(t *testing.T) { + // Test that runtime.GC() triggers a GC even if GOGC=off. + defer debug.SetGCPercent(debug.SetGCPercent(-1)) + + var ms1, ms2 runtime.MemStats + runtime.ReadMemStats(&ms1) + runtime.GC() + runtime.ReadMemStats(&ms2) + if ms1.NumGC == ms2.NumGC { + t.Fatalf("runtime.GC() did not trigger GC") + } + if ms1.NumForcedGC == ms2.NumForcedGC { + t.Fatalf("runtime.GC() was not accounted in NumForcedGC") + } +} |