@@ -364,8 +364,8 @@ type workType struct {
364
364
// (and thus 8-byte alignment even on 32-bit architectures).
365
365
bytesMarked uint64
366
366
367
- markrootNext uint32 // next markroot job
368
- markrootJobs uint32 // number of markroot jobs
367
+ markrootNext atomic. Uint32 // next markroot job
368
+ markrootJobs atomic. Uint32 // number of markroot jobs
369
369
370
370
nproc uint32
371
371
tstart int64
@@ -734,7 +734,8 @@ func gcStart(trigger gcTrigger) {
734
734
} else if debug .gcstoptheworld == 2 {
735
735
mode = gcForceBlockMode
736
736
} else if goexperiment .GoroutineLeakFinderGC {
737
- if work .goroutineLeakFinder .pending .Load () {
737
+ if work .goroutineLeakFinder .pending .Load () ||
738
+ debug .gcgoroutineleaks > 0 {
738
739
// Fully stop the world if running deadlock detection.
739
740
mode = gcForceBlockMode
740
741
}
@@ -816,7 +817,8 @@ func gcStart(trigger gcTrigger) {
816
817
schedEnableUser (false )
817
818
}
818
819
819
- if work .goroutineLeakFinder .pending .Load () {
820
+ if work .goroutineLeakFinder .pending .Load () ||
821
+ debug .gcgoroutineleaks > 0 {
820
822
work .goroutineLeakFinder .enabled = true
821
823
work .goroutineLeakFinder .pending .Store (false )
822
824
gcUntrackSyncObjects ()
@@ -1170,13 +1172,11 @@ func gcDiscoverMoreStackRoots() {
1170
1172
}
1171
1173
}
1172
1174
1173
- var oldRootJobs int32 = int32 (atomic .Load (& work .markrootJobs ))
1174
1175
var newRootJobs int32 = int32 (work .baseStacks ) + int32 (vIndex )
1175
-
1176
- if newRootJobs > oldRootJobs {
1176
+ if newRootJobs > int32 (work .markrootJobs .Load ()) {
1177
1177
// reset markrootNext as it could have been incremented past markrootJobs
1178
1178
work .nLiveStackRoots = vIndex
1179
- atomic . Store ( & work .markrootJobs , uint32 (newRootJobs ))
1179
+ work .markrootJobs . Store ( uint32 (newRootJobs ))
1180
1180
}
1181
1181
}
1182
1182
@@ -1237,7 +1237,7 @@ func findGoleaks() bool {
1237
1237
work .stackRoots [work .nLiveStackRoots ] = gp
1238
1238
work .nLiveStackRoots += 1
1239
1239
// We now have one more markroot job.
1240
- work .markrootJobs += 1
1240
+ work .markrootJobs . Add ( 1 )
1241
1241
// We might still have some work to do.
1242
1242
// Make sure in the next iteration we will check re-check for new runnable goroutines.
1243
1243
foundMoreWork = true
@@ -1261,7 +1261,7 @@ func findGoleaks() bool {
1261
1261
println ()
1262
1262
}
1263
1263
// Put the remaining roots as ready for marking and drain them.
1264
- work .markrootJobs += uint32 ( work .nStackRoots - work .nLiveStackRoots )
1264
+ work .markrootJobs . Add ( int32 ( work .nStackRoots - work .nLiveStackRoots ) )
1265
1265
work .nLiveStackRoots = work .nStackRoots
1266
1266
return true
1267
1267
}
@@ -1854,9 +1854,7 @@ func gcMarkWorkAvailable(p *p) bool {
1854
1854
if ! work .full .empty () || ! work .spanq .empty () {
1855
1855
return true // global work available
1856
1856
}
1857
- rootNext := atomic .Load (& work .markrootNext )
1858
- rootJobs := atomic .Load (& work .markrootJobs )
1859
- if rootNext < rootJobs {
1857
+ if work .markrootNext .Load () < work .markrootJobs .Load () {
1860
1858
return true // root scan work available
1861
1859
}
1862
1860
return false
@@ -1872,10 +1870,8 @@ func gcMark(startTime int64) {
1872
1870
work .tstart = startTime
1873
1871
1874
1872
// Check that there's no marking work remaining.
1875
- rootNext := atomic .Load (& work .markrootNext )
1876
- rootJobs := atomic .Load (& work .markrootJobs )
1877
- if work .full != 0 || rootNext < rootJobs {
1878
- print ("runtime: full=" , hex (work .full ), " next=" , rootNext , " jobs=" , rootJobs , " nDataRoots=" , work .nDataRoots , " nBSSRoots=" , work .nBSSRoots , " nSpanRoots=" , work .nSpanRoots , " nStackRoots=" , work .nStackRoots , "\n " )
1873
+ if work .full != 0 || work .markrootNext .Load () < work .markrootJobs .Load () {
1874
+ print ("runtime: full=" , hex (work .full ), " next=" , work .markrootNext .Load (), " jobs=" , work .markrootJobs .Load (), " nDataRoots=" , work .nDataRoots , " nBSSRoots=" , work .nBSSRoots , " nSpanRoots=" , work .nSpanRoots , " nStackRoots=" , work .nStackRoots , "\n " )
1879
1875
panic ("non-empty mark queue after concurrent mark" )
1880
1876
}
1881
1877
0 commit comments