Skip to content

Commit 8987acc

Browse files
committed
Fixed a printing bug for GC cycles.
Running without STW GC. Tightened next mark root loop syntax (and switched to non-loop variant for regular GC).
1 parent 9711f7f commit 8987acc

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

src/runtime/mgc.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,6 @@ func gcStart(trigger gcTrigger) {
733733
mode = gcForceMode
734734
} else if debug.gcstoptheworld == 2 {
735735
mode = gcForceBlockMode
736-
} else if work.goroutineLeakFinder.pending.Load() {
737-
// If goroutine leak detection has been enabled via profiling,
738-
// stop the world during the marking phase.
739-
mode = gcForceMode
740736
}
741737

742738
// Ok, we're doing it! Stop everybody else
@@ -936,9 +932,6 @@ func gcMarkDone() {
936932
// Ensure only one thread is running the ragged barrier at a
937933
// time.
938934
semacquire(&work.markDoneSema)
939-
if work.goroutineLeakFinder.enabled {
940-
findMaybeRunnableGoroutines()
941-
}
942935

943936
top:
944937
// Re-check transition condition under transition lock.
@@ -1381,9 +1374,11 @@ func gcMarkTermination(stw worldStop) {
13811374
gcRestoreSyncObjects()
13821375
}
13831376

1377+
var goroutineLeakDetectionDone bool
13841378
systemstack(func() {
13851379
// Pull the GC out of goroutine leak detection mode.
13861380
work.goroutineLeakFinder.enabled = false
1381+
goroutineLeakDetectionDone = work.goroutineLeakFinder.done
13871382
work.goroutineLeakFinder.done = false
13881383

13891384
// The memstats updated above must be updated with the world
@@ -1460,8 +1455,8 @@ func gcMarkTermination(stw worldStop) {
14601455
print("gc ", memstats.numgc,
14611456
" @", string(itoaDiv(sbuf[:], uint64(work.tSweepTerm-runtimeInitTime)/1e6, 3)), "s ",
14621457
util, "%")
1463-
if work.goroutineLeakFinder.done {
1464-
print(" (goroutine leak finder GC)")
1458+
if goroutineLeakDetectionDone {
1459+
print(" (checking for goroutine leaks)")
14651460
}
14661461
print(": ")
14671462
prev := work.tSweepTerm

src/runtime/mgcmark.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,24 +1199,18 @@ func gcDrainMarkWorkerFractional(gcw *gcWork) {
11991199
// is valid, and false if there are no more root jobs to be claimed,
12001200
// i.e. work.markrootNext >= work.markrootJobs.
12011201
func gcNextMarkRoot() (uint32, bool) {
1202-
var success bool
1203-
next, jobs := work.markrootNext.Load(), work.markrootJobs.Load()
1202+
if !work.goroutineLeakFinder.enabled {
1203+
// If not running goroutine leak detection, behave as the GC previously did.
1204+
job := work.markrootNext.Add(1) - 1
1205+
return job, job < work.markrootJobs.Load()
1206+
}
12041207

1205-
if next < jobs {
1206-
// still work available at the moment
1207-
for !success {
1208-
success = work.markrootNext.CompareAndSwap(next, next+1)
1208+
// Otherwise, use a CAS loop to increment markrootNext.
1209+
for next, jobs := work.markrootNext.Load(), work.markrootJobs.Load(); next < jobs; next = work.markrootNext.Load() {
1210+
// There is still work available at the moment.
1211+
if work.markrootNext.CompareAndSwap(next, next+1) {
12091212
// We manage to snatch a root job. Return the root index.
1210-
if success {
1211-
return next, true
1212-
}
1213-
1214-
// Get the latest value of markrootNext.
1215-
next = work.markrootNext.Load()
1216-
// We are out of markroot jobs.
1217-
if next >= jobs {
1218-
break
1219-
}
1213+
return next, true
12201214
}
12211215
}
12221216
return 0, false

0 commit comments

Comments
 (0)