Skip to content

Commit f5e67e5

Browse files
committed
runtime: allow GC drain whenever write barrier is enabled
Currently we hand-code a set of phases when draining is allowed. However, this set of phases is conservative. The critical invariant is simply that the write barrier must be enabled if we're draining. Shortly we're going to enable mutator assists during the scan phase, which means we may drain during the scan phase. In preparation, this commit generalizes these assertions to check the fundamental condition that the write barrier is enabled, rather than checking that we're in any particular phase. Change-Id: I0e1bec1ca823d4a697a0831ec4c50f5dd3f2a893 Reviewed-on: https://go-review.googlesource.com/12673 Reviewed-by: Russ Cox <[email protected]>
1 parent 64a32ff commit f5e67e5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/runtime/mgcmark.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ func setNextBarrierPC(pc uintptr) {
644644
// credit exceeds flushScanCredit.
645645
//go:nowritebarrier
646646
func gcDrain(gcw *gcWork, flushScanCredit int64) {
647-
if gcphase != _GCmark && gcphase != _GCmarktermination {
648-
throw("scanblock phase incorrect")
647+
if !writeBarrierEnabled {
648+
throw("gcDrain phase incorrect")
649649
}
650650

651651
var lastScanFlush, nextScanFlush int64
@@ -696,7 +696,7 @@ func gcDrain(gcw *gcWork, flushScanCredit int64) {
696696
// get work, even though there may be more work in the system.
697697
//go:nowritebarrier
698698
func gcDrainUntilPreempt(gcw *gcWork, flushScanCredit int64) {
699-
if gcphase != _GCmark {
699+
if !writeBarrierEnabled {
700700
println("gcphase =", gcphase)
701701
throw("gcDrainUntilPreempt phase incorrect")
702702
}
@@ -750,6 +750,9 @@ func gcDrainUntilPreempt(gcw *gcWork, flushScanCredit int64) {
750750
// scanning is always done in whole object increments.
751751
//go:nowritebarrier
752752
func gcDrainN(gcw *gcWork, scanWork int64) {
753+
if !writeBarrierEnabled {
754+
throw("gcDrainN phase incorrect")
755+
}
753756
targetScanWork := gcw.scanWork + scanWork
754757
for gcw.scanWork < targetScanWork {
755758
// This might be a good place to add prefetch code...

0 commit comments

Comments
 (0)