Commit fbd2660a authored by Austin Clements's avatar Austin Clements

runtime: introduce gcMode type for GC modes

Currently, the GC modes constants are untyped and functions pass them
around as ints. Clean this up by introducing a proper type for these
constant.

Change-Id: Ibc022447bdfa203644921fbb548312d7e2272e8d
Reviewed-on: https://go-review.googlesource.com/14981Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 1b84bb8c
...@@ -803,10 +803,13 @@ func GC() { ...@@ -803,10 +803,13 @@ func GC() {
startGC(gcForceBlockMode, false) startGC(gcForceBlockMode, false)
} }
// gcMode indicates how concurrent a GC cycle should be.
type gcMode int
const ( const (
gcBackgroundMode = iota // concurrent GC gcBackgroundMode gcMode = iota // concurrent GC and sweep
gcForceMode // stop-the-world GC now gcForceMode // stop-the-world GC now, concurrent sweep
gcForceBlockMode // stop-the-world GC now and wait for sweep gcForceBlockMode // stop-the-world GC now and STW sweep
) )
// startGC starts a GC cycle. If mode is gcBackgroundMode, this will // startGC starts a GC cycle. If mode is gcBackgroundMode, this will
...@@ -814,7 +817,7 @@ const ( ...@@ -814,7 +817,7 @@ const (
// until the new GC cycle is started and finishes. If forceTrigger is // until the new GC cycle is started and finishes. If forceTrigger is
// true, it indicates that GC should be started regardless of the // true, it indicates that GC should be started regardless of the
// current heap size. // current heap size.
func startGC(mode int, forceTrigger bool) { func startGC(mode gcMode, forceTrigger bool) {
// The gc is turned off (via enablegc) until the bootstrap has completed. // The gc is turned off (via enablegc) until the bootstrap has completed.
// Also, malloc gets called in the guts of a number of libraries that might be // Also, malloc gets called in the guts of a number of libraries that might be
// holding locks. To avoid deadlocks during stop-the-world, don't bother // holding locks. To avoid deadlocks during stop-the-world, don't bother
...@@ -889,7 +892,7 @@ func backgroundgc() { ...@@ -889,7 +892,7 @@ func backgroundgc() {
} }
} }
func gc(mode int) { func gc(mode gcMode) {
// Timing/utilization tracking // Timing/utilization tracking
var stwprocs, maxprocs int32 var stwprocs, maxprocs int32
var tSweepTerm, tScan, tInstallWB, tMark, tMarkTerm int64 var tSweepTerm, tScan, tInstallWB, tMark, tMarkTerm int64
...@@ -1513,7 +1516,7 @@ func gcMark(start_time int64) { ...@@ -1513,7 +1516,7 @@ func gcMark(start_time int64) {
} }
} }
func gcSweep(mode int) { func gcSweep(mode gcMode) {
if gcphase != _GCoff { if gcphase != _GCoff {
throw("gcSweep being done but phase is not GCoff") throw("gcSweep being done but phase is not GCoff")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment